Create Branch from Issue #56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Jira Issue and Sync with GitHub | |
on: | |
issues: | |
types: [opened] | |
push: | |
branches: | |
- 'feat/*' | |
- 'fix/*' | |
- 'docs/*' | |
- 'setting/*' | |
- 'add/*' | |
- 'refactor/*' | |
- 'chore/*' | |
jobs: | |
create_jira_issue: | |
if: github.event_name == 'issues' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Print environment variables for debugging | |
run: | | |
echo "JIRA_BASEURL=${{ secrets.JIRA_BASEURL }}" | |
echo "JIRA_API_TOKEN=${{ secrets.JIRA_API_TOKEN }}" | |
echo "JIRA_EMAIL=${{ secrets.JIRA_EMAIL }}" | |
echo "JIRA_PROJECT_KEY=${{ secrets.JIRA_PROJECT_KEY }}" | |
- name: Create Jira issue | |
env: | |
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
JIRA_BASEURL: ${{ secrets.JIRA_BASEURL }} | |
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} | |
JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }} | |
run: | | |
ISSUE_TITLE="${{ github.event.issue.title }}" | |
ISSUE_BODY="${{ github.event.issue.body }}" | |
echo "Creating Jira issue with title: $ISSUE_TITLE and body: $ISSUE_BODY" | |
RESPONSE=$(curl -D- \ | |
-u "$JIRA_EMAIL:$JIRA_API_TOKEN" \ | |
-X POST \ | |
--data '{ | |
"fields": { | |
"project": { | |
"key": "'"$JIRA_PROJECT_KEY"'" | |
}, | |
"summary": "'"$ISSUE_TITLE"'", | |
"description": "'"$ISSUE_BODY"'", | |
"issuetype": { | |
"name": "Task" | |
} | |
} | |
}' \ | |
-H "Content-Type: application/json" \ | |
"$JIRA_BASEURL/rest/api/2/issue/") | |
echo "Jira API response: $RESPONSE" | |
JIRA_ISSUE_KEY=$(echo "$RESPONSE" | grep -oP '(?<=key\":\")\w+-\d+') | |
echo "JIRA_ISSUE_KEY=$JIRA_ISSUE_KEY" >> $GITHUB_ENV | |
- name: Create branch for the issue | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
ISSUE_NUMBER=${{ github.event.issue.number }} | |
ISSUE_TITLE="${{ github.event.issue.title }}" | |
# 접두사 추출 및 이슈 타이틀에서 접두사 제거 | |
PREFIX=${ISSUE_TITLE%% :*} | |
CLEAN_TITLE=${ISSUE_TITLE#*: } | |
CLEAN_TITLE=${CLEAN_TITLE// /-} # 공백을 하이픈으로 대체 | |
BRANCH_NAME="${PREFIX}/#${ISSUE_NUMBER}-${CLEAN_TITLE}" | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git checkout -b "$BRANCH_NAME" | |
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}" "$BRANCH_NAME" | |
update_jira: | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Update Jira issue with commit info | |
env: | |
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
JIRA_BASEURL: ${{ secrets.JIRA_BASEURL }} | |
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} | |
JIRA_ISSUE_KEY: ${{ env.JIRA_ISSUE_KEY }} | |
run: | | |
COMMITS=$(jq -r '.commits[] | .message' $GITHUB_EVENT_PATH) | |
curl -D- \ | |
-u "$JIRA_EMAIL:$JIRA_API_TOKEN" \ | |
-X PUT \ | |
--data '{ | |
"update": { | |
"comment": [ | |
{ | |
"add": { | |
"body": "Commits related to this issue:\n$COMMITS" | |
} | |
] | |
] | |
} | |
}' \ | |
-H "Content-Type: application/json" \ | |
"$JIRA_BASEURL/rest/api/2/issue/$JIRA_ISSUE_KEY" |