forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 45
131 lines (120 loc) · 4.14 KB
/
label-pr.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# This workflow auto-labels PRs based on various criteria:
# - If a PR is opened or a new commit is pushed:
# - The workflow runs auto-label.cjs to add scope-related labels and to add 'needs-review'
# (unless the PR already has an approving review from a maintainer).
# - The workflow will check for linked issues and add the 'fix-me' label to them.
# - If a review (approving or otherwise) is added to the PR by a maintainer, the workflow
# removes the 'needs-review' label.
# - If 'auto merge' is enabled or disabled on the PR, the workflow adds/removes the
# 'auto-merge' label.
name: PR Auto Label
on:
pull_request_target:
types:
- edited
- synchronize
- opened
- reopened
- auto_merge_enabled
- auto_merge_disabled
- ready_for_review
pull_request_review:
types: [submitted]
jobs:
job_picker:
runs-on: ubuntu-latest
outputs:
run: ${{ steps.label_job.outputs.run }}
steps:
- name: Determine label job
id: label_job
shell: bash
run: |
if [ "${{ contains(github.event.action,'auto_merge_') }}" == "true" ]; then
echo "run=auto_merge" >> $GITHUB_OUTPUT
elif [ "${{ github.event.action }}" == "submitted" ]; then
echo "run=pr_review" >> $GITHUB_OUTPUT
elif [ "${{ github.event.action }}" == "ready_for_review" ]; then
echo "run=pr_ready" >> $GITHUB_OUTPUT
else
echo "run=push_commit" >> $GITHUB_OUTPUT
fi
auto_merge:
runs-on: ubuntu-latest
needs: job_picker
if: needs.job_picker.outputs.run == 'auto_merge'
steps:
- name: Add auto-merge label
uses: buildsville/[email protected]
if: github.event.action == 'auto_merge_enabled'
with:
token: ${{secrets.GITHUB_TOKEN}}
labels: auto-merge
type: add
- name: Remove auto-merge label
uses: buildsville/[email protected]
if: github.event.action == 'auto_merge_disabled'
with:
token: ${{secrets.GITHUB_TOKEN}}
labels: auto-merge
type: remove
pr_review:
permissions:
pull-requests: write
runs-on: ubuntu-latest
needs: job_picker
if: needs.job_picker.outputs.run == 'pr_review'
steps:
- name: Remove needs-review label
if: >
github.event.review.author_association == 'COLLABORATOR' ||
github.event.review.author_association == 'OWNER'
uses: buildsville/[email protected]
with:
token: ${{secrets.GITHUB_TOKEN}}
labels: needs-review
type: remove
pr_ready:
runs-on: ubuntu-latest
needs: job_picker
if: needs.job_picker.outputs.run == 'pr_ready'
steps:
- name: Add needs-review label
uses: buildsville/[email protected]
with:
token: ${{secrets.GITHUB_TOKEN}}
labels: needs-review
type: add
push_commit:
runs-on: ubuntu-latest
needs: job_picker
if: needs.job_picker.outputs.run == 'push_commit'
steps:
- uses: actions/checkout@v3
with:
# force to ci checkout main repo to avoid
# unexpected PR code to be executed with out github token
ref: main
- name: Check for linked issues
id: find-linked-issues
uses: mondeja/pr-linked-issues-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Label linked issues
if: join(steps.find-linked-issues.outputs.issues) != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Found linked issues: ${{ steps.find-linked-issues.outputs.issues }}"
issues=${{ steps.find-linked-issues.outputs.issues }}
for issue in ${issues//,/ }; do
echo "Adding 'fix-me' label to issue $issue"
gh issue edit $issue --add-label "fix-me"
done
- uses: ./.github/actions/setup-js-env
- name: Run Label Script
run: |
node .github/scripts/auto-label.cjs
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
PR_NUMBER: ${{ github.event.number }}