(
github: ReturnType<typeof getOctokit>,
{
owner,
repo,
issue_number,
marker,
body,
create = true,
}: {
owner: string;
repo: string;
issue_number: number;
marker: string;
body: string;
create?: boolean;
}
)
| 8 | * false). |
| 9 | */ |
| 10 | export async function createOrUpdateComment( |
| 11 | github: ReturnType<typeof getOctokit>, |
| 12 | { |
| 13 | owner, |
| 14 | repo, |
| 15 | issue_number, |
| 16 | marker, |
| 17 | body, |
| 18 | create = true, |
| 19 | }: { |
| 20 | owner: string; |
| 21 | repo: string; |
| 22 | issue_number: number; |
| 23 | marker: string; |
| 24 | body: string; |
| 25 | create?: boolean; |
| 26 | } |
| 27 | ) { |
| 28 | let commentId; |
| 29 | for await (const { data: comments } of github.paginate.iterator( |
| 30 | github.rest.issues.listComments, |
| 31 | { owner, repo, issue_number } |
| 32 | )) { |
| 33 | const comment = comments.find( |
| 34 | c => c.user?.login === BOT_LOGIN && c.body?.includes(marker) |
| 35 | ); |
| 36 | if (comment) { |
| 37 | commentId = comment.id; |
| 38 | break; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if (commentId) { |
| 43 | await github.rest.issues.updateComment({ |
| 44 | owner, |
| 45 | repo, |
| 46 | comment_id: commentId, |
| 47 | body, |
| 48 | }); |
| 49 | } else if (create) { |
| 50 | await github.rest.issues.createComment({ |
| 51 | owner, |
| 52 | repo, |
| 53 | issue_number, |
| 54 | body, |
| 55 | }); |
| 56 | } |
| 57 | } |
no test coverage detected