Skip to content

feat: Updated the workflow to allow PRs not tied to an issue. #3

feat: Updated the workflow to allow PRs not tied to an issue.

feat: Updated the workflow to allow PRs not tied to an issue. #3

name: Require Closing Keyword
on:
pull_request:
branches:
- master
types: [opened, edited, synchronize, reopened]
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Ensure PR closes an issue
uses: actions/github-script@v7
with:
script: |
const body = context.payload.pull_request.body || '';
const labels =
(context.payload.pull_request.labels || []).map(l => l.name.toLowerCase());
const bypassLabels = ['no-issue', 'chore', 'docs', 'maintenance'];
const hasBypassLabel = labels.some(name => bypassLabels.includes(name));
const keywordPattern = /(close[sd]?|fix(e[sd])?|resolve[sd]?)\s+((#[0-9]+)|([\w.-]+\/[\w.-]+#\d+))/i;
const hasKeyword = keywordPattern.test(body);
if (!hasKeyword && !hasBypassLabel) {
core.setFailed(
'Add a closing keyword like "Closes #123" to the PR description or apply the "no-issue" label for work not tied to a tracked issue.',
);
}