Skip to content

Commit

Permalink
Merge pull request #2 from agaroot-technologies/chore/consistent-pr
Browse files Browse the repository at this point in the history
[chore] Allow only consistent PR to be created
  • Loading branch information
Karibash authored Oct 3, 2023
2 parents feca478 + 4addfde commit e8d97a1
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/consistent-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Consistent Pull Request

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
consistent-pull-request:
name: Consistent Pull Request
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608

- name: Check head branch name
if: >-
github.event.action == 'opened' &&
github.head_ref != 'main'
env:
HEAD_REF: ${{ github.head_ref }}
PR_NUMBER: ${{ github.event.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! [[ "${HEAD_REF}" =~ ^(feature|bugfix|refactor|chore|deps)/.* ]]; then
echo "::error::Branch name '${HEAD_REF}' does not follow naming convention"
gh pr close "${PR_NUMBER}"
exit 1
fi
- name: Consistent pull request title and label
if: >-
github.event.action != 'synchronize' &&
github.event.pull_request.state == 'open' &&
github.head_ref != 'main'
env:
HEAD_REF: ${{ github.head_ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
label=$(echo "${HEAD_REF}" | cut -d'/' -f1)
pr_title_regex="^\[${label}\]"
if ! [[ "${PR_TITLE}" =~ ${pr_title_regex} ]]; then
PR_TITLE="[${label}] ${PR_TITLE}"
fi
gh pr edit "${PR_NUMBER}" --title "${PR_TITLE}" --add-label "${label}"
- name: Check base branch name
if: >-
github.event.pull_request.state == 'open' &&
github.head_ref != 'main'
env:
BASE_REF: ${{ github.base_ref }}
run: |
if ! [[ "${BASE_REF}" =~ ^main$ ]]; then
echo "::error::Cannot merge into branch name '${BASE_REF}'."
exit 1
fi

0 comments on commit e8d97a1

Please sign in to comment.