release(4.0.1): public redaction helpers, ReDoS validator latency, phantom ban, singleton resets, path-level gates #38
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: Issue link | |
| on: | |
| pull_request: | |
| types: [opened, edited, reopened, synchronize, labeled, unlabeled] | |
| permissions: | |
| issues: read | |
| pull-requests: read | |
| jobs: | |
| issue-link: | |
| name: issue-link | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| if (pr.user.type === 'Bot') return core.info(`bot author ${pr.user.login}, exempt`); | |
| if (pr.labels.some((label) => label.name === 'no-issue')) return core.info('no-issue label, exempt'); | |
| const pattern = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?|delivers?(?:\s+issue)?)\b:?\s*(?:https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/|#)(\d+)/gi; | |
| const numbers = [...new Set([...(pr.body || '').matchAll(pattern)].map((match) => Number(match[1])))]; | |
| if (numbers.length === 0) return core.setFailed('PR body must say "Closes #N" for an open issue in this repo, or the PR must carry the no-issue label'); | |
| const reasons = []; | |
| for (const number of numbers) { | |
| try { | |
| const { data } = await github.rest.issues.get({ ...context.repo, issue_number: number }); | |
| if (data.pull_request) reasons.push(`#${number} is a pull request, not an issue`); | |
| else if (data.state !== 'open') reasons.push(`#${number} is ${data.state}`); | |
| else return core.info(`delivers open issue #${number}`); | |
| } catch (error) { | |
| reasons.push(`#${number}: ${error.message}`); | |
| } | |
| } | |
| core.setFailed(reasons.join('; ')); |