Skip to content

タイトルの翻訳 #29

タイトルの翻訳

タイトルの翻訳 #29

name: Create Branch on Issue Assign
on:
issues:
types: [assigned]
workflow_dispatch:
inputs:
issue_number:
description: "Issue number to process"
required: true
type: number
jobs:
check_labels_and_create_branch:
runs-on: ubuntu-latest
permissions:
issues: write
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check labels and create branch
id: check_and_create
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
ISSUE_NUMBER="${{ github.event.inputs.issue_number }}"
else
ISSUE_NUMBER="${{ github.event.issue.number }}"
fi
ISSUE_DATA=$(gh issue view $ISSUE_NUMBER --json number,title,assignees,labels)
ASSIGNEE=$(echo "$ISSUE_DATA" | jq -r '.assignees[0].login // empty')
LABELS=$(echo "$ISSUE_DATA" | jq -r '.labels[].name // empty')
echo "Debug: ISSUE_DATA=$ISSUE_DATA"
echo "Debug: ASSIGNEE=$ASSIGNEE"
echo "Debug: LABELS=$LABELS"
if [ -z "$ASSIGNEE" ]; then
echo "Error: Issue is not assigned"
exit 1
fi
# Define label to branch prefix mapping
declare -A LABEL_PREFIX_MAP
LABEL_PREFIX_MAP=(
["bug"]="fix"
["feature"]="feat"
["enhancement"]="enhance"
["documentation"]="doc"
["refactor"]="refactor"
["chore"]="chore"
)
VALID_LABELS=$(echo "${!LABEL_PREFIX_MAP[@]}" | tr ' ' '|')
BRANCH_LABEL=$(echo "$LABELS" | tr ' ' '\n' | grep -m1 -E "$VALID_LABELS")
if [ -z "$BRANCH_LABEL" ]; then
echo "no_valid_label=true" >> $GITHUB_OUTPUT
echo "issue_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
exit 0
fi
echo "Debug: Matching label found: $BRANCH_LABEL"
BRANCH_PREFIX=${LABEL_PREFIX_MAP[$BRANCH_LABEL]}
BRANCH_NAME="${ASSIGNEE,,}/${BRANCH_PREFIX}-issue-${ISSUE_NUMBER}"
echo "Debug: BRANCH_NAME=$BRANCH_NAME"
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
gh issue comment $ISSUE_NUMBER --body "Created branch \`$BRANCH_NAME\`"
- name: Comment on missing label
if: steps.check_and_create.outputs.no_valid_label == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ steps.check_and_create.outputs.issue_number }}
run: |
COMMENT="Thank you for working on this issue. To help us categorize and prioritize it better, please add one of the following labels:
- bug: Something isn't working as expected
- feature: New feature implementation
- enhancement: Improvement to existing features
- documentation: Improvements or additions to documentation
- refactor: Code refactoring
- chore: General maintenance tasks
Adding an appropriate label will help our team quickly understand the nature of the issue and create the correct branch. Once you've added a label, we'll automatically create a branch for this issue. Thank you for your cooperation!"
gh issue comment $ISSUE_NUMBER --body "$COMMENT"