From 04e819ee5c39b1321e190003469bd20b7d82f574 Mon Sep 17 00:00:00 2001 From: Tobias Faust Date: Thu, 13 Aug 2020 13:52:18 +0200 Subject: [PATCH] Add support for push event --- dist/main.js | 41 ++++++++++++++++++++++++++++++----------- src/comment.js | 8 ++++++-- src/index.js | 33 ++++++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/dist/main.js b/dist/main.js index 8d4b39bc..0f7d9fa7 100644 --- a/dist/main.js +++ b/dist/main.js @@ -22883,7 +22883,9 @@ function uncovered(file, options) { function comment (lcov, options) { return fragment( - `Coverage after merging ${b(options.head)} into ${b(options.base)}`, + options.base + ? `Coverage after merging ${b(options.head)} into ${b(options.base)}` + : `Coverage for this commit`, table(tbody(tr(th(percentage(lcov).toFixed(2), "%")))), "\n\n", details(summary("Coverage Report"), tabulate(lcov, options)), @@ -22907,7 +22909,9 @@ function diff(lcov, before, options) { : "▴"; return fragment( - `Coverage after merging ${b(options.head)} into ${b(options.base)}`, + options.base + ? `Coverage after merging ${b(options.head)} into ${b(options.base)}` + : `Coverage for this commit`, table(tbody(tr( th(pafter.toFixed(2), "%"), th(arrow, " ", plus, pdiff.toFixed(2), "%"), @@ -22935,22 +22939,37 @@ async function main$1() { const options = { repository: github_1.payload.repository.full_name, - commit: github_1.payload.pull_request.head.sha, prefix: `${process.env.GITHUB_WORKSPACE}/`, - head: github_1.payload.pull_request.head.ref, - base: github_1.payload.pull_request.base.ref, }; + if (github_1.eventName === "pull_request") { + options.commit = github_1.payload.pull_request.head.sha; + options.head = github_1.payload.pull_request.head.ref; + options.base = github_1.payload.pull_request.base.ref; + } else if (github_1.eventName === "push") { + options.commit = github_1.payload.after; + options.head = github_1.ref; + } + const lcov = await parse$2(raw); const baselcov = baseRaw && await parse$2(baseRaw); const body = diff(lcov, baselcov, options); - await new github_2(token).issues.createComment({ - repo: github_1.repo.repo, - owner: github_1.repo.owner, - issue_number: github_1.payload.pull_request.number, - body: diff(lcov, baselcov, options), - }); + if (github_1.eventName === "pull_request") { + await new github_2(token).issues.createComment({ + repo: github_1.repo.repo, + owner: github_1.repo.owner, + issue_number: github_1.payload.pull_request.number, + body: diff(lcov, baselcov, options), + }); + } else if (github_1.eventName === "push") { + await new github_2(token).repos.createCommitComment({ + repo: github_1.repo.repo, + owner: github_1.repo.owner, + commit_sha: options.commit, + body: diff(lcov, baselcov, options), + }); + } } main$1().catch(function(err) { diff --git a/src/comment.js b/src/comment.js index 630ef7c9..2dd01571 100644 --- a/src/comment.js +++ b/src/comment.js @@ -5,7 +5,9 @@ import { tabulate } from "./tabulate" export function comment (lcov, options) { return fragment( - `Coverage after merging ${b(options.head)} into ${b(options.base)}`, + options.base + ? `Coverage after merging ${b(options.head)} into ${b(options.base)}` + : `Coverage for this commit`, table(tbody(tr(th(percentage(lcov).toFixed(2), "%")))), "\n\n", details(summary("Coverage Report"), tabulate(lcov, options)), @@ -29,7 +31,9 @@ export function diff(lcov, before, options) { : "▴" return fragment( - `Coverage after merging ${b(options.head)} into ${b(options.base)}`, + options.base + ? `Coverage after merging ${b(options.head)} into ${b(options.base)}` + : `Coverage for this commit`, table(tbody(tr( th(pafter.toFixed(2), "%"), th(arrow, " ", plus, pdiff.toFixed(2), "%"), diff --git a/src/index.js b/src/index.js index cbb96a22..18f17a2f 100644 --- a/src/index.js +++ b/src/index.js @@ -23,22 +23,37 @@ async function main() { const options = { repository: context.payload.repository.full_name, - commit: context.payload.pull_request.head.sha, prefix: `${process.env.GITHUB_WORKSPACE}/`, - head: context.payload.pull_request.head.ref, - base: context.payload.pull_request.base.ref, + } + + if (context.eventName === "pull_request") { + options.commit = context.payload.pull_request.head.sha + options.head = context.payload.pull_request.head.ref + options.base = context.payload.pull_request.base.ref + } else if (context.eventName === "push") { + options.commit = context.payload.after + options.head = context.ref } const lcov = await parse(raw) const baselcov = baseRaw && await parse(baseRaw) const body = diff(lcov, baselcov, options) - await new GitHub(token).issues.createComment({ - repo: context.repo.repo, - owner: context.repo.owner, - issue_number: context.payload.pull_request.number, - body: diff(lcov, baselcov, options), - }) + if (context.eventName === "pull_request") { + await new GitHub(token).issues.createComment({ + repo: context.repo.repo, + owner: context.repo.owner, + issue_number: context.payload.pull_request.number, + body: diff(lcov, baselcov, options), + }) + } else if (context.eventName === "push") { + await new GitHub(token).repos.createCommitComment({ + repo: context.repo.repo, + owner: context.repo.owner, + commit_sha: options.commit, + body: diff(lcov, baselcov, options), + }) + } } main().catch(function(err) {