forked from Bumblebee-Bee/XChangePass
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (123 loc) · 5.2 KB
/
create-jira-issue.yml
File metadata and controls
142 lines (123 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Create Jira issue
on:
issues:
types:
- opened
jobs:
create-issue:
name: Create Jira issue
runs-on: ubuntu-latest
steps:
- name: Login
uses: atlassian/gajira-login@v3
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
- name: Checkout develop code
uses: actions/checkout@v4
with:
ref: develop
- name: Install jq (if not available)
run: sudo apt-get install -y jq
- name: Issue Parser
uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: ${{
contains(github.event.issue.title, '[Feat]') && '.github/ISSUE_TEMPLATE/feature-form.yml' ||
contains(github.event.issue.title, '[Refactor]') && '.github/ISSUE_TEMPLATE/refactor-form.yml' ||
contains(github.event.issue.title, '[Fix]') && '.github/ISSUE_TEMPLATE/bug-form.yml'
}}
- name: Parse JSON Output
id: parse-json
run: |
echo 'Parsed Issue Body: ${{ steps.issue-parser.outputs.jsonString }}'
echo '${{ steps.issue-parser.outputs.jsonString }}' > json_output.json
echo "parentKey=$(jq -r '.parentKey' json_output.json)" >> $GITHUB_ENV
echo "feature_summary=$(jq -r '.feature_summary' json_output.json)" >> $GITHUB_ENV
echo "start_date=$(jq -r '.startdate' json_output.json)" >> $GITHUB_ENV
echo "end_date=$(jq -r '.enddate' json_output.json)" >> $GITHUB_ENV
- name: Debug Parsed Outputs
run: |
echo "🔍 Debugging Parsed Outputs..."
echo "-----------------------------------"
cat json_output.json | jq .
echo "-----------------------------------"
echo "Parent Key: ${{ env.parentKey }}"
echo "Feature Summary: ${{ env.feature_summary }}"
echo "Start Date: ${{ env.start_date }}"
echo "End Date: ${{ env.end_date }}"
echo "-----------------------------------"
- name: Convert markdown to Jira Syntax
uses: peter-evans/jira2md@v1
id: md2jira
with:
input-text: |
### Github Issue Link
- ${{ github.event.issue.html_url }}
${{ github.event.issue.body }}
mode: md2jira
- name: Determine Fields
id: fields
run: |
start_date="${{ env.start_date }}"
end_date="${{ env.end_date }}"
start_date_formatted=$(date -d "$start_date" +%Y-%m-%d)
end_date_formatted=$(date -d "$end_date" +%Y-%m-%d)
echo "start_date=$start_date_formatted" >> $GITHUB_ENV
echo "end_date=$end_date_formatted" >> $GITHUB_ENV
if [[ -z "${{ env.parentKey }}" ]]; then
echo 'issuetype=에픽' >> $GITHUB_ENV
JSON_FIELDS=$(jq -n \
--arg feature_summary "${{ env.feature_summary }}" \
--arg start_date "$start_date_formatted" \
--arg end_date "$end_date_formatted" \
'{ summary: $feature_summary, customfield_10015: $start_date, customfield_10017: $end_date, duedate: $end_date }')
else
echo 'issuetype=Task' >> $GITHUB_ENV
JSON_FIELDS=$(jq -n \
--arg parentKey "${{ env.parentKey }}" \
--arg feature_summary "${{ env.feature_summary }}" \
--arg start_date "$start_date_formatted" \
'{ parent: { key: $parentKey }, summary: $feature_summary, customfield_10000: $start_date }')
fi
echo "fields=$(echo $JSON_FIELDS | jq -c .)" >> $GITHUB_ENV
- name: Log Variables Before Creating Issue
run: |
echo "Issuetype: ${{ env.issuetype }}"
echo "Fields: ${{ env.fields }}"
- name: Create Issue
id: create
uses: atlassian/gajira-create@v3
with:
project: KAN
issuetype: ${{ env.issuetype }}
summary: "${{ github.event.issue.title }}"
description: "${{ steps.md2jira.outputs.output-text }}"
fields: ${{ env.fields }}
- name: Log created issue
run: echo "Jira Issue ${{ steps.create.outputs.issue }} was created"
- name: Transition Issue to In Progress
run: |
jira_url="${{ secrets.JIRA_BASE_URL }}"
username="${{ secrets.JIRA_USER_EMAIL }}"
api_token="${{ secrets.JIRA_API_TOKEN }}"
issue_key="${{ steps.create.outputs.issue }}"
transition_id="21"
curl -X POST \
-u "${username}:${api_token}" \
-H "Content-Type: application/json" \
-d '{
"transition": {
"id": "'"$transition_id"'"
}
}' \
"${jira_url}/rest/api/2/issue/${issue_key}/transitions"
echo "Transitioned Jira Issue $issue_key to In Progress"
- name: Update issue title
uses: actions-cool/issues-helper@v3
with:
actions: "update-issue"
token: ${{ secrets.GITHUB_TOKEN }}
title: "${{ steps.create.outputs.issue }} ${{ github.event.issue.title }}"