[#13144] Implement 'Copy' button in course enroll page #576
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
name: Pull Request Checker | |
on: | |
pull_request_target: | |
types: | |
- opened | |
- reopened | |
branches: | |
- master | |
jobs: | |
check-pr: | |
runs-on: ubuntu-latest | |
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) | |
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, | |
}) |