Skip to content

Commit 7f6c97f

Browse files
chore: CLOUDP-215162: Update Jira GitHub Action to update Ticket status based on the issue (#1754)
1 parent b9e795b commit 7f6c97f

File tree

1 file changed

+103
-1
lines changed

1 file changed

+103
-1
lines changed

.github/workflows/issues.yml

+103-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
on:
55
issues:
6-
types: [opened]
6+
types: [opened, reopened, closed]
77
permissions:
88
issues: write
99
contents: read
1010
jobs:
1111
jira_task:
1212
name: Create Jira issue
13+
if: github.event.action == 'opened'
1314
runs-on: ubuntu-latest
1415
steps:
1516
- name: Create JIRA ticket
@@ -66,3 +67,104 @@
6667
- Confirmation if Terraform OSS, Terraform Cloud, or Terraform Enterprise deployment
6768
6869
The ticket [${{ steps.create.outputs.jira-ticket-id }}](https://jira.mongodb.org/browse/${{ steps.create.outputs.jira-ticket-id }}) was created for internal tracking.
70+
reopen_jira_ticket:
71+
name: Reopen JIRA ticket
72+
if: github.event.action == 'reopened'
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Reopened JIRA ticket if exists
76+
run: |
77+
ISSUE_NUMBER=${{ github.event.issue.number }}
78+
JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }}
79+
80+
JIRA_QUERY="project = CLOUDP AND issuetype = Story AND resolution = Declined AND text ~ \"HELP: GitHub Issue n. $ISSUE_NUMBER\""
81+
82+
# URL encode the query
83+
JIRA_URL=$(echo "$JIRA_QUERY" | jq -s -R -r @uri)
84+
85+
json_response=$(curl -s --request GET \
86+
--url "https://jira.mongodb.org/rest/api/2/search?fields=id&jql=${JIRA_URL}" \
87+
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
88+
--header 'Accept: application/json')
89+
90+
JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.issues[0].id')
91+
if [ -z "$JIRA_TICKET_ID" ]; then
92+
echo "JIRA_TICKET_ID is not defined. Exiting the script."
93+
exit 1
94+
fi
95+
96+
JIRA_REOPENED_URL="https://jira.mongodb.org/rest/api/2/issue/${JIRA_TICKET_ID}/transitions"
97+
98+
json_response=$(curl -s --request POST \
99+
--url "${JIRA_REOPENED_URL}" \
100+
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
101+
--header 'Accept: application/json' \
102+
--header 'Content-Type: application/json' \
103+
--data '{
104+
"transition": {
105+
"id": 3
106+
},
107+
"update": {
108+
"comment": [
109+
{
110+
"add": {
111+
"body": "The related GitHub issue was reopened. Updated via automated process."
112+
}
113+
}
114+
]
115+
}
116+
}')
117+
echo "Response: ${json_response}"
118+
close_jira_ticket:
119+
name: Close JIRA ticket
120+
if: github.event.action == 'closed'
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Close JIRA ticket if exists
124+
run: |
125+
ISSUE_NUMBER=${{ github.event.issue.number }}
126+
JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }}
127+
128+
JIRA_QUERY="project = CLOUDP AND issuetype = Story AND resolution = Unresolved AND text ~ \"HELP: GitHub Issue n. $ISSUE_NUMBER\""
129+
130+
# URL encode the query
131+
JIRA_URL=$(echo "$JIRA_QUERY" | jq -s -R -r @uri)
132+
133+
json_response=$(curl -s --request GET \
134+
--url "https://jira.mongodb.org/rest/api/2/search?fields=id&jql=${JIRA_URL}" \
135+
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
136+
--header 'Accept: application/json')
137+
138+
JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.issues[0].id')
139+
if [ -z "$JIRA_TICKET_ID" ]; then
140+
echo "JIRA_TICKET_ID is not defined. Exiting the script."
141+
exit 1
142+
fi
143+
144+
JIRA_CLOSE_URL="https://jira.mongodb.org/rest/api/2/issue/${JIRA_TICKET_ID}/transitions"
145+
146+
json_response=$(curl -s --request POST \
147+
--url "${JIRA_CLOSE_URL}" \
148+
--header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \
149+
--header 'Accept: application/json' \
150+
--header 'Content-Type: application/json' \
151+
--data '{
152+
"transition": {
153+
"id": 1371
154+
},
155+
"update": {
156+
"comment": [
157+
{
158+
"add": {
159+
"body": "The related GitHub issue was closed. Resolved via automated process."
160+
}
161+
}
162+
]
163+
},
164+
"fields": {
165+
"resolution": {
166+
"name": "Declined"
167+
}
168+
}
169+
}')
170+
echo "Response: ${json_response}"

0 commit comments

Comments
 (0)