Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the try-it comment when it exists #5435

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading