-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce PRs to link with Issues (#289)
Co-authored-by: atmorling <[email protected]>
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Check Linked Issue | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize, edited] | ||
|
||
jobs: | ||
check-linked-issue: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Verify Linked Issue | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const { pull_request } = context.payload; | ||
const bodyText = pull_request.body || ''; | ||
const issuePattern = /(?:close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+#(\d+)/i; | ||
const match = bodyText.match(issuePattern); | ||
if (!match) { | ||
core.setFailed('No linked issue found in the pull request description.'); | ||
return; | ||
} | ||
const issueNumber = parseInt(match[1], 10); | ||
const { owner, repo } = context.repo; | ||
try { | ||
const issue = await github.rest.issues.get({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber | ||
}); | ||
const minLength = 30; // Minimum description length | ||
if (!issue.data.body || issue.data.body.trim().length < minLength) { | ||
core.setFailed(`Linked issue #${issueNumber} does not have a sufficient description (at least ${minLength} characters required).`); | ||
} else { | ||
console.log(`Linked issue #${issueNumber} has a sufficient description.`); | ||
} | ||
} catch (error) { | ||
core.setFailed(`Issue #${issueNumber} not found or inaccessible.`); | ||
} |