From 1158e558606034b681f4663d62677e798cf5ec23 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Fri, 29 Nov 2019 18:28:54 -0500 Subject: Implement report parsing for Tarpaulin The generated Tarpaulin HTML report does not have stats to parse via the DOM - the data is injected via a script tag, which only has line-by-line coverage, though it includes statistics for each file. The total coverage is counted by summing the covered/coverable stats reported for each file. Also, the bad version for express is fixed, and messages are included for errors that occur for the POST endpoint. --- src/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 4fe80a9..d592405 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,12 +36,12 @@ app.post("/v1/:org/:repo/:branch/:commit.html", (req, res) => { const { token, format } = req.query; //TODO @Metadata token should come from metadata if (token != TOKEN) { - return res.status(401).send(); + return res.status(401).send("Invalid token"); } const reporter = format || "tarpaulin"; if (!formats.list_formats().includes(reporter)) { - return res.status(406).send(); + return res.status(406).send("Report format unknown"); } //TODO acquire file, verify file size/content type (HTML) @@ -51,7 +51,12 @@ app.post("/v1/:org/:repo/:branch/:commit.html", (req, res) => { const doc = new DOMParser().parseFromString(contents, "text/html"); const formatter = formats.get_format(reporter); - const coverage = formatter.parse_coverage(doc); + let coverage: number; + try { + coverage = formatter.parse_coverage(doc); + } catch { + return res.status(400).send("Invalid report document"); + } const badge = badgen({ label: "coverage", -- cgit