-
Notifications
You must be signed in to change notification settings - Fork 1
30 lines (30 loc) · 1.08 KB
/
pr-title-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# From: https://levelup.gitconnected.com/enforcing-jira-ticket-formatting-in-github-pr-titles-and-commit-messages-78d9755568df
name: "PR Title Check"
on:
pull_request:
branches:
- dev
- main
- 'release/**'
- 'hotfix/**'
types: [opened, edited, synchronize]
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Check PR title
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload
const prTitle = payload.pull_request.title
const prTitleExpectedPattern = /(^LNK-\d+:\s)|(^TECH_DEBT:\s)/g
const prTitleMismatchError = 'Invalid PR title! Must begin with LNK-nnnn:<space> or TECH_DEBT:<space>, e.g. LNK-1234: My PR title, or TECH_DEBT: My PR title'
if (!prTitleExpectedPattern.test(prTitle)) {
// Fail the workflow
console.log(prTitleMismatchError)
core.setFailed(prTitleMismatchError)
} else {
console.log('PR title format is correct.')
}