-
Notifications
You must be signed in to change notification settings - Fork 2
38 lines (32 loc) · 1.34 KB
/
pr-validator.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
31
32
33
34
35
36
37
38
name: "PR Title and Description Check"
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
check-title-and-description:
runs-on: ubuntu-latest
steps:
- name: Check PR title and description
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload;
const prTitle = payload.pull_request.title;
const prDescription = payload.pull_request.body;
// The pattern for JIRA ticket format
const jiraPattern = /\b[A-Z]+-\d+\b|breakglass/gi;
// Check PR title
const hasJiraTitle = jiraPattern.test(prTitle);
console.log(`PR title: ${hasJiraTitle ? 'Valid' : 'Invalid'}`);
// Check PR description
const hasJiraDescription = prDescription ? prDescription.match(jiraPattern) : false;
console.log(`PR description: ${hasJiraDescription ? 'Valid' : 'Invalid'}`);
if (hasJiraTitle || hasJiraDescription) {
console.log('PR title or description format is correct.');
} else {
const errorMessage = [];
errorMessage.push('The PR title and description do not include a valid JIRA ticket!');
console.log(errorMessage.join('\n'));
core.setFailed(errorMessage.join('\n'));
}