-
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (97 loc) · 3.66 KB
/
label-linked-issues.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
# Label Linked Issues
#
# Add the `status:merged`, `status:prereleased`, or `status:released` label to a pull request's
# linked issues when a pull request is merged into `main` or on workflow dispatch.
#
# References:
#
# - https://docs.github.com/actions/learn-github-actions/contexts
# - https://docs.github.com/actions/learn-github-actions/expressions
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#pull_request
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# - https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
# - https://docs.github.com/graphql/reference/objects#pullrequest
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch
# - https://github.com/actions/github-script
# - https://github.com/hmarr/debug-action
# - https://github.com/octokit/graphql-action
---
name: label-linked-issues
on:
pull_request:
branches:
- main
types:
- closed
workflow_dispatch:
inputs:
pr:
description: pull request number
required: true
type: number
permissions:
issues: write
jobs:
label-linked-issues:
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged
runs-on: ubuntu-latest
steps:
- id: debug
name: Print environment variables and event payload
uses: hmarr/[email protected]
- id: checkout
name: Checkout main
uses: actions/[email protected]
with:
persist-credentials: false
ref: main
- id: version
name: Get project version
run: echo "result=$(jq .version package.json -r)" >>$GITHUB_OUTPUT
- id: query
name: Query linked issues
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
query: |
query ($limit: Int = 20, $owner: String!, $pr: Int!, $repo: String!) {
repository(name: $repo, owner: $owner) {
pullRequest(number: $pr) {
closingIssuesReferences(
first: $limit
orderBy: { direction: ASC, field: CREATED_AT }
) {
edges {
node {
number
}
}
}
}
}
}
owner: ${{ github.repository_owner }}
pr: ${{ inputs.pr || github.event.number }}
repo: ${{ github.event.repository.name }}
- id: label
name: Label linked issues
uses: actions/[email protected]
env:
DATA: ${{ steps.query.outputs.data }}
PRERELEASE: ${{ contains(steps.version.outputs.result, '-') }}
RELEASE_BRANCH: ${{ contains(github.head_ref || github.ref_name, 'release/') }}
with:
script: |
const { closingIssuesReferences } = JSON.parse(process.env.DATA).repository.pullRequest
const issues = closingIssuesReferences.edges.map(edge => edge.node.number)
const release = JSON.parse(process.env.RELEASE_BRANCH || 'false')
const prerelease = JSON.parse(process.env.PRERELEASE || 'false')
for (const issue_number of issues) {
await github.rest.issues.addLabels({
...context.repo,
issue_number,
labels: [release ? `status:${prerelease ? 'pre' : ''}released` : 'status:merged']
})
}