about summary refs log tree commit diff
path: root/third_party/gerrit-queue
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2021-12-14T16·23+0100
committerclbot <clbot@tvl.fyi>2021-12-14T17·14+0000
commitb3c4057f4bcb770785ba7147e40aa98e38171d08 (patch)
tree180fb293e2bb925bce3753f6c36cbb1f3d21d8f0 /third_party/gerrit-queue
parentb68f7eebb9763c0ea8f135f72026bfb787b78c6c (diff)
refactor(3p/gerrit-queue): use go:embed, bump go1.16, drop shell.nix r/3243
Previously, gerrit-queue used statik to embed files. Since go1.16, we
have go:embed, which solves this much nicer, without any requirements to
have the statik binary around.

As the only other thing the shell.nix and .envrc plumbing did was bring
a version of Go in scope, it's dropped now. We assume to have a
recent-enough go binary around, else go will complain.

Imported from https://github.com/flokli/gerrit-queue/pull/9

Change-Id: I851b06777a29d4f2d955cf3a7db6455a7189bc46
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4329
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Autosubmit: tazjin <mail@tazj.in>
Diffstat (limited to 'third_party/gerrit-queue')
-rw-r--r--third_party/gerrit-queue/.envrc17
-rw-r--r--third_party/gerrit-queue/default.nix8
-rw-r--r--third_party/gerrit-queue/frontend/frontend.go18
-rw-r--r--third_party/gerrit-queue/frontend/templates/changeset.tmpl.html (renamed from third_party/gerrit-queue/public/changeset.tmpl.html)0
-rw-r--r--third_party/gerrit-queue/frontend/templates/index.tmpl.html (renamed from third_party/gerrit-queue/public/index.tmpl.html)0
-rw-r--r--third_party/gerrit-queue/frontend/templates/serie.tmpl.html (renamed from third_party/gerrit-queue/public/serie.tmpl.html)0
-rw-r--r--third_party/gerrit-queue/go.mod3
-rw-r--r--third_party/gerrit-queue/go.sum2
-rw-r--r--third_party/gerrit-queue/main.go2
-rw-r--r--third_party/gerrit-queue/shell.nix12
10 files changed, 10 insertions, 52 deletions
diff --git a/third_party/gerrit-queue/.envrc b/third_party/gerrit-queue/.envrc
deleted file mode 100644
index 90cf1bb145..0000000000
--- a/third_party/gerrit-queue/.envrc
+++ /dev/null
@@ -1,17 +0,0 @@
-# This configures [direnv](https://direnv.net/) if installed and enabled to
-# automatically enter the nix-shell defined in `shell.nix`,
-# either by using lorri if available, or nix-shell otherwise.
-
-if type lorri &>/dev/null; then
-    eval "$(lorri direnv)"
-else
-    # fall back to using direnv's builtin nix support (blocking)
-    use nix
-fi
-
-# enable go modules
-export GO111MODULE=on
-unset GOPATH
-
-# Load private overrides
-[[ -f .envrc.private ]] && source_env .envrc.private
diff --git a/third_party/gerrit-queue/default.nix b/third_party/gerrit-queue/default.nix
index 468d5b9b54..427e312183 100644
--- a/third_party/gerrit-queue/default.nix
+++ b/third_party/gerrit-queue/default.nix
@@ -3,15 +3,9 @@
 pkgs.buildGoModule {
   pname = "gerrit-queue";
   version = "master";
-  vendorSha256 = "1bqllafvd4yy4cy6barpqhycxmhzcx3p5shpzhd8qwxwwg0clxs6";
+  vendorSha256 = "0n5h7j416yb2mwic9c3rhqza64jlvl7iw507r9mkw3jadn4whm7a";
   src = ./.;
 
-  # gerrit-queue embeds static assets which need to be generated
-  nativeBuildInputs = [ pkgs.statik ];
-  preBuild = ''
-    statik -f
-  '';
-
   meta = with lib; {
     description = "Gerrit submit bot";
     homepage = "https://github.com/tweag/gerrit-queue";
diff --git a/third_party/gerrit-queue/frontend/frontend.go b/third_party/gerrit-queue/frontend/frontend.go
index f00bc414a1..2cc65423f0 100644
--- a/third_party/gerrit-queue/frontend/frontend.go
+++ b/third_party/gerrit-queue/frontend/frontend.go
@@ -1,36 +1,34 @@
 package frontend
 
 import (
+	"embed"
+	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"net/http"
-	"encoding/json"
 
 	"html/template"
 
-	"github.com/rakyll/statik/fs"
-
 	"github.com/apex/log"
 
 	"github.com/tweag/gerrit-queue/gerrit"
 	"github.com/tweag/gerrit-queue/misc"
-	_ "github.com/tweag/gerrit-queue/statik" // register static assets
 	"github.com/tweag/gerrit-queue/submitqueue"
 )
 
-//loadTemplate loads a list of templates, relative to the statikFS root, and a FuncMap, and returns a template object
+//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)
-	statikFS, err := fs.New()
-	if err != nil {
-		return nil, err
-	}
 
 	for _, templateName := range templateNames {
-		r, err := statikFS.Open("/" + templateName)
+		r, err := templates.Open("/" + templateName)
 		if err != nil {
 			return nil, err
 		}
diff --git a/third_party/gerrit-queue/public/changeset.tmpl.html b/third_party/gerrit-queue/frontend/templates/changeset.tmpl.html
index 5d3997885c..5d3997885c 100644
--- a/third_party/gerrit-queue/public/changeset.tmpl.html
+++ b/third_party/gerrit-queue/frontend/templates/changeset.tmpl.html
diff --git a/third_party/gerrit-queue/public/index.tmpl.html b/third_party/gerrit-queue/frontend/templates/index.tmpl.html
index e04c0a349d..e04c0a349d 100644
--- a/third_party/gerrit-queue/public/index.tmpl.html
+++ b/third_party/gerrit-queue/frontend/templates/index.tmpl.html
diff --git a/third_party/gerrit-queue/public/serie.tmpl.html b/third_party/gerrit-queue/frontend/templates/serie.tmpl.html
index 60f0c18113..60f0c18113 100644
--- a/third_party/gerrit-queue/public/serie.tmpl.html
+++ b/third_party/gerrit-queue/frontend/templates/serie.tmpl.html
diff --git a/third_party/gerrit-queue/go.mod b/third_party/gerrit-queue/go.mod
index 0360ad21b2..3929f8cf65 100644
--- a/third_party/gerrit-queue/go.mod
+++ b/third_party/gerrit-queue/go.mod
@@ -1,11 +1,10 @@
 module github.com/tweag/gerrit-queue
 
-go 1.12
+go 1.16
 
 require (
 	github.com/andygrunwald/go-gerrit v0.0.0-20190825170856-5959a9bf9ff8
 	github.com/apex/log v1.1.1
 	github.com/google/go-querystring v1.0.0 // indirect
-	github.com/rakyll/statik v0.1.6
 	github.com/urfave/cli v1.22.1
 )
diff --git a/third_party/gerrit-queue/go.sum b/third_party/gerrit-queue/go.sum
index d4a50d4873..d11545a6c9 100644
--- a/third_party/gerrit-queue/go.sum
+++ b/third_party/gerrit-queue/go.sum
@@ -33,8 +33,6 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs=
-github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
 github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
diff --git a/third_party/gerrit-queue/main.go b/third_party/gerrit-queue/main.go
index d8577dad50..eaa792c958 100644
--- a/third_party/gerrit-queue/main.go
+++ b/third_party/gerrit-queue/main.go
@@ -1,5 +1,3 @@
-//go:generate statik -f
-
 package main
 
 import (
diff --git a/third_party/gerrit-queue/shell.nix b/third_party/gerrit-queue/shell.nix
deleted file mode 100644
index 7a2d65d596..0000000000
--- a/third_party/gerrit-queue/shell.nix
+++ /dev/null
@@ -1,12 +0,0 @@
-let
-  pkgs = (import (builtins.fetchTarball {
-    url = "https://github.com/NixOS/nixpkgs/archive/5de728659b412bcf7d18316a4b71d9a6e447f460.tar.gz";
-    sha256 = "1bdykda8k8gl2vcp36g27xf3437ig098yrhjp0hclv7sn6dp2w1l";
-  })) {};
-in
-  pkgs.mkShell {
-    buildInputs = [
-      pkgs.go_1_12
-      pkgs.statik
-    ];
-  }