Skip to content
name: Label and Create Branch for New Issues
on:
issues:
types: [opened, unlabeled]
jobs:
label-and-create-branch:
runs-on: ubuntu-latest
permissions:
issues: write
contents: write
pull-requests: write
discussions: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get conditions.json path
id: get-conditions-path
run: |
cd .github/workflows
ROOT_PATH=$(pwd)
CONDITIONS_PATH="${ROOT_PATH}/conditions.json"
echo "$CONDITIONS_PATH"
echo "::set-output name=conditions_path::$CONDITIONS_PATH"
- name: Determine label based on condition
id: determine-label
run: |
label_out=$(jq -r --arg issueTitle "$ISSUE_TITLE" '.[] | select(.program == $issueTitle) | .label' $CONDITIONS_PATH)
echo "Label: $label_out"
echo "::set-output name=label::$label_out"
env:
CONDITIONS_PATH: ${{ steps.get-conditions-path.outputs.conditions_path }}
ISSUE_TITLE: ${{ github.event.issue.title }}
- name: Print check
run: echo "There is an issue containing the word testing"
- name: Add label
run: gh issue edit "$NUMBER" --add-label "$LABELS"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: ${{ steps.determine-label.outputs.label }}
- name: Set Branch Name
id: set-branch-name
run: |
# Extract issue title and replace spaces with hyphens
ISSUE_TITLE=$(echo "$ISSUE_TITLE" | tr ' ' '-')
echo "Issue title: $ISSUE_TITLE"
# Concatenate issue number and transformed title to form branch name
BRANCH_NAME="${ISSUE_NUMBER}-${ISSUE_TITLE}"
echo "full branch name: $BRANCH_NAME"
echo "::set-output name=BRANCH_FULL_NAME::$BRANCH_NAME"
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
- name: Create Branch
id: create-branch
run: |
echo "We will create a branch with this name: $BRANCH_NAME"
gh issue develop $ISSUE_NUMBER -b dev -n $BRANCH_NAME
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BRANCH_NAME: ${{ steps.set-branch-name.outputs.BRANCH_FULL_NAME }}
ISSUE_NUMBER: ${{ github.event.issue.number }}