1+ name : PR Title - Jira Key Validation
2+
3+ on :
4+ pull_request :
5+ types : [opened, edited, reopened, synchronize]
6+
7+ jobs :
8+ validate-jira-key-in-pr-title :
9+ runs-on : ubuntu-latest
10+ if : github.event.pull_request.draft == false
11+ permissions :
12+ pull-requests : write
13+ checks : write
14+ steps :
15+ - name : Check for Jira issue key in PR title
16+ uses : actions/github-script@v7
17+ with :
18+ script : |
19+ const prTitle = context.payload.pull_request.title;
20+ console.log(`PR Title: ${prTitle}`);
21+
22+ // Regex to match Jira issue keys (CDP-123 format)
23+ // Supports conventional commits format: type(CDP-123): description
24+ const jiraKeyRegex = /\b[A-Z]+-\d+\b/;
25+
26+ if (!jiraKeyRegex.test(prTitle)) {
27+ const warningMessage = `⚠️ **Jira Issue Key Missing**
28+
29+ Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.
30+
31+ **Examples:**
32+ - \`feat: add user authentication (CDP-123)\`
33+ - \`fix(CDP-123): resolve login issue\`
34+
35+ Please add a Jira issue key to your PR title.`;
36+
37+ github.rest.issues.createComment({
38+ issue_number: context.issue.number,
39+ owner: context.repo.owner,
40+ repo: context.repo.repo,
41+ body: warningMessage
42+ });
43+
44+ // Create check run with failure conclusion
45+ github.rest.checks.create({
46+ owner: context.repo.owner,
47+ repo: context.repo.repo,
48+ head_sha: context.payload.pull_request.head.sha,
49+ name: 'Jira PR Validation',
50+ status: 'completed',
51+ conclusion: 'neutral',
52+ output: {
53+ title: 'Jira Issue Key Missing',
54+ summary: 'PR title does not contain a Jira issue key'
55+ }
56+ });
57+ } else {
58+ const match = prTitle.match(jiraKeyRegex);
59+ console.log(`✅ Found Jira issue key: ${match[0]}`);
60+
61+ // Create check run with success conclusion
62+ github.rest.checks.create({
63+ owner: context.repo.owner,
64+ repo: context.repo.repo,
65+ head_sha: context.payload.pull_request.head.sha,
66+ name: 'Jira PR Validation',
67+ status: 'completed',
68+ conclusion: 'success',
69+ output: {
70+ title: 'Jira Issue Key Found',
71+ summary: `Found Jira issue key: ${match[0]}`
72+ }
73+ });
74+ }
0 commit comments