Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new comment tags to overwrite old comments #53

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45608,6 +45608,9 @@ async function downloadBuf(version) {
// limitations under the License.


// oldCommentTag is the previous tag used to identify the comment. This is
// temporary and will be removed in a future release.
const oldCommentTag = "<!-- Buf results -->";
// commentTag returns the tag used to identify the comment. This is a non-visible
// string injected into the comment body. It is unique to the workflow and job.
function commentTag() {
Expand All @@ -45628,7 +45631,10 @@ async function findCommentOnPR(context, github) {
repo: repo,
issue_number: prNumber,
});
const previousComment = comments.find((comment) => comment.body?.includes(commentTag()));
const tag = commentTag();
const previousComment = comments.find((comment) =>
// TODO: Remove the old comment tag check in a future release.
comment.body?.includes(tag) || comment.body?.includes(oldCommentTag));
if (previousComment) {
core.info(`Found previous comment ${previousComment.id}`);
return previousComment.id;
Expand Down
11 changes: 9 additions & 2 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { context } from "@actions/github";
import { Context } from "@actions/github/lib/context";
import { GitHub } from "@actions/github/lib/utils";

// oldCommentTag is the previous tag used to identify the comment. This is
// temporary and will be removed in a future release.
const oldCommentTag = "<!-- Buf results -->";

// commentTag returns the tag used to identify the comment. This is a non-visible
// string injected into the comment body. It is unique to the workflow and job.
function commentTag(): string {
Expand All @@ -41,8 +45,11 @@ export async function findCommentOnPR(
repo: repo,
issue_number: prNumber,
});
const previousComment = comments.find((comment) =>
comment.body?.includes(commentTag()),
const tag = commentTag();
const previousComment = comments.find(
(comment) =>
// TODO: Remove the old comment tag check in a future release.
comment.body?.includes(tag) || comment.body?.includes(oldCommentTag),
);
if (previousComment) {
core.info(`Found previous comment ${previousComment.id}`);
Expand Down
Loading