Skip to content

Commit 39ca42f

Browse files
authored
[release/9.0.1xx] [Github Actions] Remove Branch Lockdown Labels on Branding Merge (#48181)
2 parents e86b026 + 992970a commit 39ca42f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Remove Lockdown Label from PRs
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
actions: write
9+
pull-requests: 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: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
- name: PR's only change is <VersionFeature> in eng/Versions.props
20+
id: only_version_feature_changed
21+
uses: actions/github-script@v4
22+
with:
23+
script: |
24+
const otherChangesMessage = "❌ Changes in eng/Versions.props other than <VersionFeature> found";
25+
const onlyVersionFeatureMessage = "✅ PR's only change is <VersionFeature> in eng/Versions.props";
26+
const prNumber = context.payload.pull_request.number;
27+
const { data: files } = await github.pulls.listFiles({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
pull_number: prNumber
31+
});
32+
// If files other than eng/Versions.props are changed, output message and exit
33+
if (files.some(file => file.filename !== "eng/Versions.props")) {
34+
console.log(otherChangesMessage);
35+
core.exportVariable("only_version_feature_changed", "false");
36+
return;
37+
}
38+
// Iterate through the patch of eng/Versions.props to check for changes other than <VersionFeature>
39+
const versionsPropsFile = files.find(file => file.filename === "eng/Versions.props");
40+
const patchLines = versionsPropsFile.patch.split("\n").filter(l => l.startsWith("+") || l.startsWith("-"));
41+
for (const line of patchLines) {
42+
if (!line.includes("<VersionFeature>")) {
43+
console.log(otherChangesMessage);
44+
core.exportVariable("only_version_feature_changed", "false");
45+
return;
46+
}
47+
}
48+
console.log(onlyVersionFeatureMessage);
49+
core.exportVariable("only_version_feature_changed", "true");
50+
51+
- name: Remove Branch Lockdown label from other PRs targeting this branch
52+
if: steps.only_version_feature_changed.outputs.only_version_feature_changed == 'true'
53+
uses: actions/github-script@v4
54+
with:
55+
script: |
56+
const prs = await github.pulls.list({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
state: 'open',
60+
base: github.event.pull_request.base.ref,
61+
per_page: 300
62+
});
63+
const filtered_prs = prs.data
64+
.filter(pr => pr.number !== github.context.payload.pull_request.number)
65+
.filter(pr => pr.labels.map(label => label.name).includes('Branch Lockdown'));
66+
for (const pr of filtered_prs) {
67+
await github.issues.removeLabel({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
issue_number: pr.number,
71+
name: 'Branch Lockdown'
72+
});
73+
console.log(`Removed Branch Lockdown label from PR #${pr.number}`);
74+
}

0 commit comments

Comments
 (0)