Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eesh Tyagi authored and Eesh Tyagi committed Sep 16, 2023
1 parent 5781346 commit 364486c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dist/main.js

Large diffs are not rendered by default.

72 changes: 38 additions & 34 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const listComments = async ({ client, context, prNumber, hiddenHeader }) => {
};

const insertComment = ({ client, context, prNumber, body }, hiddenHeader) =>
client.issues.createComment({
client.issues?.createComment({
...context.repo,
issue_number: prNumber,
body: appendHiddenHeaderToComment(body, hiddenHeader),
});

const updateComment = ({ client, context, body, commentId }, hiddenHeader) =>
client.issues.updateComment({
client.issues?.updateComment({
...context.repo,
comment_id: commentId,
body: appendHiddenHeaderToComment(body, hiddenHeader),
Expand All @@ -44,7 +44,7 @@ const updateComment = ({ client, context, body, commentId }, hiddenHeader) =>
const deleteComments = ({ client, context, comments }) =>
Promise.all(
comments.map(({ id }) =>
client.issues.deleteComment({
client.issues?.deleteComment({
...context.repo,
comment_id: id,
}),
Expand All @@ -58,37 +58,41 @@ export const upsertComment = async ({
body,
hiddenHeader,
}) => {
const existingComments = await listComments({
client,
context,
prNumber,
hiddenHeader,
});
const last = existingComments.pop();
if (client.issues) {
const existingComments = await listComments({
client,
context,
prNumber,
hiddenHeader,
});
const last = existingComments.pop();

await deleteComments({
client,
context,
comments: existingComments,
});
await deleteComments({
client,
context,
comments: existingComments,
});

return last
? updateComment(
{
client,
context,
body,
commentId: last.id,
},
hiddenHeader,
)
: insertComment(
{
client,
context,
prNumber,
body,
},
hiddenHeader,
);
}

return last
? updateComment(
{
client,
context,
body,
commentId: last.id,
},
hiddenHeader,
)
: insertComment(
{
client,
context,
prNumber,
body,
},
hiddenHeader,
);
return "";
};

0 comments on commit 364486c

Please sign in to comment.