Skip to content

Commit

Permalink
feat: auto update PR comment
Browse files Browse the repository at this point in the history
* remove pending review
  • Loading branch information
ktrz committed Feb 2, 2024
1 parent d647ff1 commit 0ee988e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,35 @@ async function leaveComment(commitId: string, body: string, token: string) {
const repoUrl = repoMetadata.html_url ?? '';
const pr = github.context.payload.pull_request;
const client = github.getOctokit(token);
const reviews = await client.rest.pulls.listReviews({
owner: repoMetadata.owner.login,
repo: repoMetadata.name,
// eslint-disable-next-line @typescript-eslint/naming-convention
pull_number: pr?.number ?? 0,
});

await Promise.all(
reviews.data
.filter((r) => r.state === 'PENDING')
.map((r) =>
client.rest.pulls.deletePendingReview({
owner: repoMetadata.owner.login,
repo: repoMetadata.name,
// eslint-disable-next-line @typescript-eslint/naming-convention
pull_number: pr?.number ?? 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
review_id: r.id,
}),
),
);

const res = await (pr?.number
? client.rest.pulls.createReview({
owner: repoMetadata.owner.login,
repo: repoMetadata.name,
// eslint-disable-next-line @typescript-eslint/naming-convention
pull_number: pr.number,
event: 'COMMENT',
body,
})
: client.rest.repos.createCommitComment({
Expand Down

0 comments on commit 0ee988e

Please sign in to comment.