diff --git a/.github/workflows/create-branch-on-issue-assign.yml b/.github/workflows/create-branch-on-issue-assign.yml new file mode 100644 index 00000000..fb854063 --- /dev/null +++ b/.github/workflows/create-branch-on-issue-assign.yml @@ -0,0 +1,40 @@ +name: Create Branch on Issue Assign + +on: + issues: + types: [assigned] + +jobs: + create_branch: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Create branch + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE_NUMBER: ${{ github.event.issue.number }} + ISSUE_TITLE: ${{ github.event.issue.title }} + ASSIGNEE: ${{ github.event.assignee.login }} + run: | + LABELS=$(gh issue view $ISSUE_NUMBER --json labels -q '.labels[].name') + + for LABEL in $LABELS; do + case $LABEL in + "feature") TYPE="feat"; break ;; + "bug") TYPE="fix"; break ;; + "documentation") TYPE="docs"; break ;; + "refactor") TYPE="refactor"; break ;; + "chore") TYPE="chore"; break ;; + esac + done + + BRANCH_NAME="${ASSIGNEE,,}/issue-${ISSUE_NUMBER}-${TYPE}" + + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git checkout -b "$BRANCH_NAME" + git push origin "$BRANCH_NAME" + + gh issue comment $ISSUE_NUMBER --body "created branch \`$BRANCH_NAME\`"