Skip to content

Commit

Permalink
Always post GitHub issue comments in order
Browse files Browse the repository at this point in the history
We always want JavaScript and Stylesheets first
  • Loading branch information
colinrotherham committed Dec 1, 2023
1 parent e391a29 commit 09a0431
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions .github/workflows/scripts/comments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@ import { outdent } from 'outdent'
* @param {DiffComment[]} diffs
*/
export async function commentDiffs(githubActionContext, issueNumber, diffs) {
// Run the comments in parallel to avoid that an early one failing prevents the others
// and use `allSettled` to avoid the promise rejecting on the first failure but wait
// for everything to complete
const results = await Promise.allSettled(
diffs.map((diff) => commentDiff(githubActionContext, issueNumber, diff))
)
const errors = []

// Run comments in order, but prevent errors stopping other comments
for (const diff of diffs) {
try {
await commentDiff(githubActionContext, issueNumber, diff)
} catch (error) {
const filename = basename(diff.path)

// Defer errors until all comments are attempted
errors.push(
new Error(`Failed to post GitHub comment for ${filename}`, {
cause: error
})
)
}
}

if (results.some((result) => result.status === 'rejected')) {
throw new Error('Posting diff comment failed', {
cause: results
// Throw on any deferred errors above
if (errors.length) {
throw new Error('Failed to post GitHub comments', {
cause: errors
})
}
}
Expand Down

0 comments on commit 09a0431

Please sign in to comment.