-
Notifications
You must be signed in to change notification settings - Fork 20
49 lines (43 loc) · 1.83 KB
/
git-auto-issue-branch-creation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: Auto create git branch upon new issue
on:
issues:
types: [opened, reopened]
jobs:
create-issue-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get issue number and title
id: issue
run: |
echo "::set-output name=number::${{ github.event.issue.number }}"
echo "::set-output name=title::${{ github.event.issue.title }}"
# Sanitize issue title to:
# - alnum
# - replace spaces with hyphen '-'
# Example:
# Given an issue title: "Fix the 2'nd bug in UI where there's a # in the form"
# Becomes:
#
# Note there is a space here, to keep both '-' and spaces ' '
echo ISSUE_BRANCH_NAME=`echo "${{ github.event.issue.title }}" | \
# Remove non alpha/numeric chars
tr -cd '[:alnum:]- ' | \
# Convert spaces to hyphens '-'
tr ' ' '-' | \
# Ensure lowercase branch name
tr '[:upper:]' '[:lower:]' | \
# Limit branch name to 60 characters
cut -c -60` >> $GITHUB_ENV
ALLOWED_BRANCH_NAME_CHARS='[^a-zA-Z0-9-]'
# Loop through each character in the branch name, replacing any not allowed characer with a hyphen '-'
while [[ $ISSUE_BRANCH_NAME =~ $ALLOWED_BRANCH_NAME_CHARS ]]; do
ISSUE_BRANCH_NAME=`echo $ISSUE_BRANCH_NAME | sed -r "s/($ALLOWED_BRANCH_NAME_CHARS)/-/g" | sed 's/--/-/g'`
done
echo $ISSUE_BRANCH_NAME >> $GITHUB_ENV
- name: Create new branch
run: |
echo "The issue branch name is ${{ env.ISSUE_BRANCH_NAME}} "
git checkout -b "${{ steps.issue.outputs.number }}-${{ env.ISSUE_BRANCH_NAME }}"
git push -u origin HEAD