-
Notifications
You must be signed in to change notification settings - Fork 111
63 lines (53 loc) · 1.99 KB
/
remove-label-on-approve.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Remove and Add Multiple Labels on Approval
on:
pull_request_target:
types:
- closed
jobs:
remove-labels-on-approve:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Remove multiple labels using github-script
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const labelsToRemove = ['waiting-review', 'ready to review']; // Labels to remove
// Get repository and PR context information
const { owner, repo } = context.repo;
const issue_number = context.payload.pull_request.number;
// Get all labels on the current PR
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number,
});
// Filter the labels that exist on the PR and are in the labelsToRemove list
const existingLabelsToRemove = labels
.filter(label => labelsToRemove.includes(label.name))
.map(label => label.name);
// Remove each label
for (const label of existingLabelsToRemove) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: label,
});
console.log(`Label '${label}' has been removed.`);
}
if (existingLabelsToRemove.length === 0) {
console.log('No matching labels found to remove.');
}
// Add new labels
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ['approved']
});