forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (71 loc) · 2.26 KB
/
pr.yml
File metadata and controls
79 lines (71 loc) · 2.26 KB
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
name: PR
on:
pull_request_target:
types: [opened, reopened, edited, closed]
jobs:
reminder:
name: Label Reminder
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check if PR has no labels
id: check
uses: actions/github-script@v8
with:
result-encoding: string
script: |
const labels = context.payload.pull_request.labels;
return labels.length === 0;
- name: Post comment if unlabeled
if: steps.check.outputs.result == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
message: 'To maintainers: Please add labels to this PR'
Sync:
if: github.event.pull_request.state == 'open'
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: read
contents: read
steps:
- uses: actions/github-script@v8
with:
script: |
const allowed = ['bug', 'enhancement', 'meta']
const { owner, repo } = context.repo
const pr = context.payload.pull_request
const query = `
query($owner:String!, $repo:String!, $number:Int!) {
repository(owner:$owner, name:$repo) {
pullRequest(number:$number) {
closingIssuesReferences(first: 10) {
nodes {
labels(first: 20) {
nodes { name }
}
}
}
}
}
}
`
const res = await github.graphql(query, {
owner, repo, number: pr.number
})
const labels = new Set()
for (const issue of res.repository.pullRequest.closingIssuesReferences.nodes) {
for (const l of issue.labels.nodes) {
if (allowed.includes(l.name)) labels.add(l.name)
}
}
if (labels.size > 0) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pr.number,
labels: [...labels]
})
}