about summary refs log tree commit diff
path: root/frontend
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2019-12-02T09·00+0100
committerFlorian Klink <flokli@flokli.de>2019-12-02T09·00+0100
commit04a24a0c601c28d01e1110fb82f57c7a7c3f5d74 (patch)
treeabe8872d565a82db38167b07b0a4526883031983 /frontend
parent7bafef7a848cc80c79551441630210e947b2481b (diff)
Use Runner
This revamps code quite a bit. Series handling has been moved into the
gerrit client, it also handles caching.

The Runner logic itself has been greatly simplified.

The runner logic has been moved into the runner.go, submitqueue.go is
gone.

The "per-run result object" concept has been dropped - we instead just
use annotated logs.

Also, we switched to apex/log
Diffstat (limited to 'frontend')
-rw-r--r--frontend/frontend.go40
1 files changed, 21 insertions, 19 deletions
diff --git a/frontend/frontend.go b/frontend/frontend.go
index eef246ea380a..abb5a3db4f70 100644
--- a/frontend/frontend.go
+++ b/frontend/frontend.go
@@ -13,9 +13,9 @@ import (
 	"github.com/tweag/gerrit-queue/gerrit"
 	_ "github.com/tweag/gerrit-queue/statik" // register static assets
 	"github.com/tweag/gerrit-queue/submitqueue"
-)
 
-//TODO: log last update
+	"github.com/apex/log/handlers/memory"
+)
 
 //loadTemplate loads a list of templates, relative to the statikFS root, and a FuncMap, and returns a template object
 func loadTemplate(templateNames []string, funcMap template.FuncMap) (*template.Template, error) {
@@ -47,46 +47,48 @@ func loadTemplate(templateNames []string, funcMap template.FuncMap) (*template.T
 	return tmpl, nil
 }
 
-// MakeFrontend configures the router and returns a new Frontend struct
-func MakeFrontend(runner *submitqueue.Runner) http.Handler {
+// MakeFrontend returns a http.Handler
+func MakeFrontend(memoryHandler *memory.Handler, gerritClient *gerrit.Client, runner *submitqueue.Runner) http.Handler {
 	router := gin.Default()
 
-	router.GET("/submit-queue.json", func(c *gin.Context) {
-		submitQueue, _, _ := runner.GetState()
-		c.JSON(http.StatusOK, submitQueue)
-	})
+	projectName := gerritClient.GetProjectName()
+	branchName := gerritClient.GetBranchName()
 
 	router.GET("/", func(c *gin.Context) {
-		submitQueue, currentlyRunning, results := runner.GetState()
+		var wipSerie *gerrit.Serie = nil
+		HEAD := ""
+		currentlyRunning := runner.IsCurrentlyRunning()
+
+		// don't trigger operations requiring a lock
+		if !currentlyRunning {
+			wipSerie = runner.GetWIPSerie()
+			HEAD = gerritClient.GetHEAD()
+		}
 
 		funcMap := template.FuncMap{
-			"isAutoSubmittable": func(serie *submitqueue.Serie) bool {
-				return submitQueue.IsAutoSubmittable(serie)
-			},
 			"changesetURL": func(changeset *gerrit.Changeset) string {
-				return submitQueue.GetChangesetURL(changeset)
+				return gerritClient.GetChangesetURL(changeset)
 			},
 		}
 
 		tmpl := template.Must(loadTemplate([]string{
 			"submit-queue.tmpl.html",
-			"series.tmpl.html",
 			"serie.tmpl.html",
 			"changeset.tmpl.html",
 		}, funcMap))
 
 		tmpl.ExecuteTemplate(c.Writer, "submit-queue.tmpl.html", gin.H{
 			// Config
-			"projectName": submitQueue.ProjectName,
-			"branchName":  submitQueue.BranchName,
+			"projectName": projectName,
+			"branchName":  branchName,
 
 			// State
 			"currentlyRunning": currentlyRunning,
-			"series":           submitQueue.Series,
-			"HEAD":             submitQueue.HEAD,
+			"wipSerie":         wipSerie,
+			"HEAD":             HEAD,
 
 			// History
-			"results": results,
+			"memory": memoryHandler,
 		})
 	})
 	return router