Skip to content

Commit

Permalink
update the try-it comment when it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
chunyu3 committed Dec 24, 2024
1 parent 70f8ea5 commit a468b37
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion eng/tsp-core/scripts/create-tryit-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<string> {
const response = await fetch(url, {
method,
Expand Down

0 comments on commit a468b37

Please sign in to comment.