1+ # Copyright The Linux Foundation and each contributor to LFX.
2+ # SPDX-License-Identifier: MIT
3+ name : Jira PR Validation
4+
5+ on :
6+ pull_request :
7+ types : [opened, edited, reopened, synchronize]
8+
9+ jobs :
10+ validate-jira-key :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : Check for Jira issue key in PR title
14+ uses : actions/github-script@v7
15+ with :
16+ script : |
17+ const prTitle = context.payload.pull_request.title;
18+ console.log(`PR Title: ${prTitle}`);
19+
20+ // Regex to match Jira issue keys (CDP-123 format)
21+ // Supports conventional commits format: type(CDP-123): description
22+ const jiraKeyRegex = /\b[A-Z]+-\d+\b/;
23+
24+ if (!jiraKeyRegex.test(prTitle)) {
25+ const warningMessage = `⚠️ **Jira Issue Key Missing**
26+
27+ Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.
28+
29+ **Examples:**
30+ - \`feat: add user authentication [PROJ-123]\`
31+ - \`fix(PROJ-123): resolve login issue [PROJ-456]\`
32+
33+ This is a reminder only - you can still merge this PR.`;
34+
35+ github.rest.issues.createComment({
36+ issue_number: context.issue.number,
37+ owner: context.repo.owner,
38+ repo: context.repo.repo,
39+ body: warningMessage
40+ });
41+
42+ // Set status but don't fail the check
43+ github.rest.repos.createCommitStatus({
44+ owner: context.repo.owner,
45+ repo: context.repo.repo,
46+ sha: context.payload.pull_request.head.sha,
47+ state: 'pending',
48+ target_url: 'https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/actions',
49+ description: 'Jira issue key not found in PR title',
50+ context: 'Jira PR Validation'
51+ });
52+ } else {
53+ const match = prTitle.match(jiraKeyRegex);
54+ console.log(`✅ Found Jira issue key: ${match[0]}`);
55+
56+ github.rest.repos.createCommitStatus({
57+ owner: context.repo.owner,
58+ repo: context.repo.repo,
59+ sha: context.payload.pull_request.head.sha,
60+ state: 'success',
61+ target_url: 'https://github.com/' + context.repo.owner + '/' + context.repo.repo + '/actions',
62+ description: `Jira issue key found: ${match[0]}`,
63+ context: 'Jira PR Validation'
64+ });
65+ }
0 commit comments