-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
144 lines (132 loc) · 5.21 KB
/
Copy pathupdate-issue-status.yml
File metadata and controls
144 lines (132 loc) · 5.21 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Update Linked Issue Status
on:
pull_request:
branches:
- main
jobs:
update-issue-status:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
- uses: actions/checkout@v4
- name: Extract issue number from PR description
id: extract-issue
run: |
PR_DESCRIPTION=$(gh pr view ${{ github.event.pull_request.number }} --json body -q .body)
echo "PR DESCR IS $PR_DESCRIPTION"
# Look for issue references like "Fixes #123" or "Closes #123"
ISSUE_NUMBER=$(echo "$PR_DESCRIPTION" | grep -oE "(fixes|closes|resolves|references|refs|re|see|addresses|related to) https://github.com/getlantern/engineering/issues/([0-9]+)" | grep -oE "[0-9]+" | head -n 1)
if [ -n "$ISSUE_NUMBER" ]; then
echo "issue_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
echo "Found linked issue: #$ISSUE_NUMBER"
else
echo "No linked issue found in PR description"
exit 0
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Update issue status in project
if: steps.extract-issue.outputs.issue_number != ''
run: |
# Use GitHub GraphQL API to update the issue's status field in the project
# First, we need to get the project item ID for this issue
ISSUE_NODE_ID=$(gh api graphql -f query='
query($repo_owner: String!, $repo_name: String!, $issue_number: Int!) {
repository(owner: $repo_owner, name: $repo_name) {
issue(number: $issue_number) {
id
projectItems(first: 1) {
nodes {
id
project {
id
title
}
}
}
}
}
}' -f repo_owner=getlantern -f repo_name=engineering -F issue_number=${{ steps.extract-issue.outputs.issue_number }} -q '.data.repository.issue.projectItems.nodes[0].id')
if [ -z "$ISSUE_NODE_ID" ]; then
echo "Issue is not in any project"
exit 0
fi
PROJECT_ID=$(gh api graphql -f query='
query($repo_owner: String!, $repo_name: String!, $issue_number: Int!) {
repository(owner: $repo_owner, name: $repo_name) {
issue(number: $issue_number) {
projectItems(first: 1) {
nodes {
project {
id
}
}
}
}
}
}' -f repo_owner=getlantern -f repo_name=engineering -F issue_number=${{ steps.extract-issue.outputs.issue_number }} -q '.data.repository.issue.projectItems.nodes[0].project.id')
# Get the status field ID
STATUS_FIELD_ID=$(gh api graphql -f query='
query($project_id: ID!) {
node(id: $project_id) {
... on ProjectV2 {
fields(first: 20) {
nodes {
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -F project_id=$PROJECT_ID -q '.data.node.fields.nodes[] | select(.name=="Status") | .id')
# Get the option ID for "In Review"
IN_REVIEW_OPTION_ID=$(gh api graphql -f query='
query($project_id: ID!) {
node(id: $project_id) {
... on ProjectV2 {
fields(first: 20) {
nodes {
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -F project_id=$PROJECT_ID -q '.data.node.fields.nodes[] | select(.name=="Status") | .options[] | select(.name=="In Review") | .id')
# Update the status field to "In Review"
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=$ISSUE_NODE_ID -F field_id=$STATUS_FIELD_ID -f option_id=$IN_REVIEW_OPTION_ID
echo "Updated issue #${{ steps.extract-issue.outputs.issue_number }} status to 'In Review'"
env:
GH_TOKEN: ${{ github.token }}