generated from im-open/javascript-action-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARCH-2011 - Re-work the expected PR comment assertions & add expected…
… file for truncated scenarios
- Loading branch information
1 parent
c601688
commit c1fe375
Showing
11 changed files
with
487 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module.exports = async (github, core) => { | ||
async function lookForExistingComments(github, core, prNum) { | ||
const markupPrefix = `<!-- im-open/process-jest-test-results`; | ||
let commentsToDelete = []; | ||
|
||
await github | ||
.paginate(github.rest.issues.listComments, { | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
issue_number: prNum | ||
}) | ||
.then(comments => { | ||
if (comments.length === 0) { | ||
core.info('There are no comments on the PR. Nothing to delete.'); | ||
} else { | ||
const existingComments = comments.filter(c => c.body.includes(markupPrefix)); | ||
if (existingComments) { | ||
commentsToDelete = existingComments.map(c => c.id); | ||
core.info(`There are existing comments to delete: ${commentsToDelete.join(',')}`); | ||
} else { | ||
core.info('No comments were found that contain the prefix. Nothing to delete.'); | ||
} | ||
} | ||
}) | ||
.catch(error => { | ||
core.info( | ||
`Failed to list PR comments. Error code: ${error.message}. Nothing will be deleted but this may affect the test run.` | ||
); | ||
}); | ||
|
||
core.info(`Finished getting comments for PR #${prNum}.`); | ||
|
||
return commentsToDelete; | ||
} | ||
|
||
async function deleteComment(github, core, commentId) { | ||
await github | ||
.request(`DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}`, { | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
comment_id: commentId, | ||
headers: { | ||
'X-GitHub-Api-Version': '2022-11-28' | ||
} | ||
}) | ||
.then(() => { | ||
core.info(`The comment '${commentId}' was deleted successfully.`); | ||
}) | ||
.catch(error => { | ||
core.info(`An error occurred deleting comment '${commentId}'. Error: ${error.message}`); | ||
core.info(`You may need to manually clean up the PR comments.`); | ||
}); | ||
} | ||
|
||
const prNum = github.context.payload.pull_request.number; | ||
core.info(`\nDeleting all pre-existing process-jest-test-results comments from PR # ${prNum}...`); | ||
|
||
const commentsToDelete = await lookForExistingComments(github, core, prNum); | ||
if (commentsToDelete.length === 0) { | ||
return; | ||
} | ||
|
||
for (const commentId of commentsToDelete) { | ||
await deleteComment(github, core, commentId); | ||
} | ||
}; |
Oops, something went wrong.