: nply/minci

commit 1f885f660e000ef923554b4838fa636be4e2839c
parent 74af646331e34f59b2c4fba9c5ec9ddc2bfce55b
Author: kristapsdz <kristaps@bsd.lv>
Date: Thu, 19 Mar 2020 13:55:54 +0000

Make the web interface more usable.
4 files changed, 102 insertions(+), 27 deletions(-)
M
Makefile
|
2
+-
M
db.ort
|
12
+++++++++---
M
main.c
|
95
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
M
minci.css
|
20
++++++++++----------
diff --git a/Makefile b/Makefile
@@ -26,7 +26,7 @@ updatecgi: all
 	install -o www -m 0500 minci.cgi $(WWWPREFIX)/cgi-bin
 
 testupdatedb:
-	ort-sqldiff $(PREFIX)/data/minci.ort db.ort || true
+	ort-sqldiff $(WWWPREFIX)/data/minci.ort db.ort || true
 
 updatedb:
 	mkdir -p $(WWWPREFIX)/data
diff --git a/db.ort b/db.ort
@@ -100,6 +100,10 @@ struct report {
 	field unamehash text limit eq 32
 		comment "Hash of uname[mnrsv].  This is used to quickly
 			 establish a kind of machine identity.";
+	field projunamehash text limit eq 32 default ""
+		comment "Hash of uname[mnrsv] and project identifier.  This is
+			 used to group recent submissions from a given machine
+			 for a given project.";
 	field fetchhead text limit le 40 default ""
 		comment "Git hash for branch master.  May be empty.";
 			 

@@ -109,16 +113,18 @@ struct report {
 	insert;
 
 	iterate ctime ge, ctime le: limit 50 name lastdate order ctime desc;
+	iterate project.name: name dashname order ctime desc grouprow projunamehash maxrow ctime;
+	iterate unamehash: name dashuname order ctime desc grouprow projunamehash 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;
+	list: name dash order projectid,ctime desc grouprow projunamehash maxrow ctime;
 
 	search id: name byid;
 
 	roles consumer {
 		list dash;
-		iterate lastdate;
 		iterate dashname;
+		iterate dashuname;
+		iterate lastdate;
 		noexport userid;
 		search byid;
 	};
diff --git a/main.c b/main.c
@@ -217,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, *urlcommit;
+	char		*urlid, *urlproj, *urldate, *urlcommit, 
+			*urluname;
 	char		 commitshort[8];
 
 	memset(&tm, 0, sizeof(struct tm));

@@ -246,6 +247,12 @@ get_html_last_report(const struct report *p, void *arg)
 	kasprintf(&urlcommit, "%s/%s/tree/%s",
 		COMMIT_BASE, p->project.name,
 		p->fetchhead);
+	urluname = kutil_urlpart(NULL,
+		r->r->pname,
+		ksuffixes[KMIME_TEXT_HTML],
+		pages[PAGE_INDEX],
+		valid_keys[VALID_REPORT_UNAMEHASH].name,
+		p->unamehash, NULL);
 
 	memset(&tm, 0, sizeof(struct tm));
 	KUTIL_EPOCH2TM(p->start, &tm);

@@ -314,7 +321,10 @@ get_html_last_report(const struct report *p, void *arg)
 
 	khtml_attr(&r->html, KELEM_DIV, KATTR_CLASS, 
 		"cell report-system", KATTR__MAX);
+	khtml_attr(&r->html, KELEM_A, 
+		KATTR_HREF, urluname, KATTR__MAX);
 	get_html_uname(&r->html, p);
+	khtml_closeelem(&r->html, 1); /* a */
 	khtml_closeelem(&r->html, 1); /* cell */
 
 	khtml_attr(&r->html, KELEM_DIV,

@@ -338,6 +348,7 @@ get_html_last_report(const struct report *p, void *arg)
 	free(urlproj);
 	free(urldate);
 	free(urlcommit);
+	free(urluname);
 }
 
 /*

@@ -358,7 +369,8 @@ get_single_html(struct kreq *r, const struct report *p)
 {
 	struct khtmlreq	 req;
 	char		 buf[64];
-	char		*url = NULL, *repo = NULL, *urlproj;
+	char		 commitshort[8];
+	char		*url = NULL, *urlcommit, *urlproj, *urluname;
 	const char	*cp;
 	size_t		 count;
 

@@ -368,8 +380,15 @@ get_single_html(struct kreq *r, const struct report *p)
 		pages[PAGE_INDEX],
 		valid_keys[VALID_PROJECT_NAME].name,
 		KATTRX_STRING, p->project.name, NULL);
-	kasprintf(&repo, "%s/%s",
-		REPO_BASE, p->project.name);
+	kasprintf(&urlcommit, "%s/%s/tree/%s",
+		COMMIT_BASE, p->project.name,
+		p->fetchhead);
+	urluname = kutil_urlpart(NULL,
+		r->pname,
+		ksuffixes[KMIME_TEXT_HTML],
+		pages[PAGE_INDEX],
+		valid_keys[VALID_REPORT_UNAMEHASH].name,
+		p->unamehash, NULL);
 
 	khtml_open(&req, r, 0);
 	html_open(&req, "Report");

@@ -387,6 +406,17 @@ get_single_html(struct kreq *r, const struct report *p)
 	khtml_elem(&req, KELEM_SPAN);
 	khtml_puts(&req, "Reports");
 	khtml_closeelem(&req, 1); /* span */
+	khtml_ncr(&req, 0x203a);
+	khtml_attr(&req, KELEM_SPAN,
+		KATTR_CLASS, "report-id", KATTR__MAX);
+	if (p->id < 1000)
+		khtml_int(&req, 0);
+	if (p->id < 100)
+		khtml_int(&req, 0);
+	if (p->id < 10)
+		khtml_int(&req, 0);
+	khtml_int(&req, p->id);
+	khtml_closeelem(&req, 1); /* span */
 	khtml_closeelem(&req, 1); /* h1 */
 	khtml_closeelem(&req, 1); /* header */
 

@@ -394,7 +424,7 @@ get_single_html(struct kreq *r, const struct report *p)
 
 	khtml_attr(&req, KELEM_DIV,
 		KATTR_CLASS, "singleton", KATTR__MAX);
-	khtml_attr(&req, KELEM_DIV, KATTR_CLASS, 
+	khtml_attr(&req, KELEM_SPAN, KATTR_CLASS, 
 		"lefthead report-id", KATTR__MAX);
 	if (p->id < 1000)
 		khtml_int(&req, 0);

@@ -405,17 +435,22 @@ get_single_html(struct kreq *r, const struct report *p)
 	khtml_int(&req, p->id);
 	khtml_closeelem(&req, 1); /* div */
 
-	khtml_attr(&req, KELEM_DIV, KATTR_CLASS, 
+	khtml_attr(&req, KELEM_SPAN, KATTR_CLASS, 
 		"lefthead project-name", KATTR__MAX);
 	khtml_attr(&req, KELEM_A, KATTR_HREF, urlproj, KATTR__MAX);
 	khtml_puts(&req, p->project.name);
 	khtml_closeelem(&req, 1); /* a */
-	khtml_closeelem(&req, 1); /* div */
+	khtml_closeelem(&req, 1); /* span */
 
+	khtml_attr(&req, KELEM_SPAN, KATTR_CLASS, 
+		"lefthead project-repo", KATTR__MAX);
 	khtml_attr(&req, KELEM_A, KATTR_CLASS, 
-		"lefthead project-repo", 
-		KATTR_HREF, repo, KATTR__MAX);
-	khtml_closeelem(&req, 1); /* div */
+		"lefthead report-commit", 
+		KATTR_HREF, urlcommit, KATTR__MAX);
+	strlcpy(commitshort, p->fetchhead, sizeof(commitshort));
+	khtml_puts(&req, commitshort);
+	khtml_closeelem(&req, 1); /* a */
+	khtml_closeelem(&req, 1); /* span */
 
 	khtml_attr(&req, KELEM_DIV, KATTR_CLASS, 
 		"lefthead report-start", KATTR__MAX);

@@ -429,7 +464,10 @@ get_single_html(struct kreq *r, const struct report *p)
 
 	khtml_attr(&req, KELEM_DIV, KATTR_CLASS,
 		"lefthead report-system", KATTR__MAX);
+	khtml_attr(&req, KELEM_A, 
+		KATTR_HREF, urluname, KATTR__MAX);
 	get_html_uname(&req, p);
+	khtml_closeelem(&req, 1); /* a */
 	khtml_closeelem(&req, 1); /* div */
 
 	khtml_attr(&req, KELEM_DIV, KATTR_CLASS,

@@ -498,7 +536,8 @@ get_single_html(struct kreq *r, const struct report *p)
 	khtml_close(&req);
 	free(url);
 	free(urlproj);
-	free(repo);
+	free(urluname);
+	free(urlcommit);
 }
 
 /*

@@ -748,15 +787,16 @@ static void
 get_last(struct kreq *r, time_t mtime)
 {
 	struct req	 req;
-	struct kpair	*kpn, *kpd;
+	struct kpair	*kpn, *kpd, *kph;
 	time_t		 t;
 	struct tm	 tm;
 	char		 datebuf[32];
 
 	kpn = r->fieldmap[VALID_PROJECT_NAME];
 	kpd = r->fieldmap[VALID_REPORT_CTIME];
+	kph = r->fieldmap[VALID_REPORT_UNAMEHASH];
 
-	assert(kpn != NULL || kpd != NULL);
+	assert(kpn != NULL || kpd != NULL || kph != NULL);
 
 	/* Open output page. */
 

@@ -785,6 +825,16 @@ 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 (kph != NULL) {
+		khtml_attr(&req.html, KELEM_A,
+			KATTR_HREF, "index.html", KATTR__MAX);
+		khtml_puts(&req.html, "CI Dashboard");
+		khtml_closeelem(&req.html, 1); /* a */
+		khtml_ncr(&req.html, 0x203a);
+		khtml_elem(&req.html, KELEM_SPAN);
+		khtml_puts(&req.html, "Machine Dashboard");
+		khtml_closeelem(&req.html, 1); /* span */
+		khtml_closeelem(&req.html, 1); /* h1 */
 	} else {
 		khtml_attr(&req.html, KELEM_A,
 			KATTR_HREF, "index.html", KATTR__MAX);

@@ -812,6 +862,9 @@ get_last(struct kreq *r, time_t mtime)
 	if (kpn != NULL)
 		khtml_attr(&req.html, KELEM_DIV, 
 			KATTR_CLASS, "table projtable", KATTR__MAX);
+	else if (kph != NULL)
+		khtml_attr(&req.html, KELEM_DIV, 
+			KATTR_CLASS, "table unametable", KATTR__MAX);
 	else
 		khtml_attr(&req.html, KELEM_DIV, 
 			KATTR_CLASS, "table datetable", KATTR__MAX);

@@ -821,6 +874,10 @@ get_last(struct kreq *r, time_t mtime)
 		db_report_iterate_dashname(r->arg, 
 			get_html_last_report, &req,
 			kpn->parsed.s); /* project.name */
+	else if (kph != NULL)
+		db_report_iterate_dashuname(r->arg, 
+			get_html_last_report, &req,
+			kph->parsed.s); /* report.unamehash */
 	else 
 		db_report_iterate_lastdate(r->arg, 
 			get_html_last_report, &req,

@@ -844,6 +901,8 @@ get(struct kreq *r, time_t mtime)
 		get_single(r, mtime);
 	else if (r->fieldmap[VALID_PROJECT_NAME] != NULL)
 		get_last(r, mtime);
+	else if (r->fieldmap[VALID_REPORT_UNAMEHASH] != NULL)
+		get_last(r, mtime);
 	else if (r->fieldmap[VALID_REPORT_CTIME] != NULL)
 		get_last(r, mtime);
 	else

@@ -871,6 +930,7 @@ post(struct kreq *r)
 	char		*buf = NULL;
 	char		 digest[MD5_DIGEST_STRING_LENGTH],
 			 unamedigest[MD5_DIGEST_STRING_LENGTH],
+			 projunamedigest[MD5_DIGEST_STRING_LENGTH],
 			 logdigest[MD5_DIGEST_STRING_LENGTH];
 
 	/* 

@@ -1047,6 +1107,14 @@ post(struct kreq *r)
 		kpus->parsed.s, kpuv->parsed.s);
 	MD5Init(&ctx);
 	MD5Update(&ctx, buf, sz);
+	MD5End(&ctx, projunamedigest);
+	free(buf);
+
+	sz = (size_t)kasprintf(&buf, "%s|%s|%s|%s|%s",
+		kpum->parsed.s, kpun->parsed.s, kpur->parsed.s, 
+		kpus->parsed.s, kpuv->parsed.s);
+	MD5Init(&ctx);
+	MD5Update(&ctx, buf, sz);
 	MD5End(&ctx, unamedigest);
 
 	/* Insert the record. */

@@ -1069,6 +1137,7 @@ post(struct kreq *r)
 		kpus->parsed.s, /* unames */
 		kpuv->parsed.s, /* unamev */
 		unamedigest, /* unamehash */
+		projunamedigest, /* projunamehash */
 		kpf->parsed.s); /* fetchhead */
 
 	kutil_info(r, user->email, "log submitted: %s", proj->name);
diff --git a/minci.css b/minci.css
@@ -35,9 +35,6 @@ div.table > :first-child		{ display: none;
 					  color: #fff; }
 .report-pass				{ color: green; }
 .report-fail				{ color: red; }
-.lefthead.report-id,
-.lefthead.project-name,
-.lefthead.project-repo,
 .row					{ padding: 0.5rem;
 					  white-space: nowrap; 
 					  text-overflow: hidden;

@@ -58,25 +55,24 @@ div.table > :first-child		{ display: none;
 .head.report-successrate,
 .cell.report-successrate		{ width: 3rem;	
 	  				  text-align: right; }
+.head.report-commit,
+.cell.report-commit			{ display: none; }
 .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; }
+.lefthead.report-commit,
 .cell.report-commit			{ font-family: monospace;
 					  font-size: 8pt; }
-.lefthead.project-repo::before		{ content: 'repository'; }
-.lefthead.report-id::after,
 .cell.report-successrate::after,
 .cell.report-finished-pct::after	{ content: '%';
 					  opacity: 0.5; }
+.lefthead.project-name::after,
+.lefthead.report-id::after		{ content: ','; }
 .report-id::before			{ content: '#';
 					  opacity: 0.5; }
-.report-start,
 .cellgroup				{ display: none; }
 .cellgroup .cell			{ flex: 1; }
 .cellgroup .cell::before		{ display: block;

@@ -99,6 +95,8 @@ div.table > :first-child		{ display: none;
 					  font-size: 8pt;
 					  text-overflow: ellipsis; }
 .lefthead.report-system-ext		{ opacity: 0.7; }
+.lefthead.project-name			{ padding: 0 0.3rem; }
+.lefthead.project-repo::before		{ content: 'commit:'; }
 .lefthead.report-env::before		{ content: 'Env: '; }
 .lefthead.report-deps::before		{ content: 'Deps: '; }
 .lefthead.report-build::before		{ content: 'Build: '; }

@@ -130,8 +128,9 @@ div.table > :first-child		{ display: none;
   .row					{ display: flex;
 	  			  	  padding: 0; }
   .head, .cell				{ padding: 0.5rem 1rem; }
-  .report-start				{ display: inline-block; }
   .report-system			{ flex: 1; }
+  .head.report-commit,
+  .cell.report-commit			{ display: inline-block; }
   .head.project-name::before		{ content: 'project'; }
   .head.report-finished-pct::before	{ content: 'fresh'; }
   .head.report-pending::before		{ content: 'wait'; }

@@ -163,4 +162,5 @@ div.table > :first-child		{ display: none;
 }
 
 .projtable .project-name		{ display: none; }
+.unametable .report-system		{ display: none; }
 .datetable .report-start		{ display: none; }