@microsoft.azure/autorest.testserver
Version:
Autorest test server.
57 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitHubCiClient = void 0;
class GitHubCiClient {
constructor(githubRepo, githubTokenOfCI) {
this.githubRepo = githubRepo;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.headersInit = {
"User-Agent": "AutoRest CI",
};
this.headersInit["Authorization"] = "token " + githubTokenOfCI;
}
async getComments(pr) {
const res = await fetch(`https://api.github.com/repos/${this.githubRepo}/issues/${pr}/comments`, {
headers: this.headersInit,
});
const comments = JSON.parse(await res.text());
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return comments.map((x) => {
return { id: x.id, message: x.body, user: x.user.login, url: x.html_url };
});
}
async getCommentsWithIndicator(pr, indicator) {
return (await this.getComments(pr)).filter((comment) => comment.message.startsWith(indicator));
}
async setComment(id, message) {
await fetch(`https://api.github.com/repos/${this.githubRepo}/issues/comments/${id}`, {
body: JSON.stringify({ body: message }),
headers: this.headersInit,
method: "POST",
});
}
async deleteComment(id) {
await fetch(`https://api.github.com/repos/${this.githubRepo}/issues/comments/${id}`, {
headers: this.headersInit,
method: "DELETE",
});
}
async tryDeleteComment(id) {
try {
await this.deleteComment(id);
}
catch (_) {
//.
}
}
async createComment(pr, message) {
const res = await fetch(`https://api.github.com/repos/${this.githubRepo}/issues/${pr}/comments`, {
body: JSON.stringify({ body: message }),
headers: this.headersInit,
method: "POST",
});
return JSON.parse(await res.text()).id;
}
}
exports.GitHubCiClient = GitHubCiClient;
//# sourceMappingURL=github.js.map