-
Notifications
You must be signed in to change notification settings - Fork 1.6k
131 lines (121 loc) · 4.74 KB
/
gardener_issue_comment.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Gardener Issue Comment
#
# This workflow moves GH issues from the Gardener board's "Blocked / Waiting" column
# to "Triage", when a comment is posted on an issue from a non-team member
# so that the Gardener can assess the issue in light of new information.
name: Gardener Issue Comment
on:
issue_comment:
types: [created]
jobs:
move-to-backlog:
name: Move issues back to Gardener project board Triage
runs-on: ubuntu-latest
timeout-minutes: 5
if: ${{ !github.event.issue.pull_request }}
steps:
- name: Generate authentication token
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
with:
app_id: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
private_key: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_PRIVATE_KEY }}
- name: Get PR comment author
id: comment
uses: tspascoal/get-user-teams-membership@v3
with:
username: ${{ github.actor }}
team: 'Vector'
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Move issue back to Triage if status is Blocked/Waiting
if: steps.comment.outputs.isTeamMember == 'false'
env:
GH_TOKEN: ${{ secrets.GH_PROJECT_PAT }}
run: |
issue_id=${{ github.event.issue.node_id }}
echo "issue_id: $issue_id"
# IDs fetched from https://docs.github.com/en/graphql/overview/explorer
project_id="PVT_kwDOAQFeYs4AAsTr" # Gardener
status_field_id="PVTF_lADOAQFeYs4AAsTrzgAXRuU" # Status
triage_option_id="2a08fafa"
# Query for project items for the given issue
project_items="$(gh api graphql -f query='
query($item_id: ID!) {
node(id: $item_id) {
... on Issue {
projectItems(first: 50) {
... on ProjectV2ItemConnection {
nodes {
fieldValueByName(name: "Status") {
... on ProjectV2ItemFieldSingleSelectValue {
name
}
}
... on ProjectV2Item {
id
project {
... on ProjectV2 {
id
}
}
}
}
}
}
}
... on PullRequest {
projectItems(first: 50) {
... on ProjectV2ItemConnection {
nodes {
fieldValueByName(name: "Status") {
... on ProjectV2ItemFieldSingleSelectValue {
name
}
}
... on ProjectV2Item {
id
project {
... on ProjectV2 {
id
}
}
}
}
}
}
}
}
}' -f item_id="$issue_id"
)"
# Extract the item in the Gardener project
project=$(echo $project_items | jq -c -r --arg project_id $project_id '.data.node.projectItems.nodes[] | select(.project.id == $project_id)')
current_status=$(echo $project | jq -c -r '.fieldValueByName.name')
item_id=$(echo $project | jq -c '.id')
if [ -z "$current_status" ] ; then
echo "Issue not found in Gardener board"
exit 0
else
echo "Found issue on Gardener board. Current issue status is: '${current_status}'"
fi
if [ "$current_status" = "Blocked / Waiting" ] ; then
echo "Moving issue from 'Blocked / Waiting' to 'Triage'"
gh api graphql -f query='
mutation($project_id: ID!, $item_id: ID!, $field_id: ID!, $option_id: String) {
updateProjectV2ItemFieldValue(
input: {
projectId: $project_id
itemId: $item_id
fieldId: $field_id
value: {
singleSelectOptionId: $option_id
}
}
) {
projectV2Item {
id
}
}
}' -f project_id="$project_id" -f item_id="$item_id" -f field_id="$status_field_id" -f option_id="$triage_option_id"
else
echo "Issue is in '${current_status}', not moving."
fi