From 85d5c32192015f4a77ce067b18cbc173cbe1dead Mon Sep 17 00:00:00 2001 From: Chris Trzesniewski Date: Tue, 2 Apr 2024 09:54:06 +0200 Subject: [PATCH] release v1.20.0 --- .gitignore | 1 + dist/src/write.js | 28 ++++++++++------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 0b4a26758..3aa65ca44 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /.nyc_output /coverage .idea +.env diff --git a/dist/src/write.js b/dist/src/write.js index fab283145..ffcac6387 100644 --- a/dist/src/write.js +++ b/dist/src/write.js @@ -27,6 +27,8 @@ const core = __importStar(require("@actions/core")); const github = __importStar(require("@actions/github")); const git = __importStar(require("./git")); const default_index_html_1 = require("./default_index_html"); +const leavePRComment_1 = require("./comment/leavePRComment"); +const leaveCommitComment_1 = require("./comment/leaveCommitComment"); exports.SCRIPT_PREFIX = 'window.BENCHMARK_DATA = '; const DEFAULT_DATA_JSON = { lastUpdate: 0, @@ -203,22 +205,13 @@ function buildAlertComment(alerts, benchName, curSuite, prevSuite, threshold, cc } return lines.join('\n'); } -async function leaveComment(commitId, body, token) { - var _a; +async function leaveComment(commitId, body, commentId, token) { core.debug('Sending comment:\n' + body); const repoMetadata = getCurrentRepoMetadata(); - const repoUrl = (_a = repoMetadata.html_url) !== null && _a !== void 0 ? _a : ''; - const client = github.getOctokit(token); - const res = await client.rest.repos.createCommitComment({ - owner: repoMetadata.owner.login, - repo: repoMetadata.name, - // eslint-disable-next-line @typescript-eslint/naming-convention - commit_sha: commitId, - body, - }); - const commitUrl = `${repoUrl}/commit/${commitId}`; - console.log(`Comment was sent to ${commitUrl}. Response:`, res.status, res.data); - return res; + const pr = github.context.payload.pull_request; + return await ((pr === null || pr === void 0 ? void 0 : pr.number) + ? (0, leavePRComment_1.leavePRComment)(repoMetadata.owner.login, repoMetadata.name, pr.number, body, commentId, token) + : (0, leaveCommitComment_1.leaveCommitComment)(repoMetadata.owner.login, repoMetadata.name, commitId, body, commentId, token)); } async function handleComment(benchName, curSuite, prevSuite, config) { const { commentAlways, githubToken } = config; @@ -231,7 +224,7 @@ async function handleComment(benchName, curSuite, prevSuite, config) { } core.debug('Commenting about benchmark comparison'); const body = buildComment(benchName, curSuite, prevSuite); - await leaveComment(curSuite.commit.id, body, githubToken); + await leaveComment(curSuite.commit.id, body, `${benchName} Summary`, githubToken); } async function handleAlert(benchName, curSuite, prevSuite, config) { const { alertThreshold, githubToken, commentOnAlert, failOnAlert, alertCommentCcUsers, failThreshold } = config; @@ -247,13 +240,12 @@ async function handleAlert(benchName, curSuite, prevSuite, config) { core.debug(`Found ${alerts.length} alerts`); const body = buildAlertComment(alerts, benchName, curSuite, prevSuite, alertThreshold, alertCommentCcUsers); let message = body; - let url = null; if (commentOnAlert) { if (!githubToken) { throw new Error("'comment-on-alert' input is set but 'github-token' input is not set"); } - const res = await leaveComment(curSuite.commit.id, body, githubToken); - url = res.data.html_url; + const res = await leaveComment(curSuite.commit.id, body, `${benchName} Alert`, githubToken); + const url = res.data.html_url; message = body + `\nComment was generated at ${url}`; } if (failOnAlert) {