forked from rpl/flow-coverage-report
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses: rpl#129
- Loading branch information
runarberg
committed
Nov 15, 2017
1 parent
d4963be
commit 9d7eb92
Showing
4 changed files
with
66 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
// @flow | ||
|
||
import path from 'path'; | ||
|
||
import badge from 'badge-up'; | ||
|
||
import {mkdirp, writeFile} from './promisified'; | ||
|
||
import type {FlowCoverageSummaryData} from './flow'; | ||
import type {FlowCoverageReportOptions} from './index'; | ||
|
||
function saveBadgeReport( | ||
coverageData: FlowCoverageSummaryData, | ||
opts: FlowCoverageReportOptions | ||
): Promise<void> { | ||
const percent = coverageData.percent; | ||
const threshold = opts.threshold || 80; | ||
const difference = percent - threshold; | ||
|
||
let color; | ||
|
||
if (difference < -40) { | ||
color = 'red'; | ||
} else if (difference < -30) { | ||
color = 'orange'; | ||
} else if (difference < -20) { | ||
color = 'yellow'; | ||
} else if (difference < -10) { | ||
color = 'yellowgreen'; | ||
} else if (difference < 0) { | ||
color = 'green'; | ||
} else { | ||
color = 'brightgreen'; | ||
} | ||
|
||
const badgeGen = () => new Promise((resolve, reject) => { | ||
badge('flow', `${percent}%`, badge.colors[color], (err, svg) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(svg); | ||
} | ||
}); | ||
}); | ||
|
||
const projectDir = opts.projectDir; | ||
const outputDir = opts.outputDir || path.join(projectDir, 'flow-coverage'); | ||
|
||
return mkdirp(outputDir).then(badgeGen).then(svg => { | ||
return writeFile(path.join(outputDir, 'flow-coverage.svg'), svg); | ||
}); | ||
} | ||
|
||
export default { | ||
generate: saveBadgeReport | ||
}; |