From bb3062e5dbe2126c69864b89c4108da1e93d1fb5 Mon Sep 17 00:00:00 2001 From: Kenneth Seet <120318851+itstrueitstrueitsrealitsreal@users.noreply.github.com> Date: Sat, 27 Jul 2024 18:09:13 +0800 Subject: [PATCH] Update pr.yml --- .github/workflows/pr.yml | 60 +++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7885aa57cd8..c36ab86f87e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -13,31 +13,35 @@ 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. `[#]`\n" - } - if (!isDescriptionValid) { - body += "- Description must reference the issue number the PR is fixing, e.g. `Fixes #` (or `Part of #` 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 isIssueOpen = pr.data.state === 'open'; + 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 && 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. `[#]`\n" + } + if (!isDescriptionValid) { + body += "- Description must reference the issue number the PR is fixing, e.g. `Fixes #` (or `Part of #` if the PR does not address the issue fully)\n" + } + if (!isIssueOpen) { + body += "- The issue this PR is addressing is closed\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, + })