From 05f0e5e7a1885de5341f7b0f55e5b9c9972da4a7 Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 16:01:39 +0800 Subject: [PATCH 01/10] Add check for closed issue --- .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..9c5cd2b6526 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 = issue.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, + }) From fca9e1ffdf5b7867b68b89e51e4d5927865e92aa Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 16:14:50 +0800 Subject: [PATCH 02/10] Update message --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9c5cd2b6526..1165bde725b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -36,7 +36,7 @@ jobs: 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 += "- Issue # is closed\n" } body += "\nPlease address the above before we proceed to review your PR." await github.rest.issues.createComment({ From f0c91b7206ff0c98aca293d6e222d92a3ac7f9e9 Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 16:30:46 +0800 Subject: [PATCH 03/10] Rephrase message --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1165bde725b..9c5cd2b6526 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -36,7 +36,7 @@ jobs: 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 += "- Issue # is closed\n" + 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({ From 699a00a9d975fd9868c8f7a0107463b09e696ea5 Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 16:31:07 +0800 Subject: [PATCH 04/10] Add logging --- .github/workflows/pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9c5cd2b6526..dcf031f49f7 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,6 +21,7 @@ jobs: repo: context.repo.repo, pull_number: context.issue.number }) + console.log(`Issue #${issueNumber} status: ${issue.data.state}`); const isIssueOpen = issue.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) From d011c16fb5a833ed7e5955190c2c1568b95ac264 Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 16:32:17 +0800 Subject: [PATCH 05/10] Test --- .github/workflows/pr.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index dcf031f49f7..9c5cd2b6526 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,7 +21,6 @@ jobs: repo: context.repo.repo, pull_number: context.issue.number }) - console.log(`Issue #${issueNumber} status: ${issue.data.state}`); const isIssueOpen = issue.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) From 73d13935a839eb775649ec6a93e4a38b0da19ac6 Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 18:23:47 +0800 Subject: [PATCH 06/10] Update pr.yml --- .github/workflows/pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9c5cd2b6526..75f339878d8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,7 +21,7 @@ jobs: repo: context.repo.repo, pull_number: context.issue.number }) - const isIssueOpen = issue.data.state === 'open'; + const isIssueOpen = pr.data.state.description === '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) { @@ -36,7 +36,7 @@ jobs: 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 += "- The issue this PR is addressing is not open.\n" } body += "\nPlease address the above before we proceed to review your PR." await github.rest.issues.createComment({ From 26ee2b5c8405ebea339bd81e2e069ad9aa4a372c Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sat, 27 Jul 2024 16:01:39 +0800 Subject: [PATCH 07/10] Add check for closed issue Update message Rephrase message Add logging Test 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..75f339878d8 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.description === '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 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, + }) From 686027ba81e74f2b3ee4a3a11a71fa39f6bd60b5 Mon Sep 17 00:00:00 2001 From: Rayson Yeap <88478542+Respirayson@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:52:14 +0800 Subject: [PATCH 08/10] [#13147] Didn't Account for the Timezone in Session Edit Form component tests (#13148) Update pr.yml Update pr.yml Update pr.yml --- .github/workflows/pr.yml | 64 +++++++++---------- .../session-edit-form.component.spec.ts | 6 +- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 75f339878d8..fefaf83e31c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,6 +1,6 @@ name: Pull Request Checker on: - pull_request_target: + pull_request: types: - opened - reopened @@ -10,38 +10,32 @@ on: 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 isIssueOpen = pr.data.state.description === '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 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, - }) + - uses: actions/github-script@v6 + 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, + }) diff --git a/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts b/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts index 4be00441ab6..ab567d31db0 100644 --- a/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts +++ b/src/web/app/components/session-edit-form/session-edit-form.component.spec.ts @@ -123,8 +123,10 @@ describe('SessionEditFormComponent', () => { it('should not adjust the session visibility date and time if submission opening date and time are later', () => { const date: DateFormat = component.minDateForSubmissionStart; const time: TimeFormat = component.minTimeForSubmissionStart; - component.model.customSessionVisibleDate = dateTimeService.getDateInstance(moment().subtract(1, 'days')); - component.model.customSessionVisibleTime = dateTimeService.getTimeInstance(moment().subtract(1, 'hours')); + component.model.customSessionVisibleDate = dateTimeService + .getDateInstance(moment().tz(component.model.timeZone).subtract(1, 'days')); + component.model.customSessionVisibleTime = dateTimeService + .getTimeInstance(moment().tz(component.model.timeZone).subtract(1, 'hours')); component.configureSessionVisibleDateTime(date, time); expect(component.model.customSessionVisibleDate).not.toEqual(date); expect(component.model.customSessionVisibleTime).not.toEqual(time); From cbb6e6fe721ea76f1fae0ab3a8bbadae6851d951 Mon Sep 17 00:00:00 2001 From: Kenneth Seet <120318851+itstrueitstrueitsrealitsreal@users.noreply.github.com> Date: Sat, 27 Jul 2024 18:36:10 +0800 Subject: [PATCH 09/10] Update pr.yml --- .github/workflows/pr.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fefaf83e31c..7885aa57cd8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,6 +1,6 @@ name: Pull Request Checker on: - pull_request: + pull_request_target: types: - opened - reopened @@ -10,8 +10,10 @@ on: jobs: check-pr: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - - uses: actions/github-script@v6 + - uses: actions/github-script@v7 with: script: | const pr = await github.rest.pulls.get({ From 01292f21a4baa5aa249eaadfd70b78f99d0aa477 Mon Sep 17 00:00:00 2001 From: Kenneth Seet Date: Sun, 28 Jul 2024 13:57:45 +0800 Subject: [PATCH 10/10] Update workflow --- .github/workflows/pr.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7a0e3490891..ef03f564de3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,11 +21,25 @@ jobs: repo: context.repo.repo, pull_number: context.issue.number }) - const isIssueOpen = pr.data.state.description === '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 + 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` @@ -35,8 +49,8 @@ jobs: 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 not open.\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({