Skip to content

Commit

Permalink
Merge pull request #5 from ambimax/add-support-for-push-event
Browse files Browse the repository at this point in the history
Add support for push event
  • Loading branch information
romeovs authored Dec 29, 2020
2 parents d69c1ec + 04e819e commit af0c2c8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
41 changes: 30 additions & 11 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22915,7 +22915,9 @@ function ranges(linenos) {

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)),
Expand All @@ -22939,7 +22941,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), "%"),
Expand Down Expand Up @@ -22967,22 +22971,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) {
Expand Down
8 changes: 6 additions & 2 deletions src/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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), "%"),
Expand Down
33 changes: 24 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit af0c2c8

Please sign in to comment.