aboutsummaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2019-11-10 13:44:09 -0500
committerKevin J Hoerr <kjhoerr@protonmail.com>2019-11-10 14:13:47 -0500
commitc045555e00a926e3506a80824d43ffc887e196f5 (patch)
tree7802c07d006cd6186cf80833cb1056ffb5df90b7 /index.ts
parent57acd7e00b445a075e6f57a69f5cdbdedf3e038a (diff)
downloadao-coverage-c045555e00a926e3506a80824d43ffc887e196f5.tar.gz
ao-coverage-c045555e00a926e3506a80824d43ffc887e196f5.tar.bz2
ao-coverage-c045555e00a926e3506a80824d43ffc887e196f5.zip
Set up initial project
Initializes project with TypeScript, ExpressJS, and Badgen. Defines initial (v1) request paths: GET /bash GET /v1/:org/:repo/:branch.svg GET /v1/:org/:repo/:branch.html GET /v1/:org/:repo/:branch/:commit.svg GET /v1/:org/:repo/:branch/:commit.html POST /v1/:org/:repo/:branch/:commit.html?token=&format= Also sets up interfaces for defining multiple formats. Tarpaulin is defined but not implemented. All requests (aside from GET /bash) return 501 NOT IMPLEMENTED. A global TOKEN is expected for POST request. This can and should be adapted to assigning tokens per repository, though this may require verification from the originating repository or administrative designation.
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts91
1 files changed, 91 insertions, 0 deletions
diff --git a/index.ts b/index.ts
new file mode 100644
index 0000000..5e54c84
--- /dev/null
+++ b/index.ts
@@ -0,0 +1,91 @@
+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';
+
+// 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 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;
+ if (token != TOKEN) {
+ return res.status(401).send();
+ }
+
+ const reporter = format || "tarpaulin";
+ if (!formats.list_formats().includes(reporter)) {
+ 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 %
+ //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 set branch alias for coverage % / uploaded file
+});
+
+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
+ return res.status(501).send();
+});
+
+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
+ return res.status(501).send();
+});
+
+// provide hard link for commit
+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
+ return res.status(501).send();
+});
+
+// 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);
+
+ //TODO link the file
+ return res.status(501).send();
+});
+
+app.listen(PORT, () => {
+ console.log('Express started on port ' + PORT);
+});