@dapplion/benchmark
Version:
Ensures that new code does not introduce performance regressions with CI. Tracks:
50 lines (49 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.commetToPrUpdatable = commetToPrUpdatable;
exports.commentToCommit = commentToCommit;
exports.getGithubDefaultBranch = getGithubDefaultBranch;
const context_js_1 = require("./context.js");
const commentTag = "benchmarkbot/action";
async function commetToPrUpdatable(prNumber, body) {
const { repo, octokit } = (0, context_js_1.getContext)();
// Append tag so the comment is findable latter
const bodyWithTag = `${body}\n\n\n> by ${commentTag}`;
const comments = await octokit.rest.issues.listComments({
...repo,
issue_number: prNumber,
});
const prevComment = comments.data.find((c) => c.body && c.body.includes(commentTag));
if (prevComment) {
// Update
await octokit.rest.issues.updateComment({
...repo,
issue_number: prNumber,
comment_id: prevComment.id,
body: bodyWithTag,
});
}
else {
// Create
await octokit.rest.issues.createComment({
...repo,
issue_number: prNumber,
body: bodyWithTag,
});
}
}
async function commentToCommit(commitSha, body) {
const { repo, octokit } = (0, context_js_1.getContext)();
await octokit.rest.repos.createCommitComment({
...repo,
commit_sha: commitSha,
body,
});
}
async function getGithubDefaultBranch() {
const { repo, octokit } = (0, context_js_1.getContext)();
const thisRepo = await octokit.rest.repos.get({
...repo,
});
return thisRepo.data.default_branch;
}