aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/formats.ts66
-rw-r--r--src/index.ts75
2 files changed, 80 insertions, 61 deletions
diff --git a/src/formats.ts b/src/formats.ts
index db9a188..34f97df 100644
--- a/src/formats.ts
+++ b/src/formats.ts
@@ -1,46 +1,52 @@
interface Format {
- // returns the coverage value as %: Number(90.0), Number(100.0), Number(89.5)
- parse_coverage: (file: Document) => number,
- match_color: (coverage: number, stage_1: number, stage_2: number) => string,
+ // returns the coverage value as %: Number(90.0), Number(100.0), Number(89.5)
+ parse_coverage: (file: Document) => number;
+ match_color: (coverage: number, stage_1: number, stage_2: number) => string;
}
interface FormatList {
- [key: string]: Format
+ [key: string]: Format;
}
interface FormatObj {
- formats: FormatList,
- list_formats: () => string[],
- get_format: (format: string) => Format,
+ formats: FormatList;
+ list_formats: () => string[];
+ get_format: (format: string) => Format;
}
// 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 gradient = coverage >= stage_1 ? 15 :
- (coverage >= stage_2 ?
- (Math.floor(coverage) - stage_2) * 16 + 15 :
- 240 + Math.floor(coverage / (stage_2 / 15)));
- return gradient.toString(16) + "0";
+const default_color_matches = (
+ coverage: number,
+ stage_1: number,
+ stage_2: number
+) => {
+ const gradient =
+ coverage >= stage_1
+ ? 15
+ : coverage >= stage_2
+ ? (Math.floor(coverage) - stage_2) * 16 + 15
+ : 240 + Math.floor(coverage / (stage_2 / 15));
+ return gradient.toString(16) + "0";
};
const FormatsObj: FormatObj = {
- formats: {
- tarpaulin: {
- parse_coverage: (file: Document) => {
- //TODO parse coverage from file (example?)
- return 0.0;
- },
- match_color: default_color_matches,
- },
- },
+ formats: {
+ tarpaulin: {
+ parse_coverage: (file: Document) => {
+ //TODO parse coverage from file (example?)
+ return 0.0;
+ },
+ match_color: default_color_matches
+ }
+ },
- list_formats: function () {
- return Object.keys(this.formats);
- },
+ list_formats: function() {
+ return Object.keys(this.formats);
+ },
- get_format: function (format: string) {
- return this.formats[format];
- }
-}
+ get_format: function(format: string) {
+ return this.formats[format];
+ }
+};
-export default FormatsObj; \ No newline at end of file
+export default FormatsObj;
diff --git a/src/index.ts b/src/index.ts
index ca65cb9..4fe80a9 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,32 +1,39 @@
-import dotenv from 'dotenv';
-import express from 'express';
-import {badgen} from 'badgen';
-import path from 'path';
-import fs from 'fs';
+import dotenv from "dotenv";
+import express from "express";
+import { badgen } from "badgen";
+import path from "path";
+import fs from "fs";
-import formats from './formats';
-import metadata from './metadata';
+import formats from "./formats";
+import metadata from "./metadata";
// Start-up configuration
dotenv.config();
const PORT = process.env.PORT ? Number(process.env.PORT) : 3000;
const TOKEN = process.env.TOKEN || "";
-const HOST_DIR = process.env.HOST_DIR || (() => {
- throw Error("HOST_DIR must be defined");
-})();
+const HOST_DIR =
+ process.env.HOST_DIR ||
+ (() => {
+ throw Error("HOST_DIR must be defined");
+ })();
const app: express.Application = express();
// serve script for posting coverage report
-app.use('/bash', express.static(path.join(__dirname, '..', 'public', 'bash')));
-
-// Upload HTML file
-app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => {
-
- const {org, repo, branch, commit} = req.params;
- console.info("POST request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit);
-
- const {token, format} = req.query;
+app.use("/bash", express.static(path.join(__dirname, "..", "public", "bash")));
+
+// Upload HTML file
+app.post("/v1/:org/:repo/:branch/:commit.html", (req, res) => {
+ const { org, repo, branch, commit } = req.params;
+ 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();
@@ -50,7 +57,7 @@ app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => {
label: "coverage",
status: Math.floor(coverage).toString() + "%",
//TODO @Metadata stage values should come from metadata
- color: formatter.match_color(coverage, 95, 80),
+ color: formatter.match_color(coverage, 95, 80)
});
//TODO store coverage % badge at %HOST_DIR%/%org%/%repo%/%commit%/badge.svg
//TODO store report file at %HOST_DIR%/%org%/%repo%/%commit%/index.html
@@ -60,8 +67,8 @@ app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => {
return res.status(501).send();
});
-app.get('/v1/:org/:repo/:branch.svg', (req, res) => {
- const {org, repo, branch} = req.params;
+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 @Metadata get the commit @@ via metadata
@@ -69,8 +76,8 @@ app.get('/v1/:org/:repo/:branch.svg', (req, res) => {
return res.status(501).send();
});
-app.get('/v1/:org/:repo/:branch.html', (req, res) => {
- const {org, repo, branch} = req.params;
+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 @Metadata get the commit @@ via metadata
@@ -79,8 +86,8 @@ app.get('/v1/:org/:repo/:branch.html', (req, res) => {
});
// provide hard link for commit
-app.get('/v1/:org/:repo/:branch/:commit.svg', (req, res) => {
- const {org, repo, branch, commit} = req.params;
+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 send the badge file
@@ -88,14 +95,20 @@ app.get('/v1/:org/:repo/:branch/:commit.svg', (req, res) => {
});
// provide hard link for commit
-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);
-
+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 send the report file
return res.status(501).send();
});
app.listen(PORT, () => {
- console.log('Express started on port ' + PORT);
+ console.log("Express started on port " + PORT);
});