@@ -2,31 +2,77 @@ name: PR
22
33on :
44 pull_request_target :
5- types : [closed]
6- pull_request_review :
7- types : [submitted]
5+ types : [opened, reopened, edited, closed]
86
97jobs :
108 reminder :
119 name : Label Reminder
12- if : github.event_name == 'pull_request_review' || github. event.pull_request.merged == true
10+ if : github.event.pull_request.merged == true
1311 runs-on : ubuntu-latest
1412 permissions :
15- contents : read
1613 pull-requests : write
1714 steps :
1815 - name : Check if PR has no labels
19- id : check_labels
16+ id : check
2017 uses : actions/github-script@v7
2118 with :
2219 result-encoding : string
2320 script : |
2421 const labels = context.payload.pull_request.labels;
2522 return labels.length === 0;
2623
27- - name : Post comment if unlabeled, or fail on third party PRs
28- if : steps.check_labels .outputs.result == 'true'
24+ - name : Post comment if unlabeled
25+ if : steps.check .outputs.result == 'true'
2926 uses : marocchino/sticky-pull-request-comment@v2
3027 with :
31- GITHUB_TOKEN : ${{ github.token }}
3228 message : ' To maintainers: Please add labels to this PR'
29+
30+ Sync :
31+ runs-on : ubuntu-latest
32+ permissions :
33+ pull-requests : write
34+ issues : read
35+ contents : read
36+ steps :
37+ - uses : actions/github-script@v7
38+ with :
39+ script : |
40+ const allowed = ['bug', 'enhancement', 'meta']
41+ const { owner, repo } = context.repo
42+ const pr = context.payload.pull_request
43+
44+ const query = `
45+ query($owner:String!, $repo:String!, $number:Int!) {
46+ repository(owner:$owner, name:$repo) {
47+ pullRequest(number:$number) {
48+ closingIssuesReferences(first: 10) {
49+ nodes {
50+ labels(first: 20) {
51+ nodes { name }
52+ }
53+ }
54+ }
55+ }
56+ }
57+ }
58+ `
59+
60+ const res = await github.graphql(query, {
61+ owner, repo, number: pr.number
62+ })
63+
64+ const labels = new Set()
65+ for (const issue of res.repository.pullRequest.closingIssuesReferences.nodes) {
66+ for (const l of issue.labels.nodes) {
67+ if (allowed.includes(l.name)) labels.add(l.name)
68+ }
69+ }
70+
71+ if (labels.size > 0) {
72+ await github.rest.issues.addLabels({
73+ owner,
74+ repo,
75+ issue_number: pr.number,
76+ labels: [...labels]
77+ })
78+ }
0 commit comments