From c4cc0bc53abb0bd4bee4d344985532d2d942e63a Mon Sep 17 00:00:00 2001 From: Rajasimman S Date: Fri, 19 Sep 2025 11:42:39 +0530 Subject: [PATCH 1/4] fix: update commit message validation pattern for improved accuracy --- commit-message-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commit-message-validator.js b/commit-message-validator.js index f11ca61..2162420 100644 --- a/commit-message-validator.js +++ b/commit-message-validator.js @@ -5,7 +5,7 @@ async function run() { try { // Get inputs from workflow const token = core.getInput('github-token', { required: true }); - const pattern = core.getInput('pattern') || '^((Merge[ a-z-]* branch.*)|(Revert*)|((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?!?: .*))$'; + const pattern = core.getInput('pattern') || '^(Merge branch \'[^\']+\' into [^\s]+|Revert ".*"|Create PR for #\d+|(?:(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z0-9\-]+\))?: .*))$'; const regexPattern = new RegExp(pattern); // Create octokit client From 2cbd338989022b76a50da4babc1acec1fb90f385 Mon Sep 17 00:00:00 2001 From: Rajasimman S Date: Fri, 19 Sep 2025 11:47:04 +0530 Subject: [PATCH 2/4] refactor: restructure commit message validation pattern for clarity and maintainability --- commit-message-validator.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/commit-message-validator.js b/commit-message-validator.js index 2162420..9e5a088 100644 --- a/commit-message-validator.js +++ b/commit-message-validator.js @@ -5,7 +5,17 @@ async function run() { try { // Get inputs from workflow const token = core.getInput('github-token', { required: true }); - const pattern = core.getInput('pattern') || '^(Merge branch \'[^\']+\' into [^\s]+|Revert ".*"|Create PR for #\d+|(?:(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z0-9\-]+\))?: .*))$'; + + const mergeBranchPattern = "Merge branch '[^']+' into [^\\s]+"; + const revertPattern = 'Revert ".*"'; + const createPrPattern = 'Create PR for #\\d+'; + const types = [ + 'feat', 'fix', 'chore', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'revert' + ].join('|'); + const conventionalPattern = `(?:(${types})(\\([a-z0-9\\-]+\\))?: .*)`; + + const defaultPattern = `^(${mergeBranchPattern}|${revertPattern}|${createPrPattern}|${conventionalPattern})$`; + const pattern = core.getInput('pattern') || defaultPattern; const regexPattern = new RegExp(pattern); // Create octokit client From 2ce64a9c28c01f34f90931fbb30189c287e92ab9 Mon Sep 17 00:00:00 2001 From: Rajasimman S Date: Fri, 19 Sep 2025 11:49:47 +0530 Subject: [PATCH 3/4] chore: add permissions section to workflow files for clarity --- .github/workflows/time-to-review.yml | 4 ++++ .github/workflows/validate-commits.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/time-to-review.yml b/.github/workflows/time-to-review.yml index bdc0fc3..9ec118c 100644 --- a/.github/workflows/time-to-review.yml +++ b/.github/workflows/time-to-review.yml @@ -4,6 +4,10 @@ on: pull_request: types: [opened, synchronize] +permissions: + pull-requests: read + issues: write + jobs: time-to-review: runs-on: ubuntu-latest diff --git a/.github/workflows/validate-commits.yml b/.github/workflows/validate-commits.yml index 9c53b93..964c207 100644 --- a/.github/workflows/validate-commits.yml +++ b/.github/workflows/validate-commits.yml @@ -4,6 +4,10 @@ on: pull_request: types: [opened, synchronize, reopened] +permissions: + contents: read + pull-requests: write + jobs: validate-commits: runs-on: ubuntu-latest From 6c127726ae71d089c264e12bca8107f99ad9bbe1 Mon Sep 17 00:00:00 2001 From: Rajasimman S Date: Fri, 19 Sep 2025 11:57:29 +0530 Subject: [PATCH 4/4] fix: correct regex patterns for merge and create PR commit messages --- commit-message-validator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commit-message-validator.js b/commit-message-validator.js index 9e5a088..12ad720 100644 --- a/commit-message-validator.js +++ b/commit-message-validator.js @@ -6,15 +6,15 @@ async function run() { // Get inputs from workflow const token = core.getInput('github-token', { required: true }); - const mergeBranchPattern = "Merge branch '[^']+' into [^\\s]+"; + const mergeBranchPattern = 'Merge branch [\'"][^\'"]+[\'"] into [^\\s]+'; const revertPattern = 'Revert ".*"'; - const createPrPattern = 'Create PR for #\\d+'; + const createPrPattern = core.getInput('create-pr-pattern') || 'Create PR for #\\d+'; const types = [ 'feat', 'fix', 'chore', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'revert' ].join('|'); - const conventionalPattern = `(?:(${types})(\\([a-z0-9\\-]+\\))?: .*)`; + const conventionalPattern = `(?:(${types})(\\([a-z0-9\\-]+\\))?(!)?: .*)`; - const defaultPattern = `^(${mergeBranchPattern}|${revertPattern}|${createPrPattern}|${conventionalPattern})$`; + const defaultPattern = `^(${mergeBranchPattern}|${revertPattern}${createPrPattern ? '|' + createPrPattern : ''}|${conventionalPattern})$`; const pattern = core.getInput('pattern') || defaultPattern; const regexPattern = new RegExp(pattern);