From 688c10748b19bbb30e78fc6f6e4bd2511357c899 Mon Sep 17 00:00:00 2001 From: YIZIHN Date: Fri, 28 Jun 2024 09:44:53 +0900 Subject: [PATCH] Update create-jira-issue.yml --- .github/workflows/create-jira-issue.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create-jira-issue.yml b/.github/workflows/create-jira-issue.yml index 3ea1c15b..4d010e58 100644 --- a/.github/workflows/create-jira-issue.yml +++ b/.github/workflows/create-jira-issue.yml @@ -4,29 +4,40 @@ on: push: branches: - '*' + pull_request: + types: [opened, synchronize, reopened] + issues: + types: [opened, edited] jobs: sync_with_jira: runs-on: ubuntu-latest steps: - - name: Sync commits with Jira + - name: Checkout code + uses: actions/checkout@v3 + + - name: Sync activity with Jira run: | function extract_issue_key_from_commit_message { echo "$1" | grep -oE 'JIRA-\d+' } - JIRA_ISSUE_KEY=$(extract_issue_key_from_commit_message "Update create-jira-issue.yml") + # 예시로 커밋 메시지 사용, 실제 환경에서는 다른 변수 사용 가능 + COMMIT_MESSAGE=$(git log -1 --pretty=%B) + JIRA_ISSUE_KEY=$(extract_issue_key_from_commit_message "$COMMIT_MESSAGE") + if [ -z "$JIRA_ISSUE_KEY" ]; then echo "No JIRA issue key found in commit message." exit 1 fi - COMMIT_ID="6f2a2640d5fdd55e4fead9548a77940585202111" - COMMIT_MSG="Update create-jira-issue.yml" + COMMIT_ID=$(git rev-parse HEAD) + + echo "Syncing commit $COMMIT_ID with JIRA issue $JIRA_ISSUE_KEY" curl -u "${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \ -X POST \ - --data "{\"update\": {\"comment\": [{\"add\": {\"body\": \"Commit '$COMMIT_ID' was added to this issue: $COMMIT_MSG\"}}]}}" \ + --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" env: