Skip to content

Commit fe53729

Browse files
authored
ci: fix jira sync for closing issues (#27155)
Resolution must be explicitly set when transitioning an issue to closed. This adds ability to set resolution on transition and updates the sync workflow to resolve issue to done when closing. Also updated the jira-query helper to output the response body on error to make it easier to determine the cause.
1 parent afc0014 commit fe53729

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.github/actions/jira/shared.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TEXT_CLEAR='\e[0m'
77

88
# Make a request to the Jira API
99
function jira-request() {
10-
curl --show-error --location --fail \
10+
curl --show-error --location --fail-with-body \
1111
--user "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" \
1212
--header "Accept: application/json" \
1313
--header "Content-Type: application/json" \

.github/actions/jira/transition/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ inputs:
77
issue:
88
required: true
99
description: JIRA issue to transition
10+
resolution:
11+
required: false
12+
description: Resolution name to apply to issue
1013
transition:
1114
required: true
1215
description: Transition name to apply to issue
@@ -20,3 +23,4 @@ runs:
2023
env:
2124
ISSUE: ${{ inputs.issue }}
2225
TRANSITION: ${{ inputs.transition }}
26+
RESOLUTION: ${{ inputs.resolution }}

.github/actions/jira/transition/jira-transition.bash

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,51 @@ if [ -z "${transition_id}" ]; then
2525
exit 1
2626
fi
2727

28-
template='
28+
# If a resolution is set, find it and generate the template
29+
# with it included
30+
if [ -n "${RESOLUTION}" ]; then
31+
# Grab the resolution ID
32+
result="$(jira-request "${JIRA_BASE_URL}/rest/api/3/resolution")" || exit
33+
query="$(printf '.[] | select(.name == "%s").id' "${RESOLUTION}")"
34+
resolution_id="$(jq -r "${query}" <<< "${result}")"
35+
36+
if [ -z "${resolution_id}" ]; then
37+
error "Could not find matching resolution with name matching '%s'" "${RESOLUTION}"
38+
exit 1
39+
fi
40+
41+
template='
2942
{
3043
transition: {
3144
id: $transition
45+
},
46+
fields: {
47+
resolution: {
48+
id: $resolution
49+
}
3250
}
3351
}
3452
'
35-
issue_transition="$(jq -n --arg transition "${transition_id}" "${template}")" || exit
53+
issue_transition="$(jq -n --arg transition "${transition_id}" --arg resolution "${resolution_id}" "${template}")" || exit
54+
else
55+
# No resolution so the template only includes the transition
56+
template='
57+
{
58+
transition: {
59+
id: $transition
60+
}
61+
}
62+
'
63+
issue_transition="$(jq -n --arg transition "${transition_id}" "${template}")" || exit
64+
fi
3665

3766
info "Transitioning JIRA issue '%s' to %s (ID: %s)" "${ISSUE}" \
3867
"${TRANSITION}" "${transition_id}"
68+
if [ -n "${resolution_id}" ]; then
69+
info "Resolving JIRA issue '%s' as %s (ID: %s)" "${ISSUE}" \
70+
"${RESOLUTION}" "${resolution_id}"
71+
fi
72+
3973
info "Transition payload:\n%s" "${issue_transition}"
4074

4175
jira-request --request "POST" --data "${issue_transition}" \

.github/workflows/jira-sync.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
with:
5959
issue: ${{ steps.search.outputs.issue }}
6060
transition: "Closed"
61+
resolution: "Done"
6162
- name: Reopen ticket
6263
if: github.event.action == 'reopened' && steps.search.outputs.issue
6364
uses: ./.github/actions/jira/transition

0 commit comments

Comments
 (0)