Skip to content
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

ADD: median & global badges, summary.json & maintainability-report.json #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# production
/build
bin
generated

# misc
.DS_Store
Expand Down
56 changes: 48 additions & 8 deletions src/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getBadgeColor = (percent: number): string => {
}

export const generateBadge = (results: Results): void => {
const { average, worst } = results.summary
const { average, median, worst } = results.summary
const { badgesDirectory } = results.options
const badgesPath = badgesDirectory[0] || '' // Fall back to root
const actualPath = slash(process.cwd()) + badgesPath
Expand All @@ -41,18 +41,58 @@ export const generateBadge = (results: Results): void => {
} catch (error) {
console.error(error)
}
try {
fs.writeFileSync(
`${actualPath}/med-maintainability.svg`,
badgen({
label: 'maintainability (median)',
status: `${median.toFixed(2)}`,
color: getBadgeColor(median),
}),
'utf8'
)
} catch (error) {
console.error(error)
}

try {
const global = Math.min(average,median);
fs.writeFileSync(
`${actualPath}/worst-maintainability.svg`,
badgen({
label: 'maintainability (worst)',
status: `${worst.toFixed(2)}`,
color: getBadgeColor(worst),
}),
'utf8'
`${actualPath}/global-maintainability.svg`,
badgen({
label: 'maintainability',
status: `${global.toPrecision(2)}`,
color: getBadgeColor(global),
}),
'utf8'
)
} catch (error) {
console.error(error)
}

try {
fs.writeFileSync(
`${actualPath}/worst-maintainability.svg`,
badgen({
label: 'maintainability (worst)',
status: `${worst.toFixed(2)}`,
color: getBadgeColor(worst),
}),
'utf8'
)
} catch (error) {
console.error(error)
}

try {
const global = Math.min(average,median);
fs.writeFileSync(`${actualPath}/summary.json`, JSON.stringify({global,average,median,worst}),'utf8')
} catch (error) {
console.error(error)
}
try {
fs.writeFileSync(`${actualPath}/maintainability-report.json`, JSON.stringify(results),'utf8')
} catch (error) {
console.error(error)
}
}