Skip to content

Commit 56ff4fa

Browse files
edvilmegithub-actions
authored andcommitted
Branding github actions
1 parent f743770 commit 56ff4fa

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Remove Lockdown Label from PRs
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
actions: write
9+
issues: write
10+
11+
jobs:
12+
remove-labels:
13+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'Branding')
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: PR's only change is <VersionFeature> in eng/Versions.props
17+
run: |
18+
git fetch --depth=2
19+
changes=$(git diff HEAD^ HEAD -- eng/Versions.props | grep '^[-+]')
20+
changes_without_version_feature=$(echo "$changes" | grep -v '<VersionFeature>')
21+
has_changes_without_version_feature=$(echo "$changes_without_version_feature" | wc -l)
22+
if [ "$has_changes_without_version_feature" -eq 0 ]; then
23+
echo "only_version_feature_changed=true" >> $GITHUB_ENV
24+
else
25+
echo "only_version_feature_changed=false" >> $GITHUB_ENV
26+
27+
- name: Remove Branch Lockdown label from other PRs targeting this branch
28+
if: steps.PR_has_Branding_label.outputs.has_branding_label == 'true' && steps.PR_only_change_is_VersionFeature_in_eng_Versions_props.outputs.only_version_feature_changed == 'true'
29+
uses: actions/github-script@v4
30+
with:
31+
script: |
32+
const prs = await github.pulls.list({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
state: 'open',
36+
base: github.event.pull_request.base.ref,
37+
per_page: 300
38+
});
39+
const filtered_prs = prs.data
40+
.filter(pr => pr.number !== github.context.payload.pull_request.number)
41+
.filter(pr => pr.labels.map(label => label.name).includes('Branch Lockdown'));
42+
for (const pr of filtered_prs) {
43+
await github.issues.removeLabel({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
issue_number: pr.number,
47+
name: 'Branch Lockdown'
48+
});
49+
console.log(`Removed Branch Lockdown label from PR #${pr.number}`);
50+
}

0 commit comments

Comments
 (0)