diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:51:45 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:51:45 +0300 |
| commit | d3261e64152397db2dca4d691a990c6bc2a6f4dd (patch) | |
| tree | fac2f7be638651181a72453d714f0f96675c2b8b /archived/projt-launcher/ci/github-script/reviews.js | |
| parent | 31b9a8949ed0a288143e23bf739f2eb64fdc63be (diff) | |
| download | Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.tar.gz Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.zip | |
NOISSUE add archived projects
Signed-off-by: Mehmet Samet Duman <yongdohyun@projecttick.org>
Diffstat (limited to 'archived/projt-launcher/ci/github-script/reviews.js')
| -rw-r--r-- | archived/projt-launcher/ci/github-script/reviews.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/archived/projt-launcher/ci/github-script/reviews.js b/archived/projt-launcher/ci/github-script/reviews.js new file mode 100644 index 0000000000..749ebc7085 --- /dev/null +++ b/archived/projt-launcher/ci/github-script/reviews.js @@ -0,0 +1,93 @@ +/** + * ProjT Launcher - Review Management + * Handles GitHub PR review operations + */ + +/** + * Dismiss all bot-created reviews on a PR + */ +async function dismissReviews({ github, context, dry }) { + const pull_number = context.payload.pull_request.number + + if (dry) { + return + } + + await Promise.all( + ( + await github.paginate(github.rest.pulls.listReviews, { + ...context.repo, + pull_number, + }) + ) + .filter((review) => review.user?.login === 'github-actions[bot]') + .map(async (review) => { + if (review.state === 'CHANGES_REQUESTED') { + await github.rest.pulls.dismissReview({ + ...context.repo, + pull_number, + review_id: review.id, + message: 'All good now, thank you!', + }) + } + await github.graphql( + `mutation($node_id:ID!) { + minimizeComment(input: { + classifier: RESOLVED, + subjectId: $node_id + }) + { clientMutationId } + }`, + { node_id: review.node_id }, + ) + }), + ) +} + +async function postReview({ github, context, core, dry, body }) { + const pull_number = context.payload.pull_request.number + + const pendingReview = ( + await github.paginate(github.rest.pulls.listReviews, { + ...context.repo, + pull_number, + }) + ).find( + (review) => + review.user?.login === 'github-actions[bot]' && + // If a review is still pending, we can just update this instead + // of posting a new one. + (review.state === 'CHANGES_REQUESTED' || + // No need to post a new review, if an older one with the exact + // same content had already been dismissed. + review.body === body), + ) + + if (dry) { + if (pendingReview) + core.info(`pending review found: ${pendingReview.html_url}`) + else core.info('no pending review found') + core.info(body) + } else { + if (pendingReview) { + await github.rest.pulls.updateReview({ + ...context.repo, + pull_number, + review_id: pendingReview.id, + body, + }) + } else { + await github.rest.pulls.createReview({ + ...context.repo, + pull_number, + event: 'REQUEST_CHANGES', + body, + }) + } + } +} + +module.exports = { + dismissReviews, + postReview, +} |
