Skip to content

Commit

Permalink
Merge branch 'master' into ENH/12508/reset-rubrics-question
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyuanc authored Jul 30, 2024
2 parents a895576 + ea30a05 commit 396d312
Showing 1 changed file with 46 additions and 28 deletions.
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,
})

0 comments on commit 396d312

Please sign in to comment.