( options: GitHubCommentOptions, )
| 81 | }; |
| 82 | |
| 83 | export async function createOrUpdateGitHubComment( |
| 84 | options: GitHubCommentOptions, |
| 85 | ): Promise<void> { |
| 86 | const token = getGitHubToken(); |
| 87 | const owner = getGitHubOwner(); |
| 88 | const repo = getGitHubRepo(); |
| 89 | const prNumber = getGitHubPRNumber(); |
| 90 | |
| 91 | const octokit = new Octokit({ auth: token }); |
| 92 | |
| 93 | const commentsResponse = await octokit.rest.issues.listComments({ |
| 94 | owner, |
| 95 | repo, |
| 96 | issue_number: prNumber, |
| 97 | per_page: 100, |
| 98 | }); |
| 99 | |
| 100 | const comments = commentsResponse.data; |
| 101 | |
| 102 | const existing = comments.find((c) => { |
| 103 | if (!c.body) { |
| 104 | return false; |
| 105 | } |
| 106 | return c.body.startsWith(options.commentMarker); |
| 107 | }); |
| 108 | |
| 109 | if (existing) { |
| 110 | console.log(`Updating existing comment (id: ${existing.id}).`); |
| 111 | await octokit.rest.issues.updateComment({ |
| 112 | owner, |
| 113 | repo, |
| 114 | comment_id: existing.id, |
| 115 | body: options.body, |
| 116 | }); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | console.log("Creating new comment."); |
| 121 | await octokit.rest.issues.createComment({ |
| 122 | owner, |
| 123 | repo, |
| 124 | issue_number: prNumber, |
| 125 | body: options.body, |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | export async function formatMarkdown(markdown: string): Promise<string> { |
| 130 | const repoRoot = getRepoRoot(); |
no test coverage detected