From a468b370593bad6ee1dddd5bfb3443fd96cadd9d Mon Sep 17 00:00:00 2001 From: "FAREAST\\chunyu" Date: Tue, 24 Dec 2024 20:26:20 +0800 Subject: [PATCH] update the try-it comment when it exists --- eng/tsp-core/scripts/create-tryit-comment.ts | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/eng/tsp-core/scripts/create-tryit-comment.ts b/eng/tsp-core/scripts/create-tryit-comment.ts index 62ce170e05..55931a50eb 100644 --- a/eng/tsp-core/scripts/create-tryit-comment.ts +++ b/eng/tsp-core/scripts/create-tryit-comment.ts @@ -30,11 +30,12 @@ async function main() { const tryItComments = data.filter((x) => x.body.includes(TRY_ID_COMMENT_IDENTIFIER)); console.log(`Found ${azoComments.length} Cadl Try It comment(s)`); + const comment = makeComment(folderName, prNumber, vscodeDownloadUrl); if (tryItComments.length > 0) { + await updateComment(repo, tryItComments[0].id, comment, ghAuth); return; } - const comment = makeComment(folderName, prNumber, vscodeDownloadUrl); await writeComment(repo, prNumber, comment, ghAuth); } @@ -85,6 +86,24 @@ async function writeComment(repo: string, prNumber: string, comment: string, ghA console.log("Comment created", response); } +async function updateComment(repo: string, commentId: string, comment: string, ghAuth: string) { + const url = `https://api.github.com/repos/${repo}/issues/comments/${commentId}`; + const body = { + body: comment, + }; + const headers = { + "Content-Type": "application/json", + }; + + const response = await request("PATCH", url, { + headers, + body: JSON.stringify(body), + ghAuth, + }); + + console.log("Comment updated", response); +} + async function request(method: string, url: string, data: any): Promise { const response = await fetch(url, { method,