diff --git a/.github/pr-validator.yml b/.github/pr-validator.yml new file mode 100644 index 0000000..e483de0 --- /dev/null +++ b/.github/pr-validator.yml @@ -0,0 +1,24 @@ +name: "PR Title Check" +on: + pull_request: + types: [opened, edited, synchronize] +jobs: + check-title: + runs-on: ubuntu-latest + steps: + - name: Check PR title + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const payload = context.payload + const prTitle = payload.pull_request.title + // The pattern for JIRA ticket format + const jiraPattern = /([A-Z]+-\d+)|(breakglass)/gi; + if (!jiraPattern.test(prTitle)) { + console.log('The PR title does not match JIRA ticket format!') + // Fails the workflow + core.setFailed('PR title does not match JIRA ticket format!') + } else { + console.log('PR title format is correct.') + }