@@ -19,18 +19,20 @@ jobs:
1919 JIRA_BASE_URL : ${{ secrets.JIRA_BASE_URL }}
2020 JIRA_USER_EMAIL : ${{ secrets.JIRA_USER_EMAIL }}
2121 JIRA_API_TOKEN : ${{ secrets.JIRA_API_TOKEN }}
22+ ISSUE_TITLE : ${{ github.event.issue.title }}
23+ ISSUE_BODY : ${{ github.event.issue.body }}
24+ ISSUE_URL : ${{ github.event.issue.html_url }}
2225 run : |
2326 # debug
2427 set -x
2528 TMP_BODY=$(mktemp)
2629 trap "rm -f $TMP_BODY" EXIT
2730
2831 # Escape special characters in title and body
29- TITLE=$(echo '${{ github.event.issue.title }}' | sed 's/"/\\"/g' | sed "s/'/\\\'/g")
30-
31- echo "${{ github.event.issue.body }}" > $TMP_BODY
32- echo -e "\n\n_Created from GitHub Action_ for ${{ github.event.issue.html_url }}" >> $TMP_BODY
33- BODY=$(cat "$TMP_BODY" | sed 's/"/\\"/g' | sed "s/'/\\\'/g")
32+ TITLE=$(echo "${ISSUE_TITLE//`/\\`}" | sed 's/"/\\"/g' | sed "s/'/\\\'/g")
33+ echo "${ISSUE_BODY//`/\\`}" | sed 's/"/\\"/g' | sed "s/'/\\\'/g" > $TMP_BODY
34+ echo -e "\n\n_Created from GitHub Action_ for $ISSUE_URL" >> $TMP_BODY
35+ BODY=$(cat "$TMP_BODY")
3436
3537 PAYLOAD=$(jq -n \
3638 --arg issuetitle "$TITLE" \
@@ -78,11 +80,25 @@ jobs:
7880 JIRA_KEY : ${{ steps.create.outputs.jira_key }}
7981 ISSUE_TITLE : ${{ github.event.issue.title }}
8082 run : |
83+ TITLE=$(echo "${ISSUE_TITLE//`/\\`}" | sed 's/"/\\"/g' | sed "s/'/\\\'/g")
84+ PAYLOAD=$(jq -n \
85+ --arg issuetitle "$TITLE" \
86+ --arg jirakey "$JIRA_KEY" \
87+ '{
88+ title: ($jirakey + ": " + $issuetitle)
89+ }')
90+
8191 # Update Github issue title with jira id
82- GH_UPD_RESPONSE=$( curl -s \
92+ curl -s \
8393 -X PATCH \
8494 -H "Authorization: Bearer $GITHUB_TOKEN" \
8595 -H "Accept: application/vnd.github+json" \
8696 -H "X-GitHub-Api-Version: 2022-11-28" \
8797 "https://api.github.com/repos/$REPOSITORY/issues/$ISSUE_NUMBER" \
88- -d "{\"title\":\"$JIRA_KEY: $ISSUE_TITLE\"}")
98+ -d "$PAYLOAD"
99+
100+ if [ "$?" != 0 ]; then
101+ echo "Failed to update GH issue. Payload was:"
102+ echo "$PAYLOAD"
103+ exit 1
104+ fi
0 commit comments