Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11383] Add detection of PRs linking to closed issues #13154

Merged
merged 19 commits into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 46 additions & 28 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,49 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
const isTitleValid = /^\[#\d+\] /.test(pr.data.title)
const isDescriptionValid = /([Ff]ix(es|ed)?|[Cc]lose(s|d)?|[Rr]esolve(s|d)?|[Pp]art [Oo]f) #\d+/.test(pr.data.body)
if (isTitleValid && isDescriptionValid) {
return
}
let body = `Hi @${pr.data.user.login}, thank you for your interest in contributing to TEAMMATES!
However, your PR does not appear to follow our [contribution guidelines](https://teammates.github.io/teammates/process.html#step-4-submit-a-pr):\n\n`
if (!isTitleValid) {
body += "- Title must start with the issue number the PR is fixing in square brackets, e.g. `[#<issue-number>]`\n"
}
if (!isDescriptionValid) {
body += "- Description must reference the issue number the PR is fixing, e.g. `Fixes #<issue-number>` (or `Part of #<issue-number>` if the PR does not address the issue fully)\n"
}
body += "\nPlease address the above before we proceed to review your PR."
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
})
- uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
const isTitleValid = /^\[#\d+\] /.test(pr.data.title)
const isDescriptionValid = /([Ff]ix(es|ed)?|[Cc]lose(s|d)?|[Rr]esolve(s|d)?|[Pp]art [Oo]f) #\d+/.test(pr.data.body)
const descriptionRegex = /(?:[Ff]ix(?:es|ed)?|[Cc]lose(?:s|d)?|[Rr]esolve(?:s|d)?|[Pp]art [Oo]f) #(\d+)/
const extractIssueNumber = (description) => {
const match = description.match(descriptionRegex)
return match ? parseInt(match[1]) : null
};
const issueNumber = extractIssueNumber(pr.data.body)
let isIssueOpen = false
if (issueNumber) {
const issue = await github.rest.issues.get({
owner: 'TEAMMATES',
repo: 'teammates',
issue_number: issueNumber
})
isIssueOpen = issue.data.state === 'open'
if (isTitleValid && isDescriptionValid && isIssueOpen) {
return
}
}
let body = `Hi @${pr.data.user.login}, thank you for your interest in contributing to TEAMMATES!
However, your PR does not appear to follow our [contribution guidelines](https://teammates.github.io/teammates/process.html#step-4-submit-a-pr):\n\n`
if (!isTitleValid) {
body += "- Title must start with the issue number the PR is fixing in square brackets, e.g. `[#<issue-number>]`\n"
}
if (!isDescriptionValid) {
body += "- Description must reference the issue number the PR is fixing, e.g. `Fixes #<issue-number>` (or `Part of #<issue-number>` if the PR does not address the issue fully)\n"
}
if (!isIssueOpen && issueNumber) {
body += "- The issue referenced in the description (#" + issueNumber + ") is not open.\n"
}
body += "\nPlease address the above before we proceed to review your PR."
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
})
Loading