-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Add descriptive check title & pull request comment summary #65
base: master
Are you sure you want to change the base?
Changes from all commits
a9caf1d
a79d871
4003780
a4acf9b
30d3dc5
c35de34
420dbd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ async function action(payload) { | |
core.error("Found no commit."); | ||
return; | ||
} | ||
const pullRequestComment = JSON.parse( | ||
core.getInput("pull_request_comment", { required: true }) | ||
); | ||
|
||
const path = core.getInput("path", { required: true }); | ||
const skipCovered = JSON.parse( | ||
|
@@ -49,14 +52,17 @@ async function action(payload) { | |
const onlyChangedFiles = JSON.parse( | ||
core.getInput("only_changed_files", { required: true }) | ||
); | ||
const reportName = core.getInput("report_name", { required: false }); | ||
const reportName = | ||
core.getInput("report_name", { required: false }) || "Coverage Report"; | ||
const checkName = | ||
core.getInput("check_name", { required: false }) || "coverage"; | ||
|
||
const changedFiles = onlyChangedFiles | ||
? await listChangedFiles(pullRequestNumber) | ||
: null; | ||
|
||
const reports = await processCoverage(path, { skipCovered }); | ||
const comment = markdownReport(reports, commit, { | ||
const [checkBody, comment] = markdownReport(reports, commit, { | ||
minimumCoverage, | ||
showLine, | ||
showBranch, | ||
|
@@ -72,13 +78,20 @@ async function action(payload) { | |
const belowThreshold = reports.some( | ||
(report) => Math.floor(report.total) < minimumCoverage | ||
); | ||
|
||
if (pullRequestNumber) { | ||
let reportTitle = reportName; | ||
// TODO: Figure out a good title for more than one report | ||
if (reports.length === 1) { | ||
const _sign = belowThreshold ? "<" : ">="; | ||
const _actual = Math.floor(reports[0].total); | ||
reportTitle = `Coverage: ${_actual}% (actual) ${_sign} ${minimumCoverage}% (expected)`; | ||
} | ||
if (pullRequestNumber && pullRequestComment) { | ||
await addComment(pullRequestNumber, comment, reportName); | ||
} | ||
await addCheck( | ||
comment, | ||
reportName, | ||
checkName, | ||
checkBody, | ||
reportTitle, | ||
commit, | ||
failBelowThreshold ? (belowThreshold ? "failure" : "success") : "neutral" | ||
); | ||
|
@@ -166,6 +179,7 @@ function markdownReport(reports, commit, options) { | |
// Setup files | ||
const files = []; | ||
let output = ""; | ||
let structuredOutput = ""; | ||
for (const report of reports) { | ||
const folder = reports.length <= 1 ? "" : ` ${report.folder}`; | ||
for (const file of report.files.filter( | ||
|
@@ -236,23 +250,23 @@ function markdownReport(reports, commit, options) { | |
return `| ${row.filter(Boolean).join(" | ")} |`; | ||
}) | ||
.join("\n"); | ||
const titleText = `<strong>${reportName}${folder}</strong>`; | ||
const titleText = `<strong>${reportName}${folder} - ${total}%</strong>`; | ||
output += `${titleText}\n\n${table}\n\n`; | ||
structuredOutput += `<details><summary>${titleText}</summary>\n\n${table}\n\n</details>\n\n`; | ||
} | ||
const minimumCoverageText = `_Minimum allowed coverage is \`${minimumCoverage}%\`_`; | ||
const footerText = `<p align="right">${credits} against ${commit} </p>`; | ||
output += `${minimumCoverageText}\n\n${footerText}`; | ||
return output; | ||
return [output, structuredOutput]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could see this being an additional |
||
} | ||
|
||
async function addComment(pullRequestNumber, body, reportName) { | ||
const comments = await client.rest.issues.listComments({ | ||
issue_number: pullRequestNumber, | ||
...github.context.repo, | ||
}); | ||
const commentFilter = reportName ? reportName : credits; | ||
const comment = comments.data.find((comment) => | ||
comment.body.includes(commentFilter) | ||
comment.body.includes(reportName) | ||
); | ||
if (comment != null) { | ||
await client.rest.issues.updateComment({ | ||
|
@@ -269,16 +283,14 @@ async function addComment(pullRequestNumber, body, reportName) { | |
} | ||
} | ||
|
||
async function addCheck(body, reportName, sha, conclusion) { | ||
const checkName = reportName ? reportName : "coverage"; | ||
|
||
async function addCheck(checkName, body, checkTitle, sha, conclusion) { | ||
await client.rest.checks.create({ | ||
name: checkName, | ||
head_sha: sha, | ||
status: "completed", | ||
conclusion: conclusion, | ||
output: { | ||
title: checkName, | ||
title: checkTitle, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
summary: body, | ||
}, | ||
...github.context.repo, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideas/suggestions welcome 🙂