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 diff --git a/commit-message-validator.js b/commit-message-validator.js index f11ca61..12ad720 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[ a-z-]* branch.*)|(Revert*)|((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?!?: .*))$'; + + const mergeBranchPattern = 'Merge branch [\'"][^\'"]+[\'"] into [^\\s]+'; + const revertPattern = 'Revert ".*"'; + 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 defaultPattern = `^(${mergeBranchPattern}|${revertPattern}${createPrPattern ? '|' + createPrPattern : ''}|${conventionalPattern})$`; + const pattern = core.getInput('pattern') || defaultPattern; const regexPattern = new RegExp(pattern); // Create octokit client