Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix/#64-' into add/#52-라이브러리추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hooni0918 committed Jun 28, 2024
2 parents 1ece034 + 874469d commit 3345d87
Showing 1 changed file with 95 additions and 36 deletions.
131 changes: 95 additions & 36 deletions .github/workflows/create-jira-issue.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,114 @@
name: Sync GitHub Actions with Jira
name: Create Jira Issue and Sync with GitHub

on:
issues:
types: [opened]
push:
branches:
- '*'
- 'feat/*'
- 'fix/*'
- 'docs/*'
- 'setting/*'
- 'add/*'
- 'refactor/*'
- 'chore/*'

jobs:
sync_with_jira:
create_jira_issue:
if: github.event_name == 'issues'
runs-on: ubuntu-latest

steps:
- name: Sync commits with Jira
- name: Checkout repository
uses: actions/checkout@v2

- name: Print environment variables for debugging
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_ID="6f2a2640d5fdd55e4fead9548a77940585202111"
COMMIT_MSG="Update create-jira-issue.yml"
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\"}}]}}" \
-H "Content-Type: application/json" \
"${{ secrets.JIRA_BASEURL }}/rest/api/2/issue/$JIRA_ISSUE_KEY"
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: Sync commits with Jira
if: github.event_name == 'push' && !startsWith(github.event.ref, 'refs/tags/')
- name: Create branch for the issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
JIRA_ISSUE_KEY=extract_issue_key_from_commit_message "${{ github.event.head_commit.message }}"
curl -u ${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }} \
-X POST \
--data '{
"update": {
"comment": [
{
"add": {
"body": "Commit '${{ github.event.head_commit.id }}' was added to this issue: ${{ github.event.head_commit.message }}"
}
}
]
}
}' \
-H "Content-Type: application/json" \
"${{ secrets.JIRA_BASEURL }}/rest/api/2/issue/$JIRA_ISSUE_KEY"
export LANG=en_US.UTF-8
ISSUE_NUMBER=${{ github.event.issue.number }}
ISSUE_TITLE="${{ github.event.issue.title }}"
PREFIX=$(echo "$ISSUE_TITLE" | grep -oE '^(feat|fix|docs|setting|add|refactor|chore)')
if [ -z "$PREFIX" ]; then PREFIX="feature"; fi
TITLE_NO_PREFIX=$(echo "$ISSUE_TITLE" | sed -e "s/$PREFIX : //")
# iconv를 사용하여 비ASCII 문자 제거
CLEAN_TITLE=$(echo "$TITLE_NO_PREFIX" | iconv -c -f utf-8 -t ascii//TRANSLIT)
# ASCII가 아닌 문자 제거
CLEAN_TITLE=$(echo "$CLEAN_TITLE" | sed 's/[^a-zA-Z0-9]//g')
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"

0 comments on commit 3345d87

Please sign in to comment.