From 87190feb3a3e4b509a468f7e3ec61f899baa2d27 Mon Sep 17 00:00:00 2001 From: Jagankumar <53823168+jagankumar-egov@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:33:26 +0530 Subject: [PATCH] branch name validators --- .github/PULL_REQUEST_TEMPLATE/bugfix.md | 13 ++++++++++++ .github/PULL_REQUEST_TEMPLATE/feature.md | 13 ++++++++++++ .github/PULL_REQUEST_TEMPLATE/release.md | 16 ++++++++++++++ .github/hooks/pre-push | 25 ++++++++++++++++++++++ .github/workflows/branch-name-check.yml | 27 ++++++++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/bugfix.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/feature.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/release.md create mode 100644 .github/hooks/pre-push create mode 100644 .github/workflows/branch-name-check.yml diff --git a/.github/PULL_REQUEST_TEMPLATE/bugfix.md b/.github/PULL_REQUEST_TEMPLATE/bugfix.md new file mode 100644 index 00000000000..bdf84d7daa1 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/bugfix.md @@ -0,0 +1,13 @@ +### Bugfix Request + +#### JIRA ID + + +#### Module + + +#### Description + + +#### Related Issues + diff --git a/.github/PULL_REQUEST_TEMPLATE/feature.md b/.github/PULL_REQUEST_TEMPLATE/feature.md new file mode 100644 index 00000000000..c707f5a2fa8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/feature.md @@ -0,0 +1,13 @@ +### Feature Request + +#### JIRA ID + + +#### Module + + +#### Description + + +#### Related Issues + diff --git a/.github/PULL_REQUEST_TEMPLATE/release.md b/.github/PULL_REQUEST_TEMPLATE/release.md new file mode 100644 index 00000000000..5be465075e1 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/release.md @@ -0,0 +1,16 @@ +### Release Request + +#### JIRA ID + + +#### Module + + +#### Description + + +#### List of Features + + +#### List of Issues + diff --git a/.github/hooks/pre-push b/.github/hooks/pre-push new file mode 100644 index 00000000000..30fe241600e --- /dev/null +++ b/.github/hooks/pre-push @@ -0,0 +1,25 @@ +#!/bin/sh + +# Get the current branch name +BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) + +# Define the pattern +PATTERN="^(FEATURE|BUGFIX|RELEASE)\/(HCMPRE|DPG|SN)-[0-9]{1,5}$" + +# Check if the branch name matches the pattern +if [[ ! "$BRANCH_NAME" =~ $PATTERN ]]; then + echo "Branch name '$BRANCH_NAME' does not follow the correct pattern:" + echo " - FEATURE/HCMPRE-" + echo " - FEATURE/DPG-" + echo " - FEATURE/SN-" + echo " - BUGFIX/HCMPRE-" + echo " - BUGFIX/DPG-" + echo " - BUGFIX/SN-" + echo " - RELEASE/HCMPRE-" + echo " - RELEASE/DPG-" + echo "Where is a number between 0 and 99999." + exit 1 +fi + +# If the pattern matches, allow the push +exit 0 diff --git a/.github/workflows/branch-name-check.yml b/.github/workflows/branch-name-check.yml new file mode 100644 index 00000000000..bacd6bc459e --- /dev/null +++ b/.github/workflows/branch-name-check.yml @@ -0,0 +1,27 @@ +name: Branch Name Validation + +on: + push: + branches: + - master + - develop + pull_request: + branches: + - master + - develop + +jobs: + validate-branch-name: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Validate branch name + run: | + branch_name=$(echo "${GITHUB_REF#refs/heads/}") + pattern="^(FEATURE|BUGFIX|RELEASE)\/(HCMPRE|DPG|SN)-[0-9]{1,5}$" + if [[ ! "$branch_name" =~ $pattern ]]; then + echo "Branch name '$branch_name' does not follow the correct pattern: FEATURE/HCMPRE-, FEATURE/DPG-, FEATURE/SN-, BUGFIX/SN-, BUGFIX/HCMPRE-, or BUGFIX/DPG- where x is a number between 0 and 99999" + exit 1 + fi