Skip to content

Commit

Permalink
Merge pull request #268 from aws/jpinkney-aws/fix2
Browse files Browse the repository at this point in the history
fix(ci): test
  • Loading branch information
jpinkney-aws authored Aug 28, 2024
2 parents 1b7041d + e92fcd0 commit f658601
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lintcommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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,
Expand All @@ -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 })
}
}

Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -34,5 +50,6 @@ function hasPath(filenames, path) {

module.exports = {
parsePRTitle,
dedupComment,
hasPath,
}

0 comments on commit f658601

Please sign in to comment.