Skip to content

Commit 3415562

Browse files
Label external contributions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1d7c02c commit 3415562

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Label external contributions
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- reopened
8+
- ready_for_review
9+
10+
permissions: {}
11+
12+
jobs:
13+
label:
14+
if: >-
15+
github.event.pull_request.draft == false &&
16+
github.event.pull_request.user.type == 'User' &&
17+
github.event.pull_request.author_association != 'MEMBER' &&
18+
github.event.pull_request.author_association != 'OWNER'
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 5
21+
permissions:
22+
issues: write
23+
concurrency:
24+
group: label-external-contribution-${{ github.event.pull_request.number }}
25+
cancel-in-progress: false
26+
27+
steps:
28+
- name: Add external contribution label
29+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
30+
with:
31+
github-token: ${{ github.token }}
32+
script: |
33+
const label = 'external-contribution';
34+
const pullRequest = context.payload.pull_request;
35+
36+
if (pullRequest.labels.some(({ name }) => name === label)) {
37+
return;
38+
}
39+
40+
if (context.payload.action !== 'opened') {
41+
const events = await github.paginate(
42+
github.rest.issues.listEvents,
43+
{
44+
...context.repo,
45+
issue_number: pullRequest.number,
46+
per_page: 100,
47+
},
48+
);
49+
if (
50+
events.some(({ event, label: eventLabel }) =>
51+
event === 'unlabeled' && eventLabel?.name === label
52+
)
53+
) {
54+
return;
55+
}
56+
}
57+
58+
await github.rest.issues.addLabels({
59+
...context.repo,
60+
issue_number: pullRequest.number,
61+
labels: [label],
62+
});

0 commit comments

Comments
 (0)