From 64cc9c3341304bca7072a821f3ec6d83d67cb569 Mon Sep 17 00:00:00 2001 From: Joshua Pinkney Date: Wed, 28 Aug 2024 08:25:28 -0400 Subject: [PATCH 1/2] fix --- .github/workflows/lintcommit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lintcommit.js b/.github/workflows/lintcommit.js index 48db41a52f1..10f446afd40 100644 --- a/.github/workflows/lintcommit.js +++ b/.github/workflows/lintcommit.js @@ -88,7 +88,7 @@ function validateTitle(title) { } else if (subject.length === 0) { return 'empty subject' } else if (subject.length > 100) { - return 'invalid subject2 (must be <=100 chars)' + return 'invalid subject (must be <=100 chars)' } return undefined From e92fcd09fd40b3cc2b707f8e47619bc20e3ad074 Mon Sep 17 00:00:00 2001 From: Joshua Pinkney Date: Wed, 28 Aug 2024 08:28:21 -0400 Subject: [PATCH 2/2] Revert "Revert "ci(workflows): log on changelog/tests needed (#5506)"" This reverts commit 8a4991287bf7da1cfda151273728d53d9743ce65. --- .github/workflows/notify.js | 15 +++++++++++---- .github/workflows/utils.js | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/notify.js b/.github/workflows/notify.js index 05329ddb90d..b720555de0e 100644 --- a/.github/workflows/notify.js +++ b/.github/workflows/notify.js @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -const { parsePRTitle, hasPath } = require('./utils') +const { parsePRTitle, hasPath, dedupComment } = require('./utils') const testFilesMessage = 'This pull request modifies files in src/ but no tests were added/updated. Confirm whether tests should be added or ensure the PR description explains why tests are not required.' @@ -21,6 +21,7 @@ module.exports = async ({ github, context }) => { const owner = context.repo.owner const repo = context.repo.repo const author = context.payload.pull_request.head.repo.owner.login + const pullRequestId = context.payload.pull_request.number const response = await github.rest.repos.compareCommitsWithBasehead({ owner, @@ -37,13 +38,19 @@ module.exports = async ({ github, context }) => { return } + // Check for prior comments on the PR + const comments = await github.rest.issues.listComments({ + owner, + repo, + issue_number: pullRequestId, + }) + if (shouldAddTestFileMessage) { - // We can't really block on this one, since its valid to make a change in src/ without adding tests :( console.error(testFilesMessage) + await dedupComment({ github, comments, owner, repo, pullRequestId, message: testFilesMessage }) } if (shouldAddChangelogMessage) { - console.error(changelogMessage) - process.exit(1) + await dedupComment({ github, comments, owner, repo, pullRequestId, message: changelogMessage }) } } diff --git a/.github/workflows/utils.js b/.github/workflows/utils.js index 3bced5b9224..80b0b41a5f1 100644 --- a/.github/workflows/utils.js +++ b/.github/workflows/utils.js @@ -25,6 +25,22 @@ function parsePRTitle(title) { } } +/** + * Create a comment on a PR if one does not already exist + */ +async function dedupComment({ github, pullRequestId, owner, repo, comments, message }) { + if (comments.data.some((comment) => comment.body.includes(message))) { + return + } + + await github.rest.issues.createComment({ + issue_number: pullRequestId, + owner, + repo, + body: message, + }) +} + /* * Check if path is included in at least one of the filename paths */ @@ -34,5 +50,6 @@ function hasPath(filenames, path) { module.exports = { parsePRTitle, + dedupComment, hasPath, }