Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Jul 5, 2024
1 parent d244f1c commit fbc09c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 101 deletions.
58 changes: 8 additions & 50 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<!-- Buf results -->";
// 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<typeof GitHub>,
summary: string,
): Promise<boolean> {
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;
Expand All @@ -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;
Expand Down
59 changes: 8 additions & 51 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,10 @@ import { GitHub } from "@actions/github/lib/utils";
// string injected into the comment body.
const commentTag = "<!-- Buf results -->";

// 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<typeof GitHub>,
summary: string,
): Promise<boolean> {
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<typeof GitHub>,
Expand All @@ -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<typeof GitHub>,
Expand Down

0 comments on commit fbc09c1

Please sign in to comment.