Skip to content

Commit 0e4eeff

Browse files
authored
FDN-4209 Update pr-validator workflow (#47)
1 parent 1e2027d commit 0e4eeff

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

.github/workflows/pr-validator.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "PR Title and Description Check"
2+
on:
3+
pull_request:
4+
types: [opened, edited, synchronize]
5+
6+
jobs:
7+
check-title-and-description:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check PR title and description
11+
uses: actions/github-script@v4
12+
with:
13+
github-token: ${{ secrets.GITHUB_TOKEN }}
14+
script: |
15+
const payload = context.payload;
16+
const prTitle = payload.pull_request.title;
17+
18+
// The pattern for JIRA ticket format
19+
// Must be at the beginning of the PR title
20+
// Prefix must be at least 3 uppercase letters
21+
// Excludes tickets with only zeros after the prefix (e.g., XXX-000, XXX-0000)
22+
// Number must be 3 to 6 digits
23+
const jiraPattern = /^[A-Z]{3,}-(?!0+\b)\d{3,6}\b/;
24+
25+
// Check PR title
26+
const hasJiraTitle = jiraPattern.test(prTitle);
27+
console.log(`PR title: ${hasJiraTitle ? 'Valid' : 'Invalid'}`);
28+
29+
if (hasJiraTitle) {
30+
console.log('PR title format is correct.');
31+
} else {
32+
const errorMessage = 'The PR title must start with a valid JIRA ticket with 3-6 digits (e.g., ABC-123, DATAPLATFORM-12345). The ticket must be at the start, use at least 3 uppercase letters, and the number must not be all zeros.';
33+
console.log(errorMessage);
34+
35+
core.setFailed(errorMessage);
36+
}

0 commit comments

Comments
 (0)