refactor(3p/gerrit-queue): use go:embed, bump go1.16, drop shell.nix
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>
This commit is contained in:
parent
b68f7eebb9
commit
b3c4057f4b
10 changed files with 10 additions and 52 deletions
17
third_party/gerrit-queue/.envrc
vendored
17
third_party/gerrit-queue/.envrc
vendored
|
@ -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
|
8
third_party/gerrit-queue/default.nix
vendored
8
third_party/gerrit-queue/default.nix
vendored
|
@ -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";
|
||||
|
|
18
third_party/gerrit-queue/frontend/frontend.go
vendored
18
third_party/gerrit-queue/frontend/frontend.go
vendored
|
@ -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
|
||||
}
|
||||
|
|
3
third_party/gerrit-queue/go.mod
vendored
3
third_party/gerrit-queue/go.mod
vendored
|
@ -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
|
||||
)
|
||||
|
|
2
third_party/gerrit-queue/go.sum
vendored
2
third_party/gerrit-queue/go.sum
vendored
|
@ -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=
|
||||
|
|
2
third_party/gerrit-queue/main.go
vendored
2
third_party/gerrit-queue/main.go
vendored
|
@ -1,5 +1,3 @@
|
|||
//go:generate statik -f
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
12
third_party/gerrit-queue/shell.nix
vendored
12
third_party/gerrit-queue/shell.nix
vendored
|
@ -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
|
||||
];
|
||||
}
|
Loading…
Reference in a new issue