From c542d7fa4ed306d82f8f3e7893e1f22ff8fa7ab0 Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Mon, 22 Jul 2024 17:00:25 +0200 Subject: [PATCH] Fix new comment tags to overwrite old comments For a better migration story ensure the old style comment tags are captured to avoid stale comments on PRs. --- dist/index.js | 8 +++++++- src/comment.ts | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7c8fc43..e20110d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 = ""; // 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() { @@ -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; diff --git a/src/comment.ts b/src/comment.ts index 1643536..73c93e0 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -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 = ""; + // 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 { @@ -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}`);