11# This workflow will comment the PR with the JIRA issue summary
22# if a JIRA issue number is detected in the branch name or title
33
4- name : Add JIRA issue summary
4+ name : Add JIRA Summary to PR
5+
6+ permissions :
7+ contents : read
8+ pull-requests : write
59
610on :
7- pull_request_target :
11+ pull_request :
812 types : [opened]
913
1014jobs :
1115 add_jira_summary :
16+ if : github.event.pull_request.head.repo.full_name == github.repository
1217 runs-on : ubuntu-latest
1318
1419 steps :
15- - name : Find JIRA issue key
16- id : find_jira_key
17- env :
18- HEAD_REF : ${{ github.head_ref}}
19- PR_TITLE : ${{ github.event.pull_request.title }}
20- run : >
21- echo $HEAD_REF $PR_TITLE
22- | echo "issue_key=$(
23- grep -osi "\b\(GA\|GEOPY\|DEVOPS\)[ #-]*[0-9]\+"
24- | head -n1
25- | sed -E "s/([A-Z]+)[-# ]*([0-9]+)/\1-\2/i"
26- | tr [:lower:] [:upper:]
27- )"
28- >> $GITHUB_OUTPUT
29- - name : Get JIRA summary
30- id : get_jira_summary
31- if : ${{ steps.find_jira_key.outputs.issue_key }}
32- env :
33- JIRA_BASE_URL : ${{ secrets.JIRA_BASE_URL }}
34- JIRA_BASIC_AUTH : ${{ secrets.JIRA_BASIC_AUTH }}
35- run : >
36- curl -sS -X GET
37- -H "Authorization: Basic $JIRA_BASIC_AUTH"
38- -H "Content-Type: application/json"
39- "$JIRA_BASE_URL/rest/api/2/issue/${{ steps.find_jira_key.outputs.issue_key }}"
40- | echo "summary=$(jq -r '.fields.summary // empty')" >> $GITHUB_OUTPUT
41- - name : Extract PR title
42- id : get_pr_title
43- env :
44- PR_TITLE : ${{ github.event.pull_request.title }}
45- run : |
46- echo "text=$(echo $PR_TITLE | sed -E "s/^\s*[?[A-Z]+[-# ]*[0-9]+]?[-: ]*(.*)/\1/i")" >> $GITHUB_OUTPUT
47- - name : Add comment
48- if : ${{ steps.find_jira_key.outputs.issue_key }}
49- env :
50- ISSUE_SUMMARY : ${{ steps.get_jira_summary.outputs.summary }}
51- TITLE_TEXT : ${{ steps.get_pr_title.outputs.text }}
52- PR_BODY : ${{ github.event.pull_request.body }}
53- run : >
54- jq
55- --arg ISSUE_ID "${{ steps.find_jira_key.outputs.issue_key }}"
56- --arg ISSUE_SUMMARY "$(cat <<< $ISSUE_SUMMARY)"
57- --arg TITLE_TEXT "$(cat <<< ${TITLE_TEXT:-$ISSUE_SUMMARY})"
58- --arg PR_BODY "$(cat <<< $PR_BODY)"
59- -c '{"title": ($ISSUE_ID + ": " + $TITLE_TEXT), "body": ("**" + $ISSUE_ID + " - " + $ISSUE_SUMMARY + "**\n" + $PR_BODY)}' <<< {}
60- | curl -sS -X POST -d @-
61- -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
62- -H "Content-Type: application/json"
63- "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}"
64- > /dev/null
20+ - name : Find JIRA issue key
21+ id : find_jira_key
22+ env :
23+ HEAD_REF : ${{ github.head_ref }}
24+ PR_TITLE : ${{ github.event.pull_request.title }}
25+ run : |
26+ echo "$HEAD_REF $PR_TITLE" \
27+ | grep -osi "\b\(GA\|GEOPY\|DEVOPS\)[ #-]*[0-9]\+" \
28+ | head -n1 \
29+ | sed -E "s/([A-Z]+)[-# ]*([0-9]+)/\1-\2/i" \
30+ | tr '[:lower:]' '[:upper:]' \
31+ | xargs -I {} echo "issue_key={}" >> $GITHUB_OUTPUT
32+
33+ - name : Get JIRA summary
34+ id : get_jira_summary
35+ if : ${{ steps.find_jira_key.outputs.issue_key }}
36+ env :
37+ JIRA_BASE_URL : ${{ secrets.JIRA_BASE_URL }}
38+ JIRA_BASIC_AUTH : ${{ secrets.JIRA_BASIC_AUTH }}
39+ ISSUE_KEY : ${{ steps.find_jira_key.outputs.issue_key }}
40+ run : |
41+ curl -sS -X GET \
42+ -H "Authorization: Basic $JIRA_BASIC_AUTH" \
43+ -H "Content-Type: application/json" \
44+ "$JIRA_BASE_URL/rest/api/2/issue/$ISSUE_KEY" \
45+ | jq -r '.fields.summary // empty' \
46+ | xargs -I {} echo "summary={}" >> $GITHUB_OUTPUT
47+
48+ - name : Extract PR title
49+ id : get_pr_title
50+ env :
51+ PR_TITLE : ${{ github.event.pull_request.title }}
52+ run : |
53+ echo "text=$(echo "$PR_TITLE" | sed -E 's/^\s*[?[A-Z]+[-# ]*[0-9]+]?[-: ]*(.*)/\1/i')" >> $GITHUB_OUTPUT
54+
55+ - name : Add comment
56+ if : ${{ steps.find_jira_key.outputs.issue_key }}
57+ env :
58+ ISSUE_KEY : ${{ steps.find_jira_key.outputs.issue_key }}
59+ ISSUE_SUMMARY : ${{ steps.get_jira_summary.outputs.summary }}
60+ TITLE_TEXT : ${{ steps.get_pr_title.outputs.text }}
61+ PR_BODY : ${{ github.event.pull_request.body }}
62+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
63+ GITHUB_API_URL : ${{ github.api_url }}
64+ GITHUB_REPOSITORY : ${{ github.repository }}
65+ PR_NUMBER : ${{ github.event.pull_request.number }}
66+ run : |
67+ FINAL_TITLE="${TITLE_TEXT:-$ISSUE_SUMMARY}"
68+ COMMENT_PAYLOAD=$(jq -c --null-input \
69+ --arg ISSUE_ID "$ISSUE_KEY" \
70+ --arg ISSUE_SUMMARY "$ISSUE_SUMMARY" \
71+ --arg TITLE_TEXT "$FINAL_TITLE" \
72+ --arg PR_BODY "$PR_BODY" \
73+ '{
74+ title: ($ISSUE_ID + ": " + $TITLE_TEXT),
75+ body: ("**" + $ISSUE_ID + " - " + $ISSUE_SUMMARY + "**\n" + $PR_BODY)
76+ }')
77+
78+ curl -sS -X POST \
79+ -H "Authorization: token $GITHUB_TOKEN" \
80+ -H "Content-Type: application/json" \
81+ -d "$COMMENT_PAYLOAD" \
82+ "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" \
83+ > /dev/null
0 commit comments