Skip to content

Commit

Permalink
Fix new comment tags to overwrite old comments
Browse files Browse the repository at this point in the history
For a better migration story ensure the old style comment tags are
captured to avoid stale comments on PRs.
  • Loading branch information
emcfarlane committed Jul 22, 2024
1 parent 3f33586 commit c542d7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit c542d7f

Please sign in to comment.