[Feat] #91 - ๊ตฌ๋งคํ์ด์ง API ์ฐ๋ #49
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: Auto Create Branch | |
| on: | |
| issues: | |
| types: [opened] | |
| jobs: | |
| create-branch: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Extract branch name from issue form | |
| id: extract | |
| run: | | |
| # Issue body๋ฅผ ํ์ผ๋ก ์ ์ฅ (ํน์๋ฌธ์ ์ฒ๋ฆฌ) | |
| cat << 'EOF' > issue_body.txt | |
| ${{ github.event.issue.body }} | |
| EOF | |
| # ์ด์ ์ ๋ชฉ ์ ์ฅ | |
| ISSUE_TITLE="${{ github.event.issue.title }}" | |
| echo "ํ์ฌ ์ด์ ์ ๋ชฉ: $ISSUE_TITLE" | |
| # ๋ธ๋์น๋ช ์ถ์ถ ("๋ธ๋์น๋ช " ๋๋ "Branch" ์น์ ) | |
| BRANCH_NAME=$(grep -A 2 "๋ธ๋์น๋ช \|Branch" issue_body.txt | tail -1 | xargs) | |
| # ๋ธ๋์น๋ช ์ฌ์ถ์ถ (๋น ์ค์ด๋ ํค๋๊ฐ ์ถ์ถ๋ ๊ฒฝ์ฐ) | |
| if [ -z "$BRANCH_NAME" ] || [[ "$BRANCH_NAME" == "###"* ]] || [[ "$BRANCH_NAME" == "๐ณ"* ]]; then | |
| BRANCH_NAME=$(sed -n '/Branch/,/###/{/Branch/n; /###/!p;}' issue_body.txt | grep -v "^$" | head -1 | xargs) | |
| fi | |
| # ๋ธ๋์น ํ์ ์ถ์ถ ("๋ธ๋์น ํ์ " ๋๋ "branchType" ์น์ ) | |
| BRANCH_TYPE=$(grep -A 2 "๋ธ๋์น ํ์ \|branchType" issue_body.txt | tail -1 | xargs) | |
| # ๋ธ๋์น ํ์ ์ฌ์ถ์ถ (๋น ์ค์ด๋ ํค๋๊ฐ ์ถ์ถ๋ ๊ฒฝ์ฐ) | |
| if [ -z "$BRANCH_TYPE" ] || [[ "$BRANCH_TYPE" == "###"* ]] || [[ "$BRANCH_TYPE" == "๐"* ]]; then | |
| BRANCH_TYPE=$(sed -n '/๋ธ๋์น ํ์ /,/###/{/๋ธ๋์น ํ์ /n; /###/!p;}' issue_body.txt | grep -v "^$" | head -1 | xargs) | |
| fi | |
| echo "์ถ์ถ๋ ๋ธ๋์น ํ์ : $BRANCH_TYPE" | |
| # ์ด์ ์ ๋ชฉ ์์ฑ ([Type] #๋ฒํธ - ์ ๋ชฉ ํ์) | |
| if [ -n "$BRANCH_TYPE" ] && [ -n "$ISSUE_TITLE" ]; then | |
| if [[ ! "$ISSUE_TITLE" =~ ^\[.*\] ]]; then | |
| # ํ์ค์นผ์ผ์ด์ค ๋ณํ | |
| BRANCH_TYPE_PASCAL=$(echo "$BRANCH_TYPE" | sed 's/\b\(.\)/\u\1/') | |
| NEW_ISSUE_TITLE="[${BRANCH_TYPE_PASCAL}] #${{ github.event.issue.number }} - ${ISSUE_TITLE}" | |
| echo "์๋ก์ด ์ด์ ์ ๋ชฉ: $NEW_ISSUE_TITLE" | |
| else | |
| NEW_ISSUE_TITLE="$ISSUE_TITLE" | |
| echo "์ด์ ์ ๋ชฉ์ ์ด๋ฏธ ํ์ ์ด ํฌํจ๋์ด ์์ต๋๋ค." | |
| fi | |
| else | |
| NEW_ISSUE_TITLE="$ISSUE_TITLE" | |
| fi | |
| # ๋ธ๋์น๋ช ์์ฑ | |
| if [ -z "$BRANCH_NAME" ]; then | |
| echo "๋ธ๋์น๋ช ์ ์ฐพ์ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ." | |
| BRANCH_NAME="issue-${{ github.event.issue.number }}" | |
| else | |
| # Git ๋ธ๋์น๋ช ๊ท์น์ ๋ง๊ฒ ์ ์ (ํ๊ธ ํ์ฉ) | |
| # 1. ๊ณต๋ฐฑ์ ํ์ดํ์ผ๋ก ๋ณ๊ฒฝ | |
| BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/ /-/g') | |
| # 2. Git ๋นํ์ฉ ํน์๋ฌธ์ ์ ๊ฑฐ (:, ^, ~, ?, *, [, \, .., @{) | |
| BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[:^~?*\[\\]//g; s/\.\.//g; s/@{//g') | |
| # 3. ์ฐ์๋ ํ์ดํ/์ฌ๋์ ์ ๊ฑฐ | |
| BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/--*/-/g; s/\/\/*\//\//g') | |
| # 4. ์๋ค ํ์ดํ/์ฌ๋์/์ ์ ๊ฑฐ | |
| BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^[-\/\.]*//; s/[-\/\.]*$//') | |
| # 5. ๋น ๋ฌธ์์ด ๊ฒ์ฆ | |
| if [ -z "$BRANCH_NAME" ]; then | |
| echo "์ ์ ํ ๋ธ๋์น๋ช ์ด ๋น์ด์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ." | |
| BRANCH_NAME="issue-${{ github.event.issue.number }}" | |
| else | |
| # ๋ธ๋์น ํ์ prefix ์ถ๊ฐ (type/) | |
| if [ -n "$BRANCH_TYPE" ]; then | |
| if [[ ! "$BRANCH_NAME" =~ ^$BRANCH_TYPE/ ]]; then | |
| BRANCH_NAME="${BRANCH_TYPE}/${BRANCH_NAME}" | |
| fi | |
| fi | |
| # ์ด์๋ฒํธ prefix ์ถ๊ฐ (๋ฒํธ-) | |
| BRANCH_NAME="${{ github.event.issue.number }}-$BRANCH_NAME" | |
| fi | |
| fi | |
| echo "์ต์ข ๋ธ๋์น๋ช : $BRANCH_NAME" | |
| echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| echo "new_issue_title=$NEW_ISSUE_TITLE" >> $GITHUB_OUTPUT | |
| echo "branch_type=$BRANCH_TYPE" >> $GITHUB_OUTPUT | |
| # ์์ ํ์ผ ์ ๋ฆฌ | |
| rm -f issue_body.txt | |
| - name: Update issue title and labels | |
| run: | | |
| NEW_TITLE="${{ steps.extract.outputs.new_issue_title }}" | |
| BRANCH_TYPE="${{ steps.extract.outputs.branch_type }}" | |
| # ๋ธ๋์น ํ์ ๋ณ ์ด๋ชจ์ง ๋ผ๋ฒจ ๋งคํ | |
| case "$BRANCH_TYPE" in | |
| "feat") LABEL="โจFeature" ;; | |
| "fix") LABEL="๐BugFix" ;; | |
| "hotfix") LABEL="๐จHotfix" ;; | |
| "refactor") LABEL="โป๏ธRefactor" ;; | |
| "test") LABEL="โ Test" ;; | |
| "docs") LABEL="๐Docs" ;; | |
| "chore") LABEL="๐ ๏ธ Chore" ;; | |
| *) LABEL="$BRANCH_TYPE" ;; | |
| esac | |
| # ์ด์ ๋ฉํ๋ฐ์ดํฐ ์ ๋ฐ์ดํธ (์ ๋ชฉ, ๋ผ๋ฒจ, ๋ด๋น์) | |
| if [ -n "$NEW_TITLE" ] && [ -n "$LABEL" ]; then | |
| curl -X PATCH \ | |
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \ | |
| -d "{\"title\":\"$NEW_TITLE\",\"labels\":[\"$LABEL\"],\"assignees\":[\"${{ github.event.issue.user.login }}\"]}" | |
| echo "์ด์ ์ ๋ชฉ ์ ๋ฐ์ดํธ: $NEW_TITLE" | |
| echo "๋ผ๋ฒจ ์ค์ : $LABEL" | |
| echo "๋ด๋น์ ํ ๋น: ${{ github.event.issue.user.login }}" | |
| fi | |
| - name: Create branch | |
| run: | | |
| BRANCH_NAME="${{ steps.extract.outputs.branch_name }}" | |
| # Git ์ค์ | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Main ๋ธ๋์น ๊ธฐ๋ฐ์ผ๋ก ์ ๋ธ๋์น ์์ฑ | |
| git checkout main | |
| git pull origin main | |
| git checkout -b "$BRANCH_NAME" | |
| git push origin "$BRANCH_NAME" | |
| echo "๋ธ๋์น '$BRANCH_NAME' ์์ฑ ์๋ฃ" | |
| - name: Add comment to issue | |
| env: | |
| BRANCH_NAME: ${{ steps.extract.outputs.branch_name }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # ์ด์์ ๋ธ๋์น ์์ฑ ์๋ฆผ ๋๊ธ ์ถ๊ฐ | |
| COMMENT=$(cat <<EOF | |
| ๐ฟ ๋ธ๋์น๊ฐ ์์ฑ๋์์ต๋๋ค! | |
| \`\`\` | |
| $BRANCH_NAME | |
| \`\`\` | |
| EOF | |
| ) | |
| gh issue comment ${{ github.event.issue.number }} --body "$COMMENT" | |
| echo "์ด์์ ๋๊ธ ์ถ๊ฐ ์๋ฃ" |