From d8b20b6d62733b796c51805cceb568e0b4163723 Mon Sep 17 00:00:00 2001 From: Vaishnavi Mudaliar Date: Sun, 14 Jul 2024 15:12:39 +0530 Subject: [PATCH] Create pr-title-check.yml Created a new GitHub Action workflow (`pr-title-check.yml`) that verifies if pull request titles start with one of the specified prefixes: "feat:", "fix:", "test:", "chore:", "docs:". This ensures consistency and clarity in PR titles, helping to categorize changes effectively. The action uses JavaScript to validate titles and provides feedback if they do not meet the required format. --- .github/workflows/pr-title-check.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/pr-title-check.yml diff --git a/.github/workflows/pr-title-check.yml b/.github/workflows/pr-title-check.yml new file mode 100644 index 00000000000..51bb8b84d7f --- /dev/null +++ b/.github/workflows/pr-title-check.yml @@ -0,0 +1,26 @@ +name: PR Title Check + +on: + pull_request: + types: [opened, edited] + +jobs: + check-pr-title: + runs-on: ubuntu-latest + + steps: + - name: Check PR Title Prefix + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const title = context.payload.pull_request.title.trim(); + const allowedPrefixes = ["feat:", "fix:", "test:", "chore:", "docs:"]; + const prefixRegex = new RegExp(`^(${allowedPrefixes.join('|')})`, 'i'); + + if (!prefixRegex.test(title)) { + const errorMessage = `PR title does not start with one of the allowed prefixes: ${allowedPrefixes.join(', ')}`; + core.setFailed(errorMessage); + } else { + console.log('PR title check passed successfully.'); + }