test] subtask로 들어가는지 테스트 #23
This file contains hidden or 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 | |
| on: | |
| issues: | |
| types: | |
| - opened | |
| jobs: | |
| create-issue: | |
| name: Create Jira issue | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Determine Issue Type | |
| id: type | |
| run: | | |
| if echo "${{ toJson(github.event.issue.labels) }}" | grep -q '✨ feat'; then | |
| echo "type=feature" >> $GITHUB_OUTPUT | |
| echo "template=feature-task.yml" >> $GITHUB_OUTPUT | |
| elif echo "${{ toJson(github.event.issue.labels) }}" | grep -q '🐞 fix'; then | |
| echo "type=fix" >> $GITHUB_OUTPUT | |
| echo "template=fix-task.yml" >> $GITHUB_OUTPUT | |
| elif echo "${{ toJson(github.event.issue.labels) }}" | grep -q '🔨 refactor'; then | |
| echo "type=refactor" >> $GITHUB_OUTPUT | |
| echo "template=refactor-task.yml" >> $GITHUB_OUTPUT | |
| elif echo "${{ toJson(github.event.issue.labels) }}" | grep -q '📃 docs'; then | |
| echo "type=docs" >> $GITHUB_OUTPUT | |
| echo "template=docs-task.yml" >> $GITHUB_OUTPUT | |
| elif echo "${{ toJson(github.event.issue.labels) }}" | grep -q '⚙️ chore'; then | |
| echo "type=chore" >> $GITHUB_OUTPUT | |
| echo "template=setting-task.yml" >> $GITHUB_OUTPUT | |
| elif echo "${{ toJson(github.event.issue.labels) }}" | grep -q '✅ test'; then | |
| echo "type=test" >> $GITHUB_OUTPUT | |
| echo "template=test-task.yml" >> $GITHUB_OUTPUT | |
| elif echo "${{ toJson(github.event.issue.labels) }}" | grep -q '🎨 style'; then | |
| echo "type=style" >> $GITHUB_OUTPUT | |
| echo "template=style-task.yml" >> $GITHUB_OUTPUT | |
| else | |
| echo "type=other" >> $GITHUB_OUTPUT | |
| echo "template=default.yml" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Jira 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 main code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: develop | |
| # 📝 이슈 파싱 (템플릿 경로 자동 선택) | |
| - name: Parse Issue | |
| uses: stefanbuck/github-issue-parser@v3 | |
| id: issue-parser | |
| with: | |
| template-path: .github/ISSUE_TEMPLATE/${{ steps.type.outputs.template }} | |
| - name: Log Issue Parser | |
| run: | | |
| echo '${{ steps.issue-parser.outputs.issueparser_parentKey }}' | |
| echo '${{ steps.issue-parser.outputs.__ticket_number }}' | |
| echo '${{ steps.issue-parser.outputs.jsonString }}' | |
| - name: Convert markdown to Jira Syntax | |
| uses: peter-evans/jira2md@v1 | |
| id: md2jira | |
| with: | |
| input-text: | | |
| ### Github Issue Link | |
| - ${{ github.event.issue.html_url }} | |
| ### 기능 설명 | |
| ${{ steps.issue-parser.outputs.issueparser_description }} | |
| ### 작업 목록 | |
| ${{ steps.issue-parser.outputs.issueparser_tasks }} | |
| ### 참고 링크 | |
| ${{ steps.issue-parser.outputs.issueparser_links }} | |
| mode: md2jira | |
| - name: Create Issue | |
| id: create | |
| uses: atlassian/gajira-create@v3 | |
| with: | |
| project: BOOK | |
| issuetype: Task | |
| summary: '${{ github.event.issue.title }}' | |
| description: '${{ steps.md2jira.outputs.output-text }}' | |
| fields: | | |
| { | |
| "parent": { | |
| "key": "${{ steps.issue-parser.outputs.issueparser_parentKey }}" | |
| } | |
| } | |
| - name: Log created issue | |
| run: echo "Jira Issue ${{ steps.issue-parser.outputs.parentKey }}/${{ steps.create.outputs.issue }} was created" | |
| - name: Extract task list | |
| id: extract-tasks | |
| run: | | |
| echo "${{ steps.issue-parser.outputs.issueparser_tasks }}" > tasks.md | |
| # Markdown 체크박스 형식에서 텍스트만 추출 | |
| grep -oP '(?<=- \[ \] ).*' tasks.md > tasks.txt | |
| echo "📋 추출된 작업 목록:" | |
| cat tasks.txt | |
| # JSON 배열로 변환 | |
| echo "TASKS_JSON=$(jq -R -s -c 'split("\n") | map(select(length > 0))' tasks.txt)" >> $GITHUB_ENV | |
| - name: Create Jira Sub-tasks | |
| if: ${{ env.TASKS_JSON != '[]' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const tasks = JSON.parse(process.env.TASKS_JSON); | |
| const parentKey = '${{ steps.create.outputs.issue }}'; | |
| const fetch = require('node-fetch'); | |
| for (const task of tasks) { | |
| const res = await fetch(`${process.env.JIRA_BASE_URL}/rest/api/3/issue`, { | |
| method: 'POST', | |
| headers: { | |
| 'Authorization': `Basic ${Buffer.from(`${process.env.JIRA_USER_EMAIL}:${process.env.JIRA_API_TOKEN}`).toString('base64')}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify({ | |
| fields: { | |
| project: { key: "BOOK" }, | |
| summary: task, | |
| issuetype: { name: "Sub-task" }, | |
| parent: { key: parentKey } | |
| } | |
| }) | |
| }); | |
| if (!res.ok) { | |
| const err = await res.text(); | |
| core.setFailed(`❌ Failed to create sub-task: ${err}`); | |
| } else { | |
| console.log(`✅ Created sub-task: ${task}`); | |
| } | |
| } | |
| env: | |
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | |
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | |
| - name: Checkout both branches | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Switch to develop | |
| run: | | |
| git fetch origin develop | |
| git checkout develop | |
| - name: Generate Branch Name | |
| id: branch | |
| run: | | |
| issue_number=${{ github.event.issue.number }} | |
| issue_title="${{ github.event.issue.title }}" | |
| slug=$(echo "$issue_title" | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g' | sed 's/[^a-z0-9\-]//g') | |
| ticket_key="${{ steps.create.outputs.issue }}" | |
| branch_name="${ticket_key}-${{ steps.type.outputs.type }}/#${issue_number}" | |
| echo "branch=${branch_name}" >> $GITHUB_OUTPUT | |
| - name: Create and push branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "${{ steps.branch.outputs.branch }}" | |
| git push origin "${{ steps.branch.outputs.branch }}" | |
| - name: Update issue title | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'update-issue' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| title: '[${{ steps.create.outputs.issue }}/${{ github.event.issue.title }}' | |
| - name: Add comment with Jira issue link | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'create-comment' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| body: 'Jira Issue Created: [${{ steps.create.outputs.issue }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.create.outputs.issue }})' | |
| - name: Add comment with Branch Name | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'create-comment' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| body: '🔀 Branch Created: `${{ steps.branch.outputs.branch }}`' | |
| - name: Assign issue author | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'add-assignees' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| assignees: ${{ github.event.issue.user.login }} |