diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-09 10:58:28 -0500 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-09 10:58:28 -0500 |
| commit | d57a1130908e920d1b033a268dac6b71a5b88978 (patch) | |
| tree | 0daa00f0d2c289b58bcf7de79105736fb6f5dd7f /src | |
| parent | 90424d59e7f038af6f9b6b69029ab5c43b1a01ee (diff) | |
| download | ao-coverage-d57a1130908e920d1b033a268dac6b71a5b88978.tar.gz ao-coverage-d57a1130908e920d1b033a268dac6b71a5b88978.tar.bz2 ao-coverage-d57a1130908e920d1b033a268dac6b71a5b88978.zip | |
Promisify data flow in POST request
Diffstat (limited to 'src')
| -rw-r--r-- | src/formats.ts | 21 | ||||
| -rw-r--r-- | src/routes.ts | 30 |
2 files changed, 32 insertions, 19 deletions
diff --git a/src/formats.ts b/src/formats.ts index 1b5a572..4b432e3 100644 --- a/src/formats.ts +++ b/src/formats.ts @@ -3,7 +3,7 @@ import { InvalidReportDocumentError } from "./errors"; export interface Format { // returns the coverage value as %: Number(90.0), Number(100.0), Number(89.5) parse_coverage: (file: Document) => number | InvalidReportDocumentError; - match_color: (coverage: number, stage_1: number, stage_2: number) => string; + match_color: (coverage: number, style: GradientStyle) => string; } interface FormatList { @@ -16,18 +16,19 @@ interface FormatObj { get_format: (format: string) => Format; } +export interface GradientStyle { + stage_1: number; + stage_2: number; +} + // color is a gradient from green (>=stage_1) -> yellow (stage_2) -> red. Stage values should come from metadata. -const default_color_matches = ( - coverage: number, - stage_1: number, - stage_2: number -) => { +const default_color_matches = (coverage: number, style: GradientStyle) => { const gradient = - coverage >= stage_1 + coverage >= style.stage_1 ? 15 - : coverage >= stage_2 - ? (Math.floor(coverage) - stage_2) * 16 + 15 - : 240 + Math.floor(coverage / (stage_2 / 15)); + : coverage >= style.stage_2 + ? (Math.floor(coverage) - style.stage_2) * 16 + 15 + : 240 + Math.floor(coverage / (style.stage_2 / 15)); return gradient.toString(16) + "0"; }; diff --git a/src/routes.ts b/src/routes.ts index 4bfee0d..9d435af 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -5,7 +5,7 @@ import winston from "winston"; import path from "path"; import fs from "fs"; -import formats from "./formats"; +import formats, { GradientStyle } from "./formats"; import Metadata, { HeadIdentity } from "./metadata"; import { config_or_error } from "./util/config"; import logger_config from "./util/logger"; @@ -53,18 +53,30 @@ export default (metadata: Metadata) => { return res.status(400).send(result.message); } - const badge = badgen({ - label: "coverage", - status: Math.floor(coverage).toString() + "%", - //TODO @Metadata stage values should come from metadata - color: formatter.match_color(coverage, 95, 80) - }); - const report_path = path.join(HOST_DIR, org, repo, branch, commit); fs.promises .mkdir(report_path, { recursive: true }) - .then(() => + .then( + () => + //TODO @Metadata stage values should come from metadata + new Promise<GradientStyle>(solv => + solv({ stage_1: 95, stage_2: 80 }) + ) + ) + .then( + style => + new Promise(solv => + solv( + badgen({ + label: "coverage", + status: Math.floor(coverage).toString() + "%", + color: formatter.match_color(coverage, style) + }) + ) + ) + ) + .then(badge => fs.promises.writeFile(path.join(report_path, "badge.svg"), badge) ) .then(() => |
