-
Notifications
You must be signed in to change notification settings - Fork 2
85 lines (76 loc) · 2.96 KB
/
match_labels.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
---
name: "Match Labels for Changelog"
"on":
pull_request_target:
branches: [develop, main]
types: [opened, closed]
# Configure the project specific variables
env:
ORGANIZATION: theteamworks
PROJECT_NUMBER: 3
PR_URL: ${{ github.event.pull_request.html_url }}
PR_ID: ${{ github.event.pull_request.node_id }}
GH_TOKEN: ${{ secrets.GH_NEW_CARD_TO_PROJECT }}
USER: ${{ github.actor }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
label-match:
name: "Matches issue labels to PRs"
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: "Get linked issue id and state"
id: linked-issue
env:
GH_TOKEN: ${{ secrets.GH_NEW_CARD_TO_PROJECT }}
run: |
gh api graphql -f query='
query($pr_url: URI!) {
resource(url: $pr_url) {
... on PullRequest {
closingIssuesReferences(last: 1) {
nodes {
id
url
}
}
}
}
}' -f pr_url=$PR_URL > data.json
echo 'LINKED_ISSUE_ID='$(jq '.data.resource.closingIssuesReferences.nodes[] | .id' data.json) >> $GITHUB_ENV
echo 'LINKED_ISSUE_URL='$(jq '.data.resource.closingIssuesReferences.nodes[] | .url' data.json) >> $GITHUB_ENV
- name: "Get issues labels"
id: get-issue-labels
if: |
env.LINKED_ISSUE_URL != ''
run: |
gh api graphql -f query='
resource(url: $issue_url) {
... on Issue {
labels(last: 10) {
nodes {
id
name
}
}
}
}' -f issue_url=env.LINKED_ISSUE_URL > data.json
echo 'BUG='$(jq '.data.resource.labels.nodes[] | select(.name== "bug") | .id' data.json) >> $GITHUB_ENV
echo 'BREAKING='$(jq '.data.resource.labels.nodes[] | select(.name== "breaking-change") | .id' data.json) >> $GITHUB_ENV
echo 'DEPRECATE='$(jq '.data.resource.labels.nodes[] | select(.name== "deprecation") | .id' data.json) >> $GITHUB_ENV
echo 'VULNERABILITY='$(jq '.data.resource.labels.nodes[] | select(.name== "vulnerability") | .id' data.json) >> $GITHUB_ENV
echo 'ENHANCE='$(jq '.data.resource.labels.nodes[] | select(.name== "enhancement") | .id' data.json) >> $GITHUB_ENV
echo 'FEATURE='$(jq '.data.resource.labels.nodes[] | select(.name== "feature") | .id' data.json) >> $GITHUB_ENV
- name: "Add bug label"
id: check-labels
if: |
env.BUG != ''
run: |
gh api graphql -f query='
mutation($user:String!, $pr:ID!) {
addLabelsToLabelable(input: {clientMutationId: $user, labelableId: $pr, labelIds: [env.BUG]}) {
clientMutationId
}
}' -f pr=$PR_ID -f user=$USER