Skip to content

Commit

Permalink
Update create-jira-issue.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
hooni0918 committed Jun 28, 2024
1 parent b56567d commit 9bdc0e9
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions .github/workflows/create-jira-issue.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sync GitHub Actions with Jira and Manage Branches
name: Sync GitHub Actions with Jira

on:
push:
Expand All @@ -14,39 +14,33 @@ jobs:

- name: Extract JIRA Issue Key and Sync
run: |
# 최신 커밋 메시지 가져오기
# 최근 커밋 메시지 가져오기
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Commit Message: $COMMIT_MESSAGE"
# JIRA 이슈 키 추출
JIRA_ISSUE_KEY=$(echo "$COMMIT_MESSAGE" | grep -oE 'JIRA-\d+')
# JIRA 이슈 키가 없다면 오류 출력 후 종료
echo "JIRA Issue Key: $JIRA_ISSUE_KEY"
# JIRA 이슈 키 검증
if [ -z "$JIRA_ISSUE_KEY" ]; then
echo "No JIRA issue key found in commit message."
exit 1
fi
# 커밋 ID 가져오기
COMMIT_ID=$(git rev-parse HEAD)
echo "Commit ID: $COMMIT_ID"
# JIRA에 커밋 정보 동기화
curl -u "${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \
RESPONSE=$(curl -s -u "${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \
-X POST \
--data "{\"update\": {\"comment\": [{\"add\": {\"body\": \"Commit '$COMMIT_ID' was added to this issue: $COMMIT_MESSAGE\"}}]}}" \
-H "Content-Type: application/json" \
"${{ secrets.JIRA_BASEURL }}/rest/api/2/issue/$JIRA_ISSUE_KEY"
"${{ secrets.JIRA_BASEURL }}/rest/api/2/issue/$JIRA_ISSUE_KEY")
echo "JIRA Response: $RESPONSE"
env:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_BASEURL: ${{ secrets.JIRA_BASEURL }}
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}

- name: Create Branch on Issue Opened
run: |
ISSUE_TITLE="${{ github.event.issue.title }}"
# 브랜치 이름 생성 (공백 및 특수문자를 하이픈으로 치환)
BRANCH_NAME=$(echo "$ISSUE_TITLE" | sed 's/[^a-zA-Z0-9가-힣]/-/g' | tr '[:upper:]' '[:lower:]')
# 브랜치 생성 및 푸시
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"

0 comments on commit 9bdc0e9

Please sign in to comment.