about summary refs log tree commit diff
path: root/third_party/gerrit-queue/frontend/frontend.go
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-20T12·18+0100
committerflokli <flokli@flokli.de>2023-10-30T09·07+0000
commit9a1e5cf4c731c082032285e9b02e453fd0d11483 (patch)
tree7c6a265f3ee80146275a621154196d1f31fa170a /third_party/gerrit-queue/frontend/frontend.go
parent2513ddd2b7559628a0135ec0c8e4e8ea4444af8d (diff)
chore(third_party/gerrit-queue): move to tvl overlay r/6906
Bump to a version including https://github.com/flokli/gerrit-queue/pull/15

Change-Id: Ie316498ca2c608e5489901c5705ce5f2dc047f29
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9808
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'third_party/gerrit-queue/frontend/frontend.go')
-rw-r--r--third_party/gerrit-queue/frontend/frontend.go113
1 files changed, 0 insertions, 113 deletions
diff --git a/third_party/gerrit-queue/frontend/frontend.go b/third_party/gerrit-queue/frontend/frontend.go
deleted file mode 100644
index 2cc65423f0e6..000000000000
--- a/third_party/gerrit-queue/frontend/frontend.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package frontend
-
-import (
-	"embed"
-	"encoding/json"
-	"fmt"
-	"io/ioutil"
-	"net/http"
-
-	"html/template"
-
-	"github.com/apex/log"
-
-	"github.com/tweag/gerrit-queue/gerrit"
-	"github.com/tweag/gerrit-queue/misc"
-	"github.com/tweag/gerrit-queue/submitqueue"
-)
-
-//go:embed templates
-var templates embed.FS
-
-//loadTemplate loads a list of templates, relative to the templates root, and a
-//FuncMap, and returns a template object
-func loadTemplate(templateNames []string, funcMap template.FuncMap) (*template.Template, error) {
-	if len(templateNames) == 0 {
-		return nil, fmt.Errorf("templateNames can't be empty")
-	}
-	tmpl := template.New(templateNames[0]).Funcs(funcMap)
-
-	for _, templateName := range templateNames {
-		r, err := templates.Open("/" + templateName)
-		if err != nil {
-			return nil, err
-		}
-		defer r.Close()
-		contents, err := ioutil.ReadAll(r)
-		if err != nil {
-			return nil, err
-		}
-		tmpl, err = tmpl.Parse(string(contents))
-		if err != nil {
-			return nil, err
-		}
-	}
-
-	return tmpl, nil
-}
-
-// MakeFrontend returns a http.Handler
-func MakeFrontend(rotatingLogHandler *misc.RotatingLogHandler, gerritClient *gerrit.Client, runner *submitqueue.Runner) http.Handler {
-	projectName := gerritClient.GetProjectName()
-	branchName := gerritClient.GetBranchName()
-
-	mux := http.NewServeMux()
-	mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
-		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{
-			"changesetURL": func(changeset *gerrit.Changeset) string {
-				return gerritClient.GetChangesetURL(changeset)
-			},
-			"levelToClasses": func(level log.Level) string {
-				switch level {
-				case log.DebugLevel:
-					return "text-muted"
-				case log.InfoLevel:
-					return "text-info"
-				case log.WarnLevel:
-					return "text-warning"
-				case log.ErrorLevel:
-					return "text-danger"
-				case log.FatalLevel:
-					return "text-danger"
-				default:
-					return "text-white"
-				}
-			},
-			"fieldsToJSON": func(fields log.Fields) string {
-				jsonData, _ := json.Marshal(fields)
-				return string(jsonData)
-			},
-		}
-
-		tmpl := template.Must(loadTemplate([]string{
-			"index.tmpl.html",
-			"serie.tmpl.html",
-			"changeset.tmpl.html",
-		}, funcMap))
-
-		tmpl.ExecuteTemplate(w, "index.tmpl.html", map[string]interface{}{
-			// Config
-			"projectName": projectName,
-			"branchName":  branchName,
-
-			// State
-			"currentlyRunning": currentlyRunning,
-			"wipSerie":         wipSerie,
-			"HEAD":             HEAD,
-
-			// History
-			"memory": rotatingLogHandler,
-		})
-	})
-	return mux
-}