@@ -13,38 +13,92 @@ jobs:
1313 issues : write
1414 if : ((github.event_name == 'issue_comment' && github.event.comment.body == 'recreate jira' && github.event.comment.user.login == 'sfc-gh-mkeller') || (github.event_name == 'issues' && github.event.pull_request.user.login != 'whitesource-for-github-com[bot]'))
1515 steps :
16- - name : Checkout
17- uses : actions/checkout@v4
18- with :
19- repository : snowflakedb/gh-actions
20- ref : jira_v1
21- token : ${{ secrets.SNOWFLAKE_GITHUB_TOKEN }} # stored in GitHub secrets
22- path : .
23-
24- - name : Login
25- 16+ - name : Create JIRA Ticket
17+ id : create
2618 env :
2719 JIRA_BASE_URL : ${{ secrets.JIRA_BASE_URL }}
2820 JIRA_USER_EMAIL : ${{ secrets.JIRA_USER_EMAIL }}
2921 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 }}
25+ run : |
26+ # debug
27+ #set -x
28+ TMP_BODY=$(mktemp)
29+ trap "rm -f $TMP_BODY" EXIT
3030
31- - name : Create JIRA Ticket
32- id : create
33- 34- with :
35- project : SNOW
36- issuetype : Bug
37- summary : ' ${{ github.event.issue.title }}'
38- description : |
39- ${{ github.event.issue.body }} \\ \\ _Created from GitHub Action_ for ${{ github.event.issue.html_url }}
40- fields : ' { "customfield_11401": {"id": "14723"}, "assignee": {"id": "712020:e527ae71-55cc-4e02-9217-1ca4ca8028a2"}, "components":[{"id":"19292"}], "labels": ["oss"], "priority": {"id": "10001"} }'
31+ # Escape special characters in title and body
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")
36+
37+ PAYLOAD=$(jq -n \
38+ --arg issuetitle "$TITLE" \
39+ --arg issuebody "$BODY" \
40+ '{
41+ fields: {
42+ project: { key: "SNOW" },
43+ issuetype: { name: "Bug" },
44+ summary: $issuetitle,
45+ description: $issuebody,
46+ customfield_11401: { id: "14723" },
47+ assignee: { id: "712020:e527ae71-55cc-4e02-9217-1ca4ca8028a2" },
48+ components: [{ id: "19292" }],
49+ labels: ["oss"],
50+ priority: { id: "10001" }
51+ }
52+ }')
53+
54+ # Create JIRA issue using REST API
55+ RESPONSE=$(curl -s -X POST \
56+ -H "Content-Type: application/json" \
57+ -H "Accept: application/json" \
58+ -u "$JIRA_USER_EMAIL:$JIRA_API_TOKEN" \
59+ "$JIRA_BASE_URL/rest/api/2/issue" \
60+ -d "$PAYLOAD")
61+
62+ # Extract JIRA issue key from response
63+ JIRA_KEY=$(echo "$RESPONSE" | jq -r '.key')
64+
65+ if [ "$JIRA_KEY" = "null" ] || [ -z "$JIRA_KEY" ]; then
66+ echo "Failed to create JIRA issue"
67+ echo "Response: $RESPONSE"
68+ echo "Request payload: $PAYLOAD"
69+ exit 1
70+ fi
71+
72+ echo "Created JIRA issue: $JIRA_KEY"
73+ echo "jira_key=$JIRA_KEY" >> $GITHUB_OUTPUT
4174
4275 - name : Update GitHub Issue
43- uses : ./jira/gajira-issue-update
4476 env :
4577 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
46- with :
47- issue_number : " {{ event.issue.id }}"
48- owner : " {{ event.repository.owner.login }}"
49- name : " {{ event.repository.name }}"
50- jira : " ${{ steps.create.outputs.issue }}"
78+ REPOSITORY : ${{ github.repository }}
79+ ISSUE_NUMBER : ${{ github.event.issue.number }}
80+ JIRA_KEY : ${{ steps.create.outputs.jira_key }}
81+ ISSUE_TITLE : ${{ github.event.issue.title }}
82+ 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+
91+ # Update Github issue title with jira id
92+ curl -s \
93+ -X PATCH \
94+ -H "Authorization: Bearer $GITHUB_TOKEN" \
95+ -H "Accept: application/vnd.github+json" \
96+ -H "X-GitHub-Api-Version: 2022-11-28" \
97+ "https://api.github.com/repos/$REPOSITORY/issues/$ISSUE_NUMBER" \
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