: nply/minci

commit 74af646331e34f59b2c4fba9c5ec9ddc2bfce55b
parent 246c129a9877caf8a7fdb1a42be889ccdb73cf8c
Author: kristapsdz <kristaps@bsd.lv>
Date: Tue, 17 Mar 2020 15:08:18 +0000

Further improvements to front-end.
4 files changed, 310 insertions(+), 53 deletions(-)
M
Makefile
|
3
+++
M
db.ort
|
4
++--
M
main.c
|
277
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
M
minci.css
|
79
++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
diff --git a/Makefile b/Makefile
@@ -25,6 +25,9 @@ updatecgi: all
 	install -o www -m 0444 minci.css $(WWWPREFIX)/htdocs
 	install -o www -m 0500 minci.cgi $(WWWPREFIX)/cgi-bin
 
+testupdatedb:
+	ort-sqldiff $(PREFIX)/data/minci.ort db.ort || true
+
 updatedb:
 	mkdir -p $(WWWPREFIX)/data
 	cp -f $(WWWPREFIX)/data/minci.db $(WWWPREFIX)/data/minci.db.old
diff --git a/db.ort b/db.ort
@@ -110,13 +110,13 @@ struct report {
 
 	iterate ctime ge, ctime le: limit 50 name lastdate order ctime desc;
 
-	iterate: name dash order projectid,ctime desc grouprow unamehash maxrow ctime;
+	list: name dash order projectid,ctime desc grouprow unamehash maxrow ctime;
 	iterate project.name: name dashname order ctime desc grouprow unamehash maxrow ctime;
 
 	search id: name byid;
 
 	roles consumer {
-		iterate dash;
+		list dash;
 		iterate lastdate;
 		iterate dashname;
 		noexport userid;
diff --git a/main.c b/main.c
@@ -14,12 +14,14 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/queue.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
 #include <assert.h>
 #include <err.h>
 #include <inttypes.h>
+#include <math.h> /* floor */
 #include <md5.h>
 #include <stdarg.h>
 #include <stdint.h>

@@ -36,6 +38,9 @@
 #ifndef REPO_BASE
 #define REPO_BASE "https://github.com/kristapsdz"
 #endif
+#ifndef COMMIT_BASE
+#define COMMIT_BASE REPO_BASE
+#endif
 
 enum	page {
 	PAGE_INDEX,

@@ -168,6 +173,9 @@ get_html_last_header(struct khtmlreq *req)
 		"head report-id", KATTR__MAX);
 	khtml_closeelem(req, 1); /* cell */
 	khtml_attr(req, KELEM_DIV, KATTR_CLASS, 
+		"head report-commit", KATTR__MAX);
+	khtml_closeelem(req, 1); /* cell */
+	khtml_attr(req, KELEM_DIV, KATTR_CLASS, 
 		"head report-start", KATTR__MAX);
 	khtml_closeelem(req, 1); /* cell */
 	khtml_attr(req, KELEM_DIV, KATTR_CLASS, 

@@ -195,8 +203,8 @@ get_html_last_header(struct khtmlreq *req)
 	khtml_closeelem(req, 1); /* cell */
 	khtml_attr(req, KELEM_DIV, KATTR_CLASS, 
 		"head report-dist", KATTR__MAX);
-	khtml_closeelem(req, 1); /* cellgroup */
 	khtml_closeelem(req, 1); /* cell */
+	khtml_closeelem(req, 1); /* cellgroup */
 	khtml_closeelem(req, 1); /* row */
 }
 

@@ -209,7 +217,8 @@ get_html_last_report(const struct report *p, void *arg)
 	struct req	*r = arg;
 	struct tm	 tm;
 	int64_t		 date;
-	char		*urlid, *urlproj, *urldate;
+	char		*urlid, *urlproj, *urldate, *urlcommit;
+	char		 commitshort[8];
 
 	memset(&tm, 0, sizeof(struct tm));
 	KUTIL_EPOCH2TM(p->ctime, &tm);

@@ -234,6 +243,9 @@ get_html_last_report(const struct report *p, void *arg)
 		pages[PAGE_INDEX],
 		valid_keys[VALID_REPORT_CTIME].name,
 		KATTRX_INT, date, NULL);
+	kasprintf(&urlcommit, "%s/%s/tree/%s",
+		COMMIT_BASE, p->project.name,
+		p->fetchhead);
 
 	memset(&tm, 0, sizeof(struct tm));
 	KUTIL_EPOCH2TM(p->start, &tm);

@@ -265,6 +277,15 @@ get_html_last_report(const struct report *p, void *arg)
 	khtml_closeelem(&r->html, 1); /* cell */
 
 	khtml_attr(&r->html, KELEM_DIV, KATTR_CLASS, 
+		"cell report-commit", KATTR__MAX);
+	khtml_attr(&r->html, KELEM_A, KATTR_HREF, 
+		urlcommit, KATTR__MAX);
+	strlcpy(commitshort, p->fetchhead, sizeof(commitshort));
+	khtml_puts(&r->html, commitshort);
+	khtml_closeelem(&r->html, 1); /* a */
+	khtml_closeelem(&r->html, 1); /* cell */
+
+	khtml_attr(&r->html, KELEM_DIV, KATTR_CLASS, 
 		"cell report-start", KATTR__MAX);
 	khtml_attr(&r->html, KELEM_A,
 		KATTR_HREF, urldate, KATTR__MAX);

@@ -316,6 +337,7 @@ get_html_last_report(const struct report *p, void *arg)
 	free(urlid);
 	free(urlproj);
 	free(urldate);
+	free(urlcommit);
 }
 
 /*

@@ -410,6 +432,11 @@ get_single_html(struct kreq *r, const struct report *p)
 	get_html_uname(&req, p);
 	khtml_closeelem(&req, 1); /* div */
 
+	khtml_attr(&req, KELEM_DIV, KATTR_CLASS,
+		"lefthead report-system-ext", KATTR__MAX);
+	khtml_puts(&req, p->unamev);
+	khtml_closeelem(&req, 1); /* div */
+
 	khtml_attr(&req, KELEM_DIV,
 		KATTR_CLASS, "leftgroup", KATTR__MAX);
 	get_html_offs(&req, "lefthead "

@@ -506,6 +533,213 @@ get_single(struct kreq *r, time_t mtime)
 	db_report_free(p);
 }
 
+struct	dash {
+	const struct project	*proj;
+	const char		*nhash;
+	time_t			 nctime;
+	size_t			 finished;
+	size_t			 success;
+	size_t			 pending;
+};
+
+/*
+ * List the last *n* records, sorted by time of accept.
+ * Always outputs HTTP 200.
+ */
+static void
+get_dash(struct kreq *r, time_t mtime)
+{
+	struct req	 req;
+	struct report_q	*rq;
+	struct report	*rn;
+	struct dash	*dash = NULL, *curdash;
+	size_t		 i, dashsz = 0;
+	struct tm	 tm;
+	char		*urlproj, *urlcommit;
+	char		 datebuf[32], commitshort[8];
+
+	/* Open output page. */
+
+	http_open(r, KHTTP_200, r->mime, mtime);
+	req.r = r;
+	khtml_open(&req.html, r, 0);
+	html_open(&req.html, "Reports");
+
+	/* Output header. */
+
+	khtml_elem(&req.html, KELEM_HEADER);
+	khtml_attr(&req.html, KELEM_H1, 
+		KATTR_CLASS, "table", KATTR__MAX);
+
+	khtml_elem(&req.html, KELEM_SPAN);
+	khtml_puts(&req.html, "CI Dashboard");
+	khtml_closeelem(&req.html, 1); /* span */
+	khtml_ncr(&req.html, 0x203a);
+	khtml_elem(&req.html, KELEM_SPAN);
+	khtml_puts(&req.html, "All Projects");
+	khtml_closeelem(&req.html, 1); /* span */
+	khtml_closeelem(&req.html, 1); /* h1 */
+	khtml_closeelem(&req.html, 1); /* header */
+
+	/* Output data. */
+
+	khtml_attr(&req.html, KELEM_DIV, 
+		KATTR_CLASS, "table alltable", KATTR__MAX);
+
+	rq = db_report_list_dash(r->arg);
+
+	/* Establish the newest report hash. */
+
+	TAILQ_FOREACH(rn, rq, _entries) {
+		for (i = 0; i < dashsz; i++)
+			if (dash[i].proj->id == rn->projectid)
+				break;
+
+		if (i == dashsz) {
+			dash = kreallocarray(dash, 
+				dashsz + 1, sizeof(struct dash));
+			dashsz++;
+			curdash = &dash[i];
+			memset(curdash, 0, sizeof(struct dash));
+			curdash->proj = &rn->project;
+			curdash->nhash = rn->fetchhead;
+			curdash->nctime = rn->ctime;
+		} else
+			curdash = &dash[i];
+
+		if (rn->ctime > curdash->nctime) {
+			curdash->nhash = rn->fetchhead;
+			curdash->nctime = rn->ctime;
+		}
+	}
+
+	/* 
+	 * Compute how many have completed the newest hash.
+	 * The empty hash is always considered old.
+	 */
+
+	TAILQ_FOREACH(rn, rq, _entries) {
+		for (i = 0; i < dashsz; i++)
+			if (dash[i].proj->id == rn->projectid)
+				break;
+		assert(i < dashsz);
+		if (dash[i].nhash[0] != '\0' &&
+		    strcmp(rn->fetchhead, dash[i].nhash) == 0) {
+			dash[i].finished++;
+			dash[i].success += rn->distcheck != 0;
+		} else {
+			dash[i].pending++;
+		}
+	}
+
+	/* Header row. */
+
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"row", KATTR__MAX);
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"head report-successrate", KATTR__MAX);
+	khtml_closeelem(&req.html, 1); /* cell */
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"head project-name", KATTR__MAX);
+	khtml_closeelem(&req.html, 1); /* cell */
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"head report-finished-pct", KATTR__MAX);
+	khtml_closeelem(&req.html, 1); /* cell */
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"head report-pending", KATTR__MAX);
+	khtml_closeelem(&req.html, 1); /* cell */
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"head report-newest", KATTR__MAX);
+	khtml_closeelem(&req.html, 1); /* cell */
+	khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+		"head report-commit", KATTR__MAX);
+	khtml_closeelem(&req.html, 1); /* cell */
+	khtml_closeelem(&req.html, 1); /* row */
+
+	/* Now each project's data. */
+
+	for (i = 0; i < dashsz; i++) {
+		urlproj = kutil_urlpartx(NULL,
+			r->pname, 
+			ksuffixes[KMIME_TEXT_HTML],
+			pages[PAGE_INDEX],
+			valid_keys[VALID_PROJECT_NAME].name,
+			KATTRX_STRING, dash[i].proj->name, NULL);
+		kasprintf(&urlcommit, "%s/%s/tree/%s",
+			COMMIT_BASE, dash[i].proj->name,
+			dash[i].nhash);
+
+		assert(dash[i].finished + dash[i].pending > 0);
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"row", KATTR__MAX);
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"cell report-successrate", KATTR__MAX);
+		khtml_attr(&req.html, KELEM_SPAN, KATTR_CLASS, 
+			dash[i].success == dash[i].finished ?
+			"report-pass" : "report-fail",
+			KATTR__MAX);
+		khtml_int(&req.html,
+			dash[i].finished == 0 ? 0 : floor
+			(100 * dash[i].success / dash[i].finished));
+		khtml_closeelem(&req.html, 1); /* span */
+		khtml_closeelem(&req.html, 1); /* cell */
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"cell project-name", KATTR__MAX);
+		khtml_attr(&req.html, KELEM_A, KATTR_HREF, 
+			urlproj, KATTR__MAX);
+		khtml_puts(&req.html, dash[i].proj->name);
+		khtml_closeelem(&req.html, 1); /* a */
+		khtml_closeelem(&req.html, 1); /* cell */
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"cell report-finished-pct", KATTR__MAX);
+		khtml_int(&req.html, floor(100 * dash[i].finished / 
+		          (dash[i].finished + dash[i].pending)));
+		khtml_closeelem(&req.html, 1); /* cell */
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"cell report-pending", KATTR__MAX);
+		khtml_elem(&req.html, KELEM_SPAN);
+		khtml_int(&req.html, dash[i].finished);
+		khtml_closeelem(&req.html, 1); /* span */
+		khtml_elem(&req.html, KELEM_SPAN);
+		khtml_int(&req.html, dash[i].pending);
+		khtml_closeelem(&req.html, 1); /* span */
+		khtml_closeelem(&req.html, 1); /* cell */
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"cell report-newest", KATTR__MAX);
+		gmtime_r(&dash[i].nctime, &tm);
+		strftime(datebuf, sizeof(datebuf), "%F %T", &tm);
+		khtml_puts(&req.html, datebuf);
+		khtml_closeelem(&req.html, 1); /* cell */
+
+		khtml_attr(&req.html, KELEM_DIV, KATTR_CLASS, 
+			"cell report-commit", KATTR__MAX);
+		khtml_attr(&req.html, KELEM_A, KATTR_HREF, 
+			urlcommit, KATTR__MAX);
+		strlcpy(commitshort, dash[i].nhash, sizeof(commitshort));
+		khtml_puts(&req.html, commitshort);
+		khtml_closeelem(&req.html, 1); /* a */
+		khtml_closeelem(&req.html, 1); /* cell */
+
+		khtml_closeelem(&req.html, 1); /* row */
+		free(urlproj);
+		free(urlcommit);
+	}
+
+	khtml_closeelem(&req.html, 1); /* table */
+	khtml_closeelem(&req.html, 1); /* body */
+	khtml_closeelem(&req.html, 1); /* html */
+	khtml_close(&req.html);
+
+	db_report_freeq(rq);
+	free(dash);
+}
+
 /*
  * List the last *n* records, sorted by time of accept.
  * Always outputs HTTP 200.

@@ -515,12 +749,15 @@ get_last(struct kreq *r, time_t mtime)
 {
 	struct req	 req;
 	struct kpair	*kpn, *kpd;
-
-	/* Both of these are optional. */
+	time_t		 t;
+	struct tm	 tm;
+	char		 datebuf[32];
 
 	kpn = r->fieldmap[VALID_PROJECT_NAME];
 	kpd = r->fieldmap[VALID_REPORT_CTIME];
 
+	assert(kpn != NULL || kpd != NULL);
+
 	/* Open output page. */
 
 	http_open(r, KHTTP_200, r->mime, mtime);

@@ -548,7 +785,7 @@ get_last(struct kreq *r, time_t mtime)
 		khtml_puts(&req.html, kpn->parsed.s);
 		khtml_closeelem(&req.html, 1); /* span */
 		khtml_closeelem(&req.html, 1); /* h1 */
-	} else if (kpd != NULL) {
+	} else {
 		khtml_attr(&req.html, KELEM_A,
 			KATTR_HREF, "index.html", KATTR__MAX);
 		khtml_puts(&req.html, "CI Dashboard");

@@ -557,15 +794,14 @@ get_last(struct kreq *r, time_t mtime)
 		khtml_elem(&req.html, KELEM_SPAN);
 		khtml_puts(&req.html, "Date Reports");
 		khtml_closeelem(&req.html, 1); /* span */
-		khtml_closeelem(&req.html, 1); /* h1 */
-	} else {
-		khtml_elem(&req.html, KELEM_SPAN);
-		khtml_puts(&req.html, "CI Dashboard");
-		khtml_closeelem(&req.html, 1); /* span */
 		khtml_ncr(&req.html, 0x203a);
 		khtml_elem(&req.html, KELEM_SPAN);
-		khtml_puts(&req.html, "All Projects");
+		t = kpd->parsed.i;
+		gmtime_r(&t, &tm);
+		strftime(datebuf, sizeof(datebuf), "%F", &tm);
+		khtml_puts(&req.html, datebuf);
 		khtml_closeelem(&req.html, 1); /* span */
+		khtml_closeelem(&req.html, 1); /* h1 */
 	}
 
 	khtml_closeelem(&req.html, 1); /* h1 */

@@ -573,22 +809,23 @@ get_last(struct kreq *r, time_t mtime)
 
 	/* Output data. */
 
-	khtml_attr(&req.html, KELEM_DIV, 
-		KATTR_CLASS, "table", KATTR__MAX);
+	if (kpn != NULL)
+		khtml_attr(&req.html, KELEM_DIV, 
+			KATTR_CLASS, "table projtable", KATTR__MAX);
+	else
+		khtml_attr(&req.html, KELEM_DIV, 
+			KATTR_CLASS, "table datetable", KATTR__MAX);
 	get_html_last_header(&req.html);
 
 	if (kpn != NULL)
 		db_report_iterate_dashname(r->arg, 
 			get_html_last_report, &req,
 			kpn->parsed.s); /* project.name */
-	else if (kpd != NULL)
+	else 
 		db_report_iterate_lastdate(r->arg, 
 			get_html_last_report, &req,
 			kpd->parsed.i, /* ctime ge */
 			kpd->parsed.i + 86400); /* ctime le */
-	else
-		db_report_iterate_dash(r->arg, 
-			get_html_last_report, &req);
 
 	khtml_closeelem(&req.html, 1); /* table */
 	khtml_closeelem(&req.html, 1); /* body */

@@ -605,8 +842,12 @@ get(struct kreq *r, time_t mtime)
 
 	if (r->fieldmap[VALID_REPORT_ID] != NULL)
 		get_single(r, mtime);
-	else
+	else if (r->fieldmap[VALID_PROJECT_NAME] != NULL)
+		get_last(r, mtime);
+	else if (r->fieldmap[VALID_REPORT_CTIME] != NULL)
 		get_last(r, mtime);
+	else
+		get_dash(r, mtime);
 }
 
 /*
diff --git a/minci.css b/minci.css
@@ -38,32 +38,45 @@ div.table > :first-child		{ display: none;
 .lefthead.report-id,
 .lefthead.project-name,
 .lefthead.project-repo,
-.cell.report-id,
-.cell.report-passfail,
-.cell.project-name			{ display: inline-block; }
-.cell.report-system			{ white-space: nowrap;
-					  overflow: hidden;
-					  text-overflow: ellipsis; }
-.cell.report-system			{ display: inline; }
+.row					{ padding: 0.5rem;
+					  white-space: nowrap; 
+					  text-overflow: hidden;
+				  	  overflow: hidden; }
+.cell					{ padding: 0.25rem 0; }
+.head, .cell				{ display: inline-block;
+					  width: 4rem; }
+.cell + .cellgroup,
+.cellgroup + .cell,
+.head + .head, 
+.cell + .cell				{ padding-left: 0.5rem; }
+.head.report-newest,
+.cell.report-newest			{ width: 11rem; }
+.head.report-commit,
+.cell.report-commit			{ width: 6rem; }
+.head.project-name,
+.cell.project-name			{ width: 7rem; }
+.head.report-successrate,
+.cell.report-successrate		{ width: 3rem;	
+	  				  text-align: right; }
+.head.report-passfail,
+.cell.report-passfail			{ width: 0.5rem; }
+.head.report-finished-pct,
+.cell.report-finished-pct		{ text-align: right; }
+.head.report-start,
+.cell.report-start			{ width: 6rem; }
 .lefthead.project-name			{ border-right: thin solid #888;
 					  padding-right: 0.5rem;
 					  margin-right: 0.5rem; }
+.cell.report-commit			{ font-family: monospace;
+					  font-size: 8pt; }
 .lefthead.project-repo::before		{ content: 'repository'; }
 .lefthead.report-id::after,
-.cell.report-start::after,
-.cell.project-name::after,
-.cell.report-id::after			{ content: ', ';
-					  opacity: 0.5;
-					  margin-right: 0.2rem; }
-.lefthead.report-id::before,
-.cell.report-id::before			{ content: '#';
+.cell.report-successrate::after,
+.cell.report-finished-pct::after	{ content: '%';
 					  opacity: 0.5; }
-.row					{ padding: 0.5rem;
-					  white-space: nowrap; 
-				  	  overflow: hidden; 
-				  	  text-overflow: ellipsis; }
-.cell					{ padding: 0.25rem 0; }
-.cell.report-start,
+.report-id::before			{ content: '#';
+					  opacity: 0.5; }
+.report-start,
 .cellgroup				{ display: none; }
 .cellgroup .cell			{ flex: 1; }
 .cellgroup .cell::before		{ display: block;

@@ -85,6 +98,7 @@ div.table > :first-child		{ display: none;
 					  margin: 0.5rem 0;
 					  font-size: 8pt;
 					  text-overflow: ellipsis; }
+.lefthead.report-system-ext		{ opacity: 0.7; }
 .lefthead.report-env::before		{ content: 'Env: '; }
 .lefthead.report-deps::before		{ content: 'Deps: '; }
 .lefthead.report-build::before		{ content: 'Build: '; }

@@ -97,6 +111,9 @@ div.table > :first-child		{ display: none;
 					  text-align: right;
 					  display: inline-block;
 					  padding-right: 0.25rem; }
+.report-pending				{ text-align: center; }
+.report-pending > :first-child::after	{ content: ':';
+					  opacity: 0.5; }
 .report-failure::before			{ content: 'Report failure.';
 					  color: red; }
 .report-success::before			{ content: 'Report success.';

@@ -112,21 +129,12 @@ div.table > :first-child		{ display: none;
   div.table > :first-child,
   .row					{ display: flex;
 	  			  	  padding: 0; }
-  .head, .cell				{ width: 4rem;
-					  padding: 0.5rem 1rem; }
-  .head.report-passfail,
-  .cell.report-passfail			{ width: 0.5rem; }
-  .head.project-name,
-  .cell.project-name			{ width: 8rem; }
-  .head.report-start,
-  .cell.report-start			{ width: 6rem; }
-  .cell.report-start			{ display: inline-block; }
+  .head, .cell				{ padding: 0.5rem 1rem; }
+  .report-start				{ display: inline-block; }
   .report-system			{ flex: 1; }
-  .cell.report-start::after,
-  .cell.project-name::after,
-  .cell.report-id::after		{ content: none;
-					  margin-right: 0; }
   .head.project-name::before		{ content: 'project'; }
+  .head.report-finished-pct::before	{ content: 'fresh'; }
+  .head.report-pending::before		{ content: 'wait'; }
   .head.report-start::before		{ content: 'date'; }
   .head.report-env::before		{ content: 'env'; }
   .head.report-deps::before		{ content: 'deps'; }

@@ -134,7 +142,9 @@ div.table > :first-child		{ display: none;
   .head.report-regress::before		{ content: 'test'; }
   .head.report-install::before		{ content: 'install'; }
   .head.report-dist::before		{ content: 'check'; }
+  .head.report-commit::before		{ content: 'commit'; }
   .head.report-system::before		{ content: 'system'; }
+  .head.report-newest::before		{ content: 'latest (GMT)'; }
   .cellgroup				{ display: flex; }
 }
 

@@ -151,3 +161,6 @@ div.table > :first-child		{ display: none;
   .cellgroup .cell span::after		{ color: rgb(255, 50, 50); }
   .report-log				{ background-color: #000; }
 }
+
+.projtable .project-name		{ display: none; }
+.datetable .report-start		{ display: none; }