aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2019-11-23 12:02:45 -0500
committerKevin J Hoerr <kjhoerr@protonmail.com>2019-11-23 12:02:45 -0500
commit62a6c312a19824a284d95d6f81d3eb5da86dbf5a (patch)
treeee398cb28006ed3d988b93bd9bf0a7c64953fcaf /src/index.ts
parenta4fdedfcac02cb53608d9d3b9e96de0526140fd7 (diff)
downloadao-coverage-62a6c312a19824a284d95d6f81d3eb5da86dbf5a.tar.gz
ao-coverage-62a6c312a19824a284d95d6f81d3eb5da86dbf5a.tar.bz2
ao-coverage-62a6c312a19824a284d95d6f81d3eb5da86dbf5a.zip
Generate report badge with color gradient
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/index.ts b/src/index.ts
index 5e54c84..ca65cb9 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,6 @@
import dotenv from 'dotenv';
import express from 'express';
-import badgen from 'badgen';
+import {badgen} from 'badgen';
import path from 'path';
import fs from 'fs';
@@ -27,6 +27,7 @@ app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => {
console.info("POST request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit);
const {token, format} = req.query;
+ //TODO @Metadata token should come from metadata
if (token != TOKEN) {
return res.status(401).send();
}
@@ -36,27 +37,35 @@ app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => {
return res.status(406).send();
}
- return res.status(501).send();
-
//TODO acquire file, verify file size/content type (HTML)
const contents = "";
//req.on('data', (raw) => {});
//req.on('end', () => {});
- // const doc = new DOMParser().parseFromString(contents, "text/html");
- // const coverage = formats.get_format(reporter).parse_coverage(doc);
- //TODO create badge for coverage %
+ const doc = new DOMParser().parseFromString(contents, "text/html");
+ const formatter = formats.get_format(reporter);
+ const coverage = formatter.parse_coverage(doc);
+
+ 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),
+ });
//TODO store coverage % badge at %HOST_DIR%/%org%/%repo%/%commit%/badge.svg
- //TODO store uploaded file at %HOST_DIR%/%org%/%repo%/%commit%/index.html
+ //TODO store report file at %HOST_DIR%/%org%/%repo%/%commit%/index.html
- //TODO set branch alias for coverage % / uploaded file
+ //TODO @Metadata set branch alias for badge / report file
+
+ return res.status(501).send();
});
app.get('/v1/:org/:repo/:branch.svg', (req, res) => {
const {org, repo, branch} = req.params;
console.info("GET request to /v1/%s/%s/%s.svg", org, repo, branch);
- //TODO link the badge via metadata
+ //TODO @Metadata get the commit @@ via metadata
+ //TODO send the badge file
return res.status(501).send();
});
@@ -64,7 +73,8 @@ app.get('/v1/:org/:repo/:branch.html', (req, res) => {
const {org, repo, branch} = req.params;
console.info("GET request to /v1/%s/%s/%s.html", org, repo, branch);
- //TODO link the file via metadata
+ //TODO @Metadata get the commit @@ via metadata
+ //TODO send the report file
return res.status(501).send();
});
@@ -73,7 +83,7 @@ app.get('/v1/:org/:repo/:branch/:commit.svg', (req, res) => {
const {org, repo, branch, commit} = req.params;
console.info("GET request to /v1/%s/%s/%s/%s.svg", org, repo, branch, commit);
- //TODO link the badge
+ //TODO send the badge file
return res.status(501).send();
});
@@ -82,7 +92,7 @@ app.get('/v1/:org/:repo/:branch/:commit.html', (req, res) => {
const {org, repo, branch, commit} = req.params;
console.info("GET request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit);
- //TODO link the file
+ //TODO send the report file
return res.status(501).send();
});