Skip to content

Commit

Permalink
feat: don't update the comment if it's the same
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Dec 11, 2023
1 parent 5d3244d commit 47bd55f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
42 changes: 27 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/pull-request.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions dist/pull-request.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/pull-request.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class PullRequest {

async publishComment(content: string, octokit: CustomOctokit) {
if (this.metadata.commentID) {
// Check if the comment is already up to date
const currentComment = await this.getComment(octokit);
if (JSON.stringify(currentComment) === JSON.stringify(content)) return;
// Update the comment
this.updateComment(content, octokit);
return;
}
Expand All @@ -32,6 +36,23 @@ export class PullRequest {
await this.metadata.setMetadata();
}

async getComment(octokit: CustomOctokit): Promise<string> {
if (!this.metadata.commentID) return '';

const comment =
(
await octokit.request(
'GET /repos/{owner}/{repo}/issues/comments/{comment_id}',
{
...context.repo,
comment_id: +this.metadata.commentID,
}
)
).data.body ?? '';

return comment;
}

private async createComment(
body: string,
octokit: CustomOctokit
Expand Down

0 comments on commit 47bd55f

Please sign in to comment.