Skip to content

Commit fcd43e8

Browse files
flokliclbot
authored andcommitted
refactor(ops/gerrit-webhook-to-irccat): use streams data types
The types are different for `gerrit stream-events` and webhooks, so switch to a fork of go-gerrit containing their definitions. andygrunwald/go-gerrit#189 is the upstream PR. Change-Id: I24136af2f2cf5655f2a8278632a3b0f52aa6adcc Reviewed-on: https://cl.snix.dev/c/snix/+/30544 Autosubmit: Florian Klink <flokli@flokli.de> Tested-by: besadii Reviewed-by: Ilan Joselevich <personal@ilanjoselevich.com>
1 parent abb2daa commit fcd43e8

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

ops/gerrit-webhook-to-irccat/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ pkgs.buildGoModule {
1010
./go.sum
1111
];
1212
};
13-
vendorHash = "sha256-x5ldt3KWL6ri5UqbKFXN717R4JVTIFZyn5DsgGi/RY4=";
13+
vendorHash = "sha256-Xq0p6EEPFS23H+RMkzQw6767d8WujAz7doR6E/YKrgY=";
1414
}

ops/gerrit-webhook-to-irccat/go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ require (
1010
)
1111

1212
require (
13-
github.com/google/go-querystring v1.1.0 // indirect
1413
github.com/google/uuid v1.6.0 // indirect
1514
go.opentelemetry.io/otel v1.29.0 // indirect
1615
go.opentelemetry.io/otel/trace v1.29.0 // indirect
1716
)
1817

19-
// switch to the "fixes" branch, which renames _number to number and
20-
// work_in_progress to wip to match the structure of the JSON being sent.
21-
// Tracking issue: https://github.com/andygrunwald/go-gerrit/pull/187
22-
replace github.com/andygrunwald/go-gerrit v1.0.0 => github.com/flokli/go-gerrit v0.0.0-20250515192813-cf3a6e735367
18+
// Use the different data types sent in streams
19+
// https://github.com/andygrunwald/go-gerrit/pull/189
20+
replace github.com/andygrunwald/go-gerrit v1.0.0 => github.com/flokli/go-gerrit v0.0.0-20250523210852-9e357d872ff3

ops/gerrit-webhook-to-irccat/go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8
22
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/flokli/go-gerrit v0.0.0-20250515192813-cf3a6e735367 h1:qurVA28MaXYGbk1nWD5+PQhO5URhJW0PTgPNT1CPp0c=
6-
github.com/flokli/go-gerrit v0.0.0-20250515192813-cf3a6e735367/go.mod h1:SeP12EkHZxEVjuJ2HZET304NBtHGG2X6w2Gzd0QXAZw=
5+
github.com/flokli/go-gerrit v0.0.0-20250523210852-9e357d872ff3 h1:bkCL+U77VI69eCzZjBszrtl4ytCJcWZdkZeKfiNlz3o=
6+
github.com/flokli/go-gerrit v0.0.0-20250523210852-9e357d872ff3/go.mod h1:SeP12EkHZxEVjuJ2HZET304NBtHGG2X6w2Gzd0QXAZw=
77
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
88
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
99
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1010
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
11-
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
1211
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
1312
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1413
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

ops/gerrit-webhook-to-irccat/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
sloghttp "github.com/samber/slog-http"
1919
"golang.org/x/sync/errgroup"
2020

21-
"github.com/andygrunwald/go-gerrit"
21+
gerritStreams "github.com/andygrunwald/go-gerrit/streams"
2222
)
2323

2424
// TODO:
@@ -27,7 +27,7 @@ import (
2727

2828
var logger *slog.Logger
2929
var tmplStr = `{{- if eq .Type "patchset-created" -}}
30-
{{- if (and (eq .PatchSet.Number "1") (eq .Change.WorkInProgress false) ) -}}
30+
{{- if (and (eq .PatchSet.Number "1") (eq .Change.Wip false) ) -}}
3131
#snix CL/{{.Change.Number}} proposed by {{.Change.Owner.Username}} - {{.Change.Subject}} - {{.Change.URL}}
3232
{{- end -}}
3333
{{- else if eq .Type "change-merged" -}}
@@ -51,17 +51,17 @@ func handler(w http.ResponseWriter, r *http.Request) {
5151
}
5252
logger.InfoContext(r.Context(), "received event", slog.Any("body", body.Bytes()))
5353

54-
var eventInfo gerrit.EventInfo
55-
if err := json.Unmarshal(body.Bytes(), &eventInfo); err != nil {
54+
var event gerritStreams.Event
55+
if err := json.Unmarshal(body.Bytes(), &event); err != nil {
5656
logger.WarnContext(r.Context(), "failed to parse body", slog.Any("error", err))
5757
return
5858
}
5959

60-
logger.InfoContext(r.Context(), "received event", slog.Any("event", eventInfo))
60+
logger.InfoContext(r.Context(), "received event", slog.Any("event", event))
6161

6262
// render the template into a buffer.
6363
var msg bytes.Buffer
64-
if err := tmpl.Execute(&msg, eventInfo); err != nil {
64+
if err := tmpl.Execute(&msg, event); err != nil {
6565
logger.WarnContext(r.Context(), "failed to execute template with data", slog.Any("error", err))
6666
return
6767
}

0 commit comments

Comments
 (0)