refactor metrics decorator #83 #103
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 Issue Link Check | |
| on: | |
| pull_request: | |
| types: [opened, edited, synchronize] | |
| jobs: | |
| check-issue-link: | |
| runs-on: ubuntu-latest | |
| if: github.event.action == 'opened' || github.event.action == 'edited' | |
| steps: | |
| - name: Check if PR references an issue | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number | |
| }); | |
| // Check PR body for issue references | |
| const prBody = pr.body || ''; | |
| const issueRegex = /(fixes|fix|closes|close|resolves|resolve|refs|references)\s+#(\d+)/gi; | |
| const hasIssueReference = issueRegex.test(prBody); | |
| // Check PR title for issue references | |
| const prTitle = pr.title || ''; | |
| const titleIssueRegex = /#\d+/g; | |
| const hasTitleIssueReference = titleIssueRegex.test(prTitle); | |
| if (!hasIssueReference && !hasTitleIssueReference) { | |
| // Create the comment body | |
| const commentBody = [ | |
| '⚠️ **PR Must Reference an Issue**', | |
| '', | |
| "This pull request doesn't reference any issue. Please link your PR to an existing issue by:", | |
| '', | |
| '1. Adding one of the following keywords in your PR description followed by the issue number:', | |
| ' - fixes #123', | |
| ' - closes #123', | |
| ' - resolves #123', | |
| ' - refs #123', | |
| ' - references #123', | |
| '', | |
| '2. Or including the issue number in the PR title like:', | |
| ' - [FEATURE] Add new feature #123', | |
| ' - [BUG] Fix critical bug #123', | |
| '', | |
| `If no issue exists for this change, please [create an issue](https://github.com/${context.repo.owner}/${context.repo.repo}/issues/new) first to describe the problem or feature request.` | |
| ].join('\n'); | |
| // Add comment asking to link an issue | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: commentBody | |
| }); | |
| // Fail the check | |
| core.setFailed('PR must reference an issue'); | |
| } else { | |
| console.log('✅ PR properly references an issue'); | |
| } |