-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from brenoepics/code-health
feat: implement code health and new template
- Loading branch information
Showing
15 changed files
with
1,425 additions
and
2,322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { VMDAnalysis } from "../types.js"; | ||
import { | ||
getCoverageInfo, | ||
replaceBadges, | ||
replaceCodeHealth, | ||
replaceRepoData | ||
} from "./utils.js"; | ||
import { getReportTemplate } from "./reportTemplate.js"; | ||
|
||
const commentTemplate: string = ` | ||
## 📊 Vue Mess Detector Analysis Results | ||
#### {{coverageBadge}} | ||
{{coverageInfo}} | ||
{{reportBlock}} | ||
{{artifactText}} | ||
###### For any issues or feedback, feel free to [report them here](https://github.com/brenoepics/vmd-action/issues/). | ||
`; | ||
|
||
export const coverageInfo: string = ` | ||
🚨 Errors: {{errors}} | ||
⚠️ Warnings: {{warnings}} | ||
📝 Total Lines: {{linesCount}} | ||
📁 Total Files: {{filesCount}} | ||
`; | ||
|
||
export const artifactText: string = ` | ||
🔍 [View Full Analysis Details](../actions/runs/{{runId}}/artifacts/{{artifactId}}) | ||
`; | ||
|
||
export function getCommentTemplate( | ||
result: VMDAnalysis, | ||
artifactId: number | undefined | ||
): string { | ||
let message: string = replaceRepoData(commentTemplate, artifactId); | ||
if (result.codeHealth) { | ||
message = replaceCodeHealth(message, result.codeHealth); | ||
} else { | ||
message = message.replace(/{{coverageInfo}}/g, getCoverageInfo(result)); | ||
} | ||
|
||
message = replaceBadges(message, result); | ||
message = message.replace(/{{reportBlock}}/g, getReportTemplate(result)); | ||
return message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ReportOutput, VMDAnalysis } from "../types.js"; | ||
import { getReportAsMap } from "./utils.js"; | ||
import path from "node:path"; | ||
const reportBlock: string = ` | ||
<details> | ||
<summary>VMD Report</summary> | ||
{{outputList}} | ||
</details> | ||
`; | ||
|
||
export function getReportTemplate(analysis: VMDAnalysis): string { | ||
const codeBlock: string = `\`\`\`\n${renderReport(analysis.reportOutput)}\n\`\`\``; | ||
return reportBlock.replace(/{{outputList}}/g, codeBlock); | ||
} | ||
|
||
export function renderReport(analysis: { | ||
[key: string]: ReportOutput[]; | ||
}): string { | ||
let outputList: string = ""; | ||
const res: Map<string, ReportOutput[]> = getReportAsMap(analysis); | ||
|
||
res.forEach((value, key) => { | ||
outputList += renderReportsByKey(key, value); | ||
}); | ||
|
||
return outputList; | ||
} | ||
|
||
function isPath(key: string): boolean { | ||
return path.isAbsolute(key) || key.includes(path.sep); | ||
} | ||
|
||
function renderReportsByKey(key: string, value: ReportOutput[]) { | ||
if (isPath(key)) { | ||
key = path.relative(process.cwd(), key); | ||
} | ||
let output: string = `\n- ${key}:`; | ||
value.forEach(report => (output += singleReport(report))); | ||
return output; | ||
} | ||
|
||
const singleReport: (report: ReportOutput) => string = ( | ||
report: ReportOutput | ||
): string => { | ||
if (isPath(report.id)) { | ||
report.id = path.relative(process.cwd(), report.id); | ||
} | ||
return `\n ${report.id}: ${report.message}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CodeHealth, ReportOutput, VMDAnalysis } from "../types.js"; | ||
import * as github from "@actions/github"; | ||
import { artifactText, coverageInfo } from "./commentTemplate.js"; | ||
import { getCoverageBadge } from "./badgeTemplate.js"; | ||
|
||
export function getReportAsMap(report: { | ||
[key: string]: ReportOutput[]; | ||
}): Map<string, ReportOutput[]> { | ||
const reportOutputMap: Map<string, ReportOutput[]> = new Map< | ||
string, | ||
ReportOutput[] | ||
>(); | ||
|
||
for (const [parent, outputs] of Object.entries(report)) { | ||
reportOutputMap.set(parent, outputs); | ||
} | ||
|
||
return reportOutputMap; | ||
} | ||
|
||
export function getCoverageInfo(result: VMDAnalysis): string { | ||
return result.codeHealthOutput.map(element => element.info).join("\n"); | ||
} | ||
|
||
export function replaceCodeHealth(message: string, health: CodeHealth): string { | ||
return message | ||
.replace(/{{coverageInfo}}/g, coverageInfo) | ||
.replace(/{{errors}}/g, health.errors.toLocaleString()) | ||
.replace(/{{warnings}}/g, health.warnings.toLocaleString()) | ||
.replace(/{{linesCount}}/g, health.linesCount.toLocaleString()) | ||
.replace(/{{filesCount}}/g, health.filesCount.toLocaleString()) | ||
.replace(/{{points}}/g, health.points ? health.points.toString() : "0"); | ||
} | ||
|
||
export function replaceRepoData( | ||
message: string, | ||
artifactId: number | undefined | ||
): string { | ||
return message | ||
.replace(/{{artifactText}}/g, artifactId ? artifactText : "") | ||
.replace(/{{artifactId}}/g, String(artifactId ?? 0)) | ||
.replace(/{{runId}}/g, github.context.runId.toString()) | ||
.replace(/{{repository/g, github.context.repo.repo) | ||
.replace(/{{repositoryOwner/g, github.context.repo.owner); | ||
} | ||
|
||
export function replaceBadges(message: string, result: VMDAnalysis): string { | ||
return message.replace( | ||
/{{coverageBadge}}/g, | ||
getCoverageBadge(result.codeHealth?.points) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.