fix: use correct merge API endpoint in LFID enrichment (CM-1142) #3548
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Title - Jira Key Validation | |
| on: | |
| pull_request: | |
| types: [opened, edited, reopened] | |
| jobs: | |
| validate-jira-key-in-pr-title: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.draft == false | |
| permissions: | |
| pull-requests: write | |
| checks: write | |
| steps: | |
| - name: Check for Jira issue key in PR title | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prTitle = context.payload.pull_request.title; | |
| const prNumber = context.issue.number; | |
| const { owner, repo } = context.repo; | |
| const headSha = context.payload.pull_request.head.sha; | |
| const COMMENT_MARKER = '<!-- jira-key-validation-comment -->'; | |
| const jiraKeyRegex = /\b[A-Z]+-\d+\b/; | |
| console.log(`PR Title: ${prTitle}`); | |
| const matchingComments = []; | |
| const perPage = 100; | |
| for (let page = 1; ; page += 1) { | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| per_page: perPage, | |
| page, | |
| }); | |
| for (const c of comments) { | |
| if (c.user?.type === 'Bot' && c.body?.includes(COMMENT_MARKER)) { | |
| matchingComments.push(c); | |
| } | |
| } | |
| if (comments.length < perPage) break; | |
| } | |
| if (!jiraKeyRegex.test(prTitle)) { | |
| const warningMessage = [ | |
| COMMENT_MARKER, | |
| '⚠️ **Jira Issue Key Missing**', | |
| '', | |
| "Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.", | |
| '', | |
| '**Example:**', | |
| '- `feat: add user authentication (CM-123)`', | |
| '- `feat: add user authentication (IN-123)`', | |
| '', | |
| '**Projects:**', | |
| '- CM: Community Data Platform', | |
| '- IN: Insights', | |
| '', | |
| 'Please add a Jira issue key to your PR title.', | |
| ].join('\n'); | |
| if (matchingComments.length === 0) { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| body: warningMessage, | |
| }); | |
| } else { | |
| const [keep, ...extras] = matchingComments; | |
| if (keep.body !== warningMessage) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: keep.id, | |
| body: warningMessage, | |
| }); | |
| } | |
| for (const extra of extras) { | |
| await github.rest.issues.deleteComment({ owner, repo, comment_id: extra.id }); | |
| } | |
| } | |
| await github.rest.checks.create({ | |
| owner, | |
| repo, | |
| head_sha: headSha, | |
| name: 'Jira PR Validation', | |
| status: 'completed', | |
| conclusion: 'neutral', | |
| output: { | |
| title: 'Jira Issue Key Missing', | |
| summary: 'PR title does not contain a Jira issue key', | |
| }, | |
| }); | |
| } else { | |
| const match = prTitle.match(jiraKeyRegex); | |
| console.log(`✅ Found Jira issue key: ${match[0]}`); | |
| for (const c of matchingComments) { | |
| await github.rest.issues.deleteComment({ owner, repo, comment_id: c.id }); | |
| } | |
| await github.rest.checks.create({ | |
| owner, | |
| repo, | |
| head_sha: headSha, | |
| name: 'Jira PR Validation', | |
| status: 'completed', | |
| conclusion: 'success', | |
| output: { | |
| title: 'Jira Issue Key Found', | |
| summary: `Found Jira issue key: ${match[0]}`, | |
| }, | |
| }); | |
| } |