-
Notifications
You must be signed in to change notification settings - Fork 7
49 lines (43 loc) · 1.49 KB
/
on-pr-closed.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
name: On PR Closed - Copy Issue Labels
on:
pull_request:
types:
- closed
jobs:
copy-labels:
name: Copy linked issue labels
runs-on: ubuntu-latest
steps:
- name: copy labels
env:
GITHUB_TOKEN: ${{ secrets.GH_CLI_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
run: |
org=${{ github.repository_owner }}
repo=psibase
pr_number=$PR_NUMBER
issue_number=$(gh api graphql -F owner="$org" -F repo="$repo" -F pr=$pr_number -f query='
query ($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
closingIssuesReferences(first: 1) {
nodes {
number
}
}
}
}
}' --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[].number')
if [ -z "${issue_number}" ]; then
echo "No issue linked to this PR"
exit 0
fi
labels=$(gh api "repos/$org/$repo/issues/$issue_number/labels" --jq 'map(.name) | join(",")')
if [ -z "${labels}" ]; then
echo "No labels on linked issue"
exit 0
fi
json_labels="[\"$(echo "$labels" | sed 's/,/","/g')\"]"
echo "{\"labels\":$json_labels}" > input.json
gh api "repos/$org/$repo/issues/$pr_number/labels" -X POST --input input.json
rm input.json