Skip to content

Commit e92fcd0

Browse files
committed
Revert "Revert "ci(workflows): log on changelog/tests needed (#5506)""
This reverts commit 8a49912.
1 parent 64cc9c3 commit e92fcd0

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.github/workflows/notify.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
const { parsePRTitle, hasPath } = require('./utils')
6+
const { parsePRTitle, hasPath, dedupComment } = require('./utils')
77

88
const testFilesMessage =
99
'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 }) => {
2121
const owner = context.repo.owner
2222
const repo = context.repo.repo
2323
const author = context.payload.pull_request.head.repo.owner.login
24+
const pullRequestId = context.payload.pull_request.number
2425

2526
const response = await github.rest.repos.compareCommitsWithBasehead({
2627
owner,
@@ -37,13 +38,19 @@ module.exports = async ({ github, context }) => {
3738
return
3839
}
3940

41+
// Check for prior comments on the PR
42+
const comments = await github.rest.issues.listComments({
43+
owner,
44+
repo,
45+
issue_number: pullRequestId,
46+
})
47+
4048
if (shouldAddTestFileMessage) {
41-
// We can't really block on this one, since its valid to make a change in src/ without adding tests :( console.error(testFilesMessage)
49+
await dedupComment({ github, comments, owner, repo, pullRequestId, message: testFilesMessage })
4250
}
4351

4452
if (shouldAddChangelogMessage) {
45-
console.error(changelogMessage)
46-
process.exit(1)
53+
await dedupComment({ github, comments, owner, repo, pullRequestId, message: changelogMessage })
4754
}
4855
}
4956

.github/workflows/utils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ function parsePRTitle(title) {
2525
}
2626
}
2727

28+
/**
29+
* Create a comment on a PR if one does not already exist
30+
*/
31+
async function dedupComment({ github, pullRequestId, owner, repo, comments, message }) {
32+
if (comments.data.some((comment) => comment.body.includes(message))) {
33+
return
34+
}
35+
36+
await github.rest.issues.createComment({
37+
issue_number: pullRequestId,
38+
owner,
39+
repo,
40+
body: message,
41+
})
42+
}
43+
2844
/*
2945
* Check if path is included in at least one of the filename paths
3046
*/
@@ -34,5 +50,6 @@ function hasPath(filenames, path) {
3450

3551
module.exports = {
3652
parsePRTitle,
53+
dedupComment,
3754
hasPath,
3855
}

0 commit comments

Comments
 (0)