-
Notifications
You must be signed in to change notification settings - Fork 47
58 lines (48 loc) · 2.01 KB
/
pull_request_opened.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
name: PullRequest | Opened
on:
pull_request_target:
types: [opened, ready_for_review]
jobs:
opened:
name: Set labels
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: read
pull-requests: write
steps:
- name: Add review label
if: ${{ github.event.pull_request.draft == false }}
uses: actions/github-script@v6
with:
script: |
const issue_number = context.payload.pull_request.number
const owner = context.repo.owner
const repo = context.repo.repo
const labelsToAdd = ['to-review']
const labelsToRemove = ['wip']
const currentLabels = await github.rest.issues.listLabelsOnIssue({ issue_number, owner, repo })
github.rest.issues.addLabels({ labels: labelsToAdd, issue_number, owner, repo })
labelsToRemove.forEach(labelToRemove => {
if (currentLabels.data.find(label => label.name === labelToRemove)) {
github.rest.issues.removeLabel({ name: labelToRemove, issue_number, owner, repo });
}
})
- name: Add wip label
if: ${{ github.event.pull_request.draft == true }}
uses: actions/github-script@v6
with:
script: |
const issue_number = context.payload.pull_request.number
const owner = context.repo.owner
const repo = context.repo.repo
const labelsToAdd = ['wip']
const labelsToRemove = ['to-review']
const currentLabels = await github.rest.issues.listLabelsOnIssue({ issue_number, owner, repo })
github.rest.issues.addLabels({ labels: labelsToAdd, issue_number, owner, repo })
labelsToRemove.forEach(labelToRemove => {
if (currentLabels.data.find(label => label.name === labelToRemove)) {
github.rest.issues.removeLabel({ name: labelToRemove, issue_number, owner, repo });
}
})