MCPcopy Index your code
hub / github.com/lingodotdev/lingo.dev / createOrUpdateGitHubComment

Function createOrUpdateGitHubComment

scripts/docs/src/utils.ts:83–127  ·  view source on GitHub ↗
(
  options: GitHubCommentOptions,
)

Source from the content-addressed store, hash-verified

81};
82
83export 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
129export async function formatMarkdown(markdown: string): Promise<string> {
130 const repoRoot = getRepoRoot();

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 5

getGitHubTokenFunction · 0.85
getGitHubOwnerFunction · 0.85
getGitHubRepoFunction · 0.85
getGitHubPRNumberFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected