Skip to content

Commit 3d868ff

Browse files
authored
Meta: Sync PR labels (#8838)
1 parent 55a9f6a commit 3d868ff

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

.github/workflows/copy-labels.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: PR labeler
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
Sync:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
issues: read
13+
steps:
14+
- uses: actions/github-script@v7
15+
with:
16+
script: |
17+
const allowed = ['bug', 'enhancement', 'meta']
18+
const { owner, repo } = context.repo
19+
const pr = context.payload.pull_request
20+
21+
const query = `
22+
query($owner:String!, $repo:String!, $number:Int!) {
23+
repository(owner:$owner, name:$repo) {
24+
pullRequest(number:$number) {
25+
closingIssuesReferences(first: 10) {
26+
nodes {
27+
labels(first: 20) {
28+
nodes { name }
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
`
36+
37+
const res = await github.graphql(query, {
38+
owner, repo, number: pr.number
39+
})
40+
41+
const labels = new Set()
42+
for (const issue of res.repository.pullRequest.closingIssuesReferences.nodes) {
43+
for (const l of issue.labels.nodes) {
44+
if (allowed.includes(l.name)) labels.add(l.name)
45+
}
46+
}
47+
48+
if (labels.size > 0) {
49+
await github.rest.issues.addLabels({
50+
owner,
51+
repo,
52+
issue_number: pr.number,
53+
labels: [...labels]
54+
})
55+
}

0 commit comments

Comments
 (0)