Skip to content

Commit

Permalink
🚸 Improve GitHub action summary
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Apr 24, 2023
1 parent 5e14015 commit ddd70ab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
32 changes: 19 additions & 13 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72644,15 +72644,20 @@ var require_output = __commonJS({
var ANNOTATION_NOTICE = "notice";
var SUMMARY_TABLE_HEADER = "| Name | Severity | Problems |";
var SUMMARY_TABLE_SEP = "| --- | --- | --- |";
var SUMMARY_MISC = `### Contact us

Contact us at [qodana-support@jetbrains.com](mailto:qodana-support@jetbrains.com)
var SUMMARY_MISC = `Contact us at [qodana-support@jetbrains.com](mailto:qodana-support@jetbrains.com)
- Or via our issue tracker: https://jb.gg/qodana-issue
- Or share your feedback: https://jb.gg/qodana-discussions`;
function getViewReportText(sarifPath) {
var _a, _b, _c, _d;
const sarif = JSON.parse(fs.readFileSync(sarifPath, { encoding: "utf8" }));
const link = (_d = (_c = (_b = (_a = sarif.runs) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c["reportUrl"]) !== null && _d !== void 0 ? _d : "";
function wrapToToggleBlock(header, body) {
return `<details>
<summary>${header}</summary>

${body}
</details>`;
}
__name(wrapToToggleBlock, "wrapToToggleBlock");
function getViewReportText() {
var _a;
const link = (_a = process.env["QODANA_REPORT_URL"]) !== null && _a !== void 0 ? _a : "";
if (link !== "") {
return `\u2601\uFE0F [View the Qodana report](${link})`;
}
Expand All @@ -72667,16 +72672,17 @@ var require_output = __commonJS({
return Array.from(problems.entries()).sort((a, b) => b[1] - a[1]).map(([title, count]) => `| ${title} | ${level} | ${count} |`).join("\n");
}
__name(getRowsByLevel, "getRowsByLevel");
function getSummary(annotations, shortSarifPath) {
function getSummary(annotations) {
const contactBlock = wrapToToggleBlock("Contact Qodana team", SUMMARY_MISC);
if (annotations.length === 0) {
return [
`# ${QODANA_CHECK_NAME}`,
"",
"**It seems all right \u{1F44C}**",
"",
"No problems found according to the checks applied",
getViewReportText(shortSarifPath),
SUMMARY_MISC
getViewReportText(),
contactBlock
].join("\n");
}
return [
Expand All @@ -72692,8 +72698,8 @@ var require_output = __commonJS({
getRowsByLevel(annotations.filter((a) => a.level === ANNOTATION_NOTICE), "\u25FD\uFE0F Notice")
].filter((e) => e !== "").join("\n"),
"",
getViewReportText(shortSarifPath),
SUMMARY_MISC
getViewReportText(),
contactBlock
].join("\n");
}
__name(getSummary, "getSummary");
Expand Down Expand Up @@ -72773,7 +72779,7 @@ var require_output = __commonJS({
}
}
}
yield core2.summary.addRaw(getSummary(problems, shortSarifPath)).write();
yield core2.summary.addRaw(getSummary(problems)).write();
} catch (error) {
core2.warning(`Failed to publish annotations \u2013 ${error.message}`);
}
Expand Down
31 changes: 19 additions & 12 deletions scan/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ const ANNOTATION_WARNING = 'warning'
const ANNOTATION_NOTICE = 'notice'
const SUMMARY_TABLE_HEADER = '| Name | Severity | Problems |'
const SUMMARY_TABLE_SEP = '| --- | --- | --- |'
const SUMMARY_MISC = `### Contact us
Contact us at [qodana-support@jetbrains.com](mailto:qodana-support@jetbrains.com)
const SUMMARY_MISC = `Contact us at [qodana-support@jetbrains.com](mailto:qodana-support@jetbrains.com)
- Or via our issue tracker: https://jb.gg/qodana-issue
- Or share your feedback: https://jb.gg/qodana-discussions`

Expand All @@ -28,9 +26,16 @@ export interface Annotation {
properties: AnnotationProperties
}

function getViewReportText(sarifPath: string): string {
const sarif: Log = JSON.parse(fs.readFileSync(sarifPath, {encoding: 'utf8'}))
const link: string = sarif.runs?.[0]?.properties?.['reportUrl'] ?? ''
function wrapToToggleBlock(header: string, body: string): string {
return `<details>
<summary>${header}</summary>
${body}
</details>`
}

function getViewReportText(): string {
const link: string = process.env['QODANA_REPORT_URL'] ?? ''
if (link !== '') {
return `☁️ [View the Qodana report](${link})`
}
Expand Down Expand Up @@ -64,16 +69,18 @@ function getRowsByLevel(annotations: Annotation[], level: string): string {
* @param annotations The annotations to generate the summary from.
* @param shortSarifPath The path to the SARIF file.
*/
function getSummary(annotations: Annotation[], shortSarifPath: string): string {
function getSummary(annotations: Annotation[]): string {
const contactBlock = wrapToToggleBlock('Contact Qodana team', SUMMARY_MISC)

if (annotations.length === 0) {
return [
`# ${QODANA_CHECK_NAME}`,
'',
'**It seems all right 👌**',
'',
'No problems found according to the checks applied',
getViewReportText(shortSarifPath),
SUMMARY_MISC
getViewReportText(),
contactBlock
].join('\n')
}

Expand Down Expand Up @@ -103,8 +110,8 @@ function getSummary(annotations: Annotation[], shortSarifPath: string): string {
.filter(e => e !== '')
.join('\n'),
'',
getViewReportText(shortSarifPath),
SUMMARY_MISC
getViewReportText(),
contactBlock
].join('\n')
}

Expand Down Expand Up @@ -216,7 +223,7 @@ export async function publishOutput(
}
}
}
await core.summary.addRaw(getSummary(problems, shortSarifPath)).write()
await core.summary.addRaw(getSummary(problems)).write()
} catch (error) {
core.warning(`Failed to publish annotations – ${(error as Error).message}`)
}
Expand Down

0 comments on commit ddd70ab

Please sign in to comment.