File tree Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ TEXT_CLEAR='\e[0m'
77
88# Make a request to the Jira API
99function 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" \
Original file line number Diff line number Diff line change 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
2023 env :
2124 ISSUE : ${{ inputs.issue }}
2225 TRANSITION : ${{ inputs.transition }}
26+ RESOLUTION : ${{ inputs.resolution }}
Original file line number Diff line number Diff line change @@ -25,17 +25,51 @@ if [ -z "${transition_id}" ]; then
2525 exit 1
2626fi
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
3766info " 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+
3973info " Transition payload:\n%s" " ${issue_transition} "
4074
4175jira-request --request " POST" --data " ${issue_transition} " \
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments