diff --git a/dist/index.js b/dist/index.js index 776aa2c..a3e8a2c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -45608,56 +45608,10 @@ async function downloadBuf(version) { // commentTag is the tag used to identify the comment. This is a non-visible // string injected into the comment body. const commentTag = ""; -// commentOnPR comments on the PR with the summary of the Buf results. The -// summary should be a markdown formatted string. This function returns true if -// the comment was successfully created or updated. On failure, it returns -// false but does not throw an error. -/*export async function commentOnPR( - context: Context, - github: InstanceType, - summary: string, -): Promise { - const comment = `The latest Buf updates on your PR.\n\n${summary}`; - try { - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request?.number; - if (!prNumber) { - core.info("This is not a PR, skipping commenting"); - return false; - } - const content = { - owner: owner, - repo: repo, - body: comment + commentTag, - }; - // Check if a comment already exists and update it. - const comments = await github.paginate(github.rest.issues.listComments, { - owner: owner, - repo: repo, - issue_number: prNumber, - }); - const previousComment = comments.find((comment) => - comment.body?.includes(commentTag), - ); - if (previousComment) { - await github.rest.issues.updateComment({ - ...content, - comment_id: previousComment.id, - }); - core.info(`Updated comment ${previousComment.id} on PR #${prNumber}`); - } else { - await github.rest.issues.createComment({ - ...content, - issue_number: prNumber, - }); - core.info(`Commented on PR #${prNumber}`); - } - return true; - } catch (error) { - core.info(`Error occurred while commenting on PR: ${error}`); - return false; - } -}*/ +// findCommentOnPR finds the comment on the PR that contains the Buf results. +// If the comment is found, it returns the comment ID. If the comment is not +// found, it returns undefined. On failure, it returns undefined but does not +// throw an error. async function findCommentOnPR(context, github) { const { owner, repo } = context.repo; const prNumber = context.payload.pull_request?.number; @@ -45677,6 +45631,10 @@ async function findCommentOnPR(context, github) { } return undefined; } +// commentOnPR comments on the PR with the summary of the Buf results. The +// summary should be a markdown formatted string. This function returns true if +// the comment was successfully created or updated. On failure, it returns +// false but does not throw an error. async function commentOnPR(context, github, commentID, body) { const { owner, repo } = context.repo; const prNumber = context.payload.pull_request?.number; diff --git a/src/comment.ts b/src/comment.ts index 3756577..de663e0 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -20,57 +20,10 @@ import { GitHub } from "@actions/github/lib/utils"; // string injected into the comment body. const commentTag = ""; -// commentOnPR comments on the PR with the summary of the Buf results. The -// summary should be a markdown formatted string. This function returns true if -// the comment was successfully created or updated. On failure, it returns -// false but does not throw an error. -/*export async function commentOnPR( - context: Context, - github: InstanceType, - summary: string, -): Promise { - const comment = `The latest Buf updates on your PR.\n\n${summary}`; - try { - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request?.number; - if (!prNumber) { - core.info("This is not a PR, skipping commenting"); - return false; - } - const content = { - owner: owner, - repo: repo, - body: comment + commentTag, - }; - // Check if a comment already exists and update it. - const comments = await github.paginate(github.rest.issues.listComments, { - owner: owner, - repo: repo, - issue_number: prNumber, - }); - const previousComment = comments.find((comment) => - comment.body?.includes(commentTag), - ); - if (previousComment) { - await github.rest.issues.updateComment({ - ...content, - comment_id: previousComment.id, - }); - core.info(`Updated comment ${previousComment.id} on PR #${prNumber}`); - } else { - await github.rest.issues.createComment({ - ...content, - issue_number: prNumber, - }); - core.info(`Commented on PR #${prNumber}`); - } - return true; - } catch (error) { - core.info(`Error occurred while commenting on PR: ${error}`); - return false; - } -}*/ - +// findCommentOnPR finds the comment on the PR that contains the Buf results. +// If the comment is found, it returns the comment ID. If the comment is not +// found, it returns undefined. On failure, it returns undefined but does not +// throw an error. export async function findCommentOnPR( context: Context, github: InstanceType, @@ -96,6 +49,10 @@ export async function findCommentOnPR( return undefined; } +// commentOnPR comments on the PR with the summary of the Buf results. The +// summary should be a markdown formatted string. This function returns true if +// the comment was successfully created or updated. On failure, it returns +// false but does not throw an error. export async function commentOnPR( context: Context, github: InstanceType,