From 5260dee4a4151f5d482d6a7ef609bb931871133c Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Tue, 27 Feb 2024 15:13:55 +0100 Subject: [PATCH] Migrate to slog --- .github/workflows/docker.yaml | 10 ++-- Dockerfile | 2 +- cmd/metal-robot/main.go | 29 ++++------ go.mod | 25 +++++---- go.sum | 53 +++++++++---------- pkg/clients/common.go | 8 +-- pkg/clients/github.go | 8 +-- pkg/clients/gitlab.go | 7 +-- pkg/webhooks/common.go | 12 ++--- .../github/actions/aggregate_releases.go | 16 +++--- pkg/webhooks/github/actions/common.go | 36 ++++++------- .../github/actions/distribute_releases.go | 22 ++++---- .../github/actions/docs_preview_comment.go | 8 +-- pkg/webhooks/github/actions/issues_handler.go | 18 +++---- .../github/actions/release_drafter.go | 24 ++++----- .../github/actions/release_drafter_test.go | 6 +-- .../github/actions/repository_maintainers.go | 12 ++--- .../github/actions/yaml_translate_releases.go | 16 +++--- pkg/webhooks/github/github.go | 24 ++++----- pkg/webhooks/gitlab/actions/common.go | 14 ++--- pkg/webhooks/gitlab/gitlab.go | 14 ++--- 21 files changed, 176 insertions(+), 188 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 007feb4..e08672b 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -22,23 +22,23 @@ jobs: steps: - name: Log in to the container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.DOCKER_REGISTRY_USER }} password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache: false - name: Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: args: --build-tags integration -p bugs -p unused --timeout=3m @@ -49,7 +49,7 @@ jobs: [ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true - name: Build and push image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: . push: true diff --git a/Dockerfile b/Dockerfile index d237cd8..42fbf29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ghcr.io/metal-stack/builder:latest as builder -FROM alpine:3.18 +FROM alpine:3.19 RUN apk add --no-cache ca-certificates COPY --from=builder /work/bin/metal-robot /metal-robot CMD ["/metal-robot"] diff --git a/cmd/metal-robot/main.go b/cmd/metal-robot/main.go index f007024..cb767c5 100644 --- a/cmd/metal-robot/main.go +++ b/cmd/metal-robot/main.go @@ -4,13 +4,12 @@ import ( "errors" "fmt" "log" + "log/slog" "net/http" + "os" "strings" "time" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/webhooks" @@ -28,7 +27,7 @@ const ( var ( cfgFile string - logger *zap.SugaredLogger + logger *slog.Logger c *config.Configuration ) @@ -62,7 +61,7 @@ var cmd = &cobra.Command{ func main() { if err := cmd.Execute(); err != nil { - logger.Fatalw("an error occurred", "error", err) + log.Fatalf("an error occurred %s", err) } } @@ -141,25 +140,19 @@ func loadRobotConfig() error { } func initLogging() { - level := zap.InfoLevel + level := slog.LevelInfo + var lvlvar slog.LevelVar if viper.IsSet("log-level") { - err := level.UnmarshalText([]byte(viper.GetString("log-level"))) + err := lvlvar.UnmarshalText([]byte(viper.GetString("log-level"))) if err != nil { log.Fatalf("can't initialize zap logger: %v", err) } + level = lvlvar.Level() } - cfg := zap.NewProductionConfig() - cfg.Level = zap.NewAtomicLevelAt(level) - cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - - l, err := cfg.Build() - if err != nil { - log.Fatalf("can't initialize zap logger: %v", err) - } - - logger = l.Sugar() + jsonHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}) + logger = slog.New(jsonHandler) } func run(opts *Opts) error { @@ -174,7 +167,7 @@ func run(opts *Opts) error { } addr := fmt.Sprintf("%s:%d", opts.BindAddr, opts.Port) - logger.Infow("starting metal-robot server", "version", v.V.String(), "address", addr) + logger.Info("starting metal-robot server", "version", v.V.String(), "address", addr) server := http.Server{ Addr: addr, ReadHeaderTimeout: 1 * time.Minute, diff --git a/go.mod b/go.mod index d7fdf5e..1100f83 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/metal-stack/metal-robot -go 1.21 +go 1.22 require ( github.com/Masterminds/semver/v3 v3.2.1 @@ -9,7 +9,7 @@ require ( github.com/go-git/go-billy/v5 v5.5.0 // IMPORTANT: keep this version as long as https://github.com/go-git/go-git/issues/328 is open github.com/go-git/go-git/v5 v5.3.0 - github.com/go-playground/validator/v10 v10.16.0 + github.com/go-playground/validator/v10 v10.18.0 github.com/go-playground/webhooks/v6 v6.3.0 github.com/google/go-cmp v0.6.0 github.com/google/go-github/v57 v57.0.0 @@ -17,9 +17,8 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 - github.com/tidwall/gjson v1.17.0 + github.com/tidwall/gjson v1.17.1 github.com/tidwall/sjson v1.2.5 - go.uber.org/zap v1.26.0 golang.org/x/sync v0.6.0 sigs.k8s.io/yaml v1.4.0 ) @@ -29,7 +28,7 @@ require ( github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect @@ -40,10 +39,10 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/leodido/go-urn v1.2.4 // indirect + github.com/leodido/go-urn v1.4.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sergi/go-diff v1.3.1 // indirect @@ -56,13 +55,13 @@ require ( github.com/tidwall/pretty v1.2.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.16.0 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.19.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/crypto v0.20.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/mod v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.13.0 // indirect + golang.org/x/tools v0.18.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index ae45c0f..cece7de 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= @@ -52,8 +52,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= -github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U= +github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-playground/webhooks/v6 v6.3.0 h1:zBLUxK1Scxwi97TmZt5j/B/rLlard2zY7P77FHg58FE= github.com/go-playground/webhooks/v6 v6.3.0/go.mod h1:GCocmfMtpJdkEOM1uG9p2nXzg1kY5X/LtvQgtPHUaaA= github.com/gogits/go-gogs-client v0.0.0-20200905025246-8bb8a50cb355/go.mod h1:cY2AIrMgHm6oOHmR7jY+9TtjzSjQ3iG7tURJG3Y6XH0= @@ -89,8 +89,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs= @@ -102,8 +102,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -143,14 +143,13 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM= -github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= +github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= @@ -161,26 +160,22 @@ github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6 github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= -go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg= +golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -195,18 +190,18 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/clients/common.go b/pkg/clients/common.go index aeafe60..a12dba7 100644 --- a/pkg/clients/common.go +++ b/pkg/clients/common.go @@ -2,9 +2,9 @@ package clients import ( "fmt" + "log/slog" "github.com/metal-stack/metal-robot/pkg/config" - "go.uber.org/zap" ) type ClientMap map[string]Client @@ -14,7 +14,7 @@ type Client interface { Organization() string } -func InitClients(logger *zap.SugaredLogger, config []config.Client) (ClientMap, error) { +func InitClients(logger *slog.Logger, config []config.Client) (ClientMap, error) { cs := ClientMap{} for _, clientConfig := range config { ghConfig := clientConfig.GithubAuthConfig @@ -25,7 +25,7 @@ func InitClients(logger *zap.SugaredLogger, config []config.Client) (ClientMap, } if ghConfig != nil { - client, err := NewGithub(logger.Named(clientConfig.Name), clientConfig.OrganizationName, ghConfig) + client, err := NewGithub(logger.WithGroup(clientConfig.Name), clientConfig.OrganizationName, ghConfig) if err != nil { return nil, err } @@ -34,7 +34,7 @@ func InitClients(logger *zap.SugaredLogger, config []config.Client) (ClientMap, } if glConfig != nil { - client, err := NewGitlab(logger.Named(clientConfig.Name), glConfig.Token) + client, err := NewGitlab(logger.WithGroup(clientConfig.Name), glConfig.Token) if err != nil { return nil, err } diff --git a/pkg/clients/github.go b/pkg/clients/github.go index 4df7df1..d68c0f5 100644 --- a/pkg/clients/github.go +++ b/pkg/clients/github.go @@ -3,17 +3,17 @@ package clients import ( "context" "fmt" + "log/slog" "net/http" "github.com/bradleyfalzon/ghinstallation/v2" "github.com/metal-stack/metal-robot/pkg/config" - "go.uber.org/zap" v3 "github.com/google/go-github/v57/github" ) type Github struct { - logger *zap.SugaredLogger + logger *slog.Logger keyPath string appID int64 installationID int64 @@ -23,7 +23,7 @@ type Github struct { itr *ghinstallation.Transport } -func NewGithub(logger *zap.SugaredLogger, organizationID string, config *config.GithubClient) (*Github, error) { +func NewGithub(logger *slog.Logger, organizationID string, config *config.GithubClient) (*Github, error) { a := &Github{ logger: logger, keyPath: config.PrivateKeyCertPath, @@ -59,7 +59,7 @@ func (a *Github) initClients() error { a.atr = atr a.itr = itr - a.logger.Infow("successfully initalized github app client", "organization-id", a.organizationID, "installation-id", a.installationID, "expected-events", installation.Events) + a.logger.Info("successfully initalized github app client", "organization-id", a.organizationID, "installation-id", a.installationID, "expected-events", installation.Events) return nil } diff --git a/pkg/clients/gitlab.go b/pkg/clients/gitlab.go index 906d77c..875238b 100644 --- a/pkg/clients/gitlab.go +++ b/pkg/clients/gitlab.go @@ -1,17 +1,18 @@ package clients import ( + "log/slog" + "github.com/metal-stack/metal-robot/pkg/config" - "go.uber.org/zap" ) type Gitlab struct { - logger *zap.SugaredLogger + logger *slog.Logger token string organizationID string } -func NewGitlab(logger *zap.SugaredLogger, token string) (*Gitlab, error) { +func NewGitlab(logger *slog.Logger, token string) (*Gitlab, error) { a := &Gitlab{ logger: logger, token: token, diff --git a/pkg/webhooks/common.go b/pkg/webhooks/common.go index 888ab09..8edaf79 100644 --- a/pkg/webhooks/common.go +++ b/pkg/webhooks/common.go @@ -2,32 +2,32 @@ package webhooks import ( "fmt" + "log/slog" "net/http" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/webhooks/github" "github.com/metal-stack/metal-robot/pkg/webhooks/gitlab" - "go.uber.org/zap" ) -func InitWebhooks(logger *zap.SugaredLogger, cs clients.ClientMap, c *config.Configuration) error { +func InitWebhooks(logger *slog.Logger, cs clients.ClientMap, c *config.Configuration) error { for _, w := range c.Webhooks { switch w.VCS { case config.Github: - controller, err := github.NewGithubWebhook(logger.Named("github-webhook"), w, cs) + controller, err := github.NewGithubWebhook(logger.WithGroup("github-webhook"), w, cs) if err != nil { return err } http.HandleFunc(w.ServePath, controller.Handle) - logger.Infow("initialized github webhook", "serve-path", w.ServePath) + logger.Info("initialized github webhook", "serve-path", w.ServePath) case config.Gitlab: - controller, err := gitlab.NewGitlabWebhook(logger.Named("gitlab-webhook"), w, cs) + controller, err := gitlab.NewGitlabWebhook(logger.WithGroup("gitlab-webhook"), w, cs) if err != nil { return err } http.HandleFunc(w.ServePath, controller.Handle) - logger.Infow("initialized gitlab webhook", "serve-path", w.ServePath) + logger.Info("initialized gitlab webhook", "serve-path", w.ServePath) default: return fmt.Errorf("unsupported webhook type: %s", w.VCS) } diff --git a/pkg/webhooks/github/actions/aggregate_releases.go b/pkg/webhooks/github/actions/aggregate_releases.go index fabcb94..aaf9819 100644 --- a/pkg/webhooks/github/actions/aggregate_releases.go +++ b/pkg/webhooks/github/actions/aggregate_releases.go @@ -3,6 +3,7 @@ package actions import ( "context" "fmt" + "log/slog" "net/url" "strings" "sync" @@ -17,11 +18,10 @@ import ( "github.com/metal-stack/metal-robot/pkg/git" filepatchers "github.com/metal-stack/metal-robot/pkg/webhooks/modifiers/file-patchers" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" ) type AggregateReleases struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github branch string branchBase string @@ -39,7 +39,7 @@ type AggregateReleaseParams struct { TagName string } -func NewAggregateReleases(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*AggregateReleases, error) { +func NewAggregateReleases(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*AggregateReleases, error) { var ( branch = "develop" branchBase = "master" @@ -107,7 +107,7 @@ func NewAggregateReleases(logger *zap.SugaredLogger, client *clients.Github, raw func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateReleaseParams) error { patches, ok := r.patchMap[p.RepositoryName] if !ok { - r.logger.Debugw("skip applying release actions to aggregation repo, not in list of source repositories", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) + r.logger.Debug("skip applying release actions to aggregation repo, not in list of source repositories", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) return nil } @@ -115,7 +115,7 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe trimmed := strings.TrimPrefix(tag, "v") _, err := semver.NewVersion(trimmed) if err != nil { - r.logger.Infow("skip applying release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) + r.logger.Info("skip applying release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) return nil //nolint:nilerr } @@ -159,12 +159,12 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe hash, err := git.CommitAndPush(repository, commitMessage) if err != nil { if errors.Is(err, git.NoChangesError) { - r.logger.Debugw("skip push to target repository because nothing changed", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag) + r.logger.Debug("skip push to target repository because nothing changed", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag) } else { return fmt.Errorf("error pushing to target repository %w", err) } } else { - r.logger.Infow("pushed to aggregate target repo", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag, "branch", r.branch, "hash", hash) + r.logger.Info("pushed to aggregate target repo", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag, "branch", r.branch, "hash", hash) once.Do(func() { r.lock.Unlock() }) } @@ -181,7 +181,7 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe return err } } else { - r.logger.Infow("created pull request", "target-repo", p.RepositoryName, "url", pr.GetURL()) + r.logger.Info("created pull request", "target-repo", p.RepositoryName, "url", pr.GetURL()) } return nil diff --git a/pkg/webhooks/github/actions/common.go b/pkg/webhooks/github/actions/common.go index e9f4414..ee4f54a 100644 --- a/pkg/webhooks/github/actions/common.go +++ b/pkg/webhooks/github/actions/common.go @@ -3,13 +3,13 @@ package actions import ( "context" "fmt" + "log/slog" "strconv" "strings" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/webhooks/constants" - "go.uber.org/zap" "golang.org/x/sync/errgroup" ghwebhooks "github.com/go-playground/webhooks/v6/github" @@ -26,7 +26,7 @@ const ( ) type WebhookActions struct { - logger *zap.SugaredLogger + logger *slog.Logger rm []*repositoryMaintainers dp []*docsPreviewComment ar []*AggregateReleases @@ -36,7 +36,7 @@ type WebhookActions struct { yr []*yamlTranslateReleases } -func InitActions(logger *zap.SugaredLogger, cs clients.ClientMap, config config.WebhookActions) (*WebhookActions, error) { +func InitActions(logger *slog.Logger, cs clients.ClientMap, config config.WebhookActions) (*WebhookActions, error) { actions := WebhookActions{ logger: logger, } @@ -100,7 +100,7 @@ func InitActions(logger *zap.SugaredLogger, cs clients.ClientMap, config config. return nil, fmt.Errorf("handler type not supported: %s", t) } - logger.Debugw("initialized github webhook action", "name", spec.Type) + logger.Debug("initialized github webhook action", "name", spec.Type) } return &actions, nil @@ -123,7 +123,7 @@ func (w *WebhookActions) ProcessReleaseEvent(ctx context.Context, payload *ghweb } err := a.AggregateRelease(ctx, params) if err != nil { - w.logger.Errorw("error in aggregate release action", "source-repo", params.RepositoryName, "target-repo", a.repoName, "tag", params.TagName, "error", err) + w.logger.Error("error in aggregate release action", "source-repo", params.RepositoryName, "target-repo", a.repoName, "tag", params.TagName, "error", err) return err } @@ -145,7 +145,7 @@ func (w *WebhookActions) ProcessReleaseEvent(ctx context.Context, payload *ghweb } err := a.draft(ctx, params) if err != nil { - w.logger.Errorw("error creating release draft", "repo", a.repoName, "tag", params.TagName, "error", err) + w.logger.Error("error creating release draft", "repo", a.repoName, "tag", params.TagName, "error", err) return err } @@ -166,7 +166,7 @@ func (w *WebhookActions) ProcessReleaseEvent(ctx context.Context, payload *ghweb } err := a.translateRelease(ctx, params) if err != nil { - w.logger.Errorw("error creating translating release", "repo", a.repoName, "tag", params.TagName, "error", err) + w.logger.Error("error creating translating release", "repo", a.repoName, "tag", params.TagName, "error", err) return err } @@ -175,7 +175,7 @@ func (w *WebhookActions) ProcessReleaseEvent(ctx context.Context, payload *ghweb } if err := g.Wait(); err != nil { - w.logger.Errorw("errors processing event", "error", err) + w.logger.Error("errors processing event", "error", err) } } @@ -195,7 +195,7 @@ func (w *WebhookActions) ProcessPullRequestEvent(ctx context.Context, payload *g } err := a.AddDocsPreviewComment(ctx, params) if err != nil { - w.logger.Errorw("error adding docs preview comment to docs", "repo", payload.Repository.Name, "pull_request", params.PullRequestNumber, "error", err) + w.logger.Error("error adding docs preview comment to docs", "repo", payload.Repository.Name, "pull_request", params.PullRequestNumber, "error", err) return err } @@ -222,7 +222,7 @@ func (w *WebhookActions) ProcessPullRequestEvent(ctx context.Context, payload *g } err := a.appendMergedPR(ctx, payload.PullRequest.Title, payload.PullRequest.Number, payload.PullRequest.User.Login, params) if err != nil { - w.logger.Errorw("error append merged PR to release draft", "repo", a.repoName, "pr", payload.PullRequest.Title, "error", err) + w.logger.Error("error append merged PR to release draft", "repo", a.repoName, "pr", payload.PullRequest.Title, "error", err) return err } @@ -231,7 +231,7 @@ func (w *WebhookActions) ProcessPullRequestEvent(ctx context.Context, payload *g } if err := g.Wait(); err != nil { - w.logger.Errorw("errors processing event", "error", err) + w.logger.Error("errors processing event", "error", err) } } @@ -253,7 +253,7 @@ func (w *WebhookActions) ProcessPushEvent(ctx context.Context, payload *ghwebhoo err := a.AggregateRelease(ctx, params) if err != nil { - w.logger.Errorw("error in aggregate release action", "source-repo", params.RepositoryName, "target-repo", a.repoName, "tag", params.TagName, "error", err) + w.logger.Error("error in aggregate release action", "source-repo", params.RepositoryName, "target-repo", a.repoName, "tag", params.TagName, "error", err) return err } @@ -275,7 +275,7 @@ func (w *WebhookActions) ProcessPushEvent(ctx context.Context, payload *ghwebhoo err := a.DistributeRelease(ctx, params) if err != nil { - w.logger.Errorw("error in distribute release action", "source-repo", params.RepositoryName, "tag", params.TagName, "error", err) + w.logger.Error("error in distribute release action", "source-repo", params.RepositoryName, "tag", params.TagName, "error", err) return err } @@ -284,7 +284,7 @@ func (w *WebhookActions) ProcessPushEvent(ctx context.Context, payload *ghwebhoo } if err := g.Wait(); err != nil { - w.logger.Errorw("errors processing event", "error", err) + w.logger.Error("errors processing event", "error", err) } } @@ -306,7 +306,7 @@ func (w *WebhookActions) ProcessRepositoryEvent(ctx context.Context, payload *gh } err := a.CreateRepositoryMaintainers(ctx, params) if err != nil { - w.logger.Errorw("error creating repository maintainers team", "repo", params.RepositoryName, "error", err) + w.logger.Error("error creating repository maintainers team", "repo", params.RepositoryName, "error", err) return err } @@ -315,7 +315,7 @@ func (w *WebhookActions) ProcessRepositoryEvent(ctx context.Context, payload *gh } if err := g.Wait(); err != nil { - w.logger.Errorw("errors processing event", "error", err) + w.logger.Error("errors processing event", "error", err) } } @@ -352,7 +352,7 @@ func (w *WebhookActions) ProcessIssueCommentEvent(ctx context.Context, payload * err = i.HandleIssueComment(ctx, params) if err != nil { - w.logger.Errorw("error in issue comment handler action", "source-repo", params.RepositoryName, "error", err) + w.logger.Error("error in issue comment handler action", "source-repo", params.RepositoryName, "error", err) return err } @@ -361,7 +361,7 @@ func (w *WebhookActions) ProcessIssueCommentEvent(ctx context.Context, payload * } if err := g.Wait(); err != nil { - w.logger.Errorw("errors processing event", "error", err) + w.logger.Error("errors processing event", "error", err) } } diff --git a/pkg/webhooks/github/actions/distribute_releases.go b/pkg/webhooks/github/actions/distribute_releases.go index c946d8a..37314c9 100644 --- a/pkg/webhooks/github/actions/distribute_releases.go +++ b/pkg/webhooks/github/actions/distribute_releases.go @@ -3,6 +3,7 @@ package actions import ( "context" "fmt" + "log/slog" "net/url" "strings" "sync" @@ -17,7 +18,6 @@ import ( "github.com/metal-stack/metal-robot/pkg/git" filepatchers "github.com/metal-stack/metal-robot/pkg/webhooks/modifiers/file-patchers" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" "golang.org/x/sync/errgroup" ) @@ -27,7 +27,7 @@ type distributeReleaseParams struct { } type distributeReleases struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github commitMessageTemplate string branchTemplate string @@ -42,7 +42,7 @@ type targetRepo struct { url string } -func newDistributeReleases(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*distributeReleases, error) { +func newDistributeReleases(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*distributeReleases, error) { var ( commitMessageTemplate = "Bump %s to version %s" branchTemplate = "auto-generate/%s" @@ -104,13 +104,13 @@ func newDistributeReleases(logger *zap.SugaredLogger, client *clients.Github, ra // DistributeRelease applies the actions to a given list of target repositories after a push or release trigger on the source repository func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distributeReleaseParams) error { if p.RepositoryName != d.repoName { - d.logger.Debugw("skip applying release actions to target repos, not triggered by source repo", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName) + d.logger.Debug("skip applying release actions to target repos, not triggered by source repo", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName) return nil } tag := p.TagName if !strings.HasPrefix(tag, "v") { - d.logger.Debugw("skip applying release actions to target repos because release tag not starting with v", "source-repo", p.RepositoryName, "tag", p.TagName) + d.logger.Debug("skip applying release actions to target repos because release tag not starting with v", "source-repo", p.RepositoryName, "tag", p.TagName) return nil } @@ -118,12 +118,12 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut parsedVersion, err := semver.NewVersion(trimmed) if err != nil { - d.logger.Infow("skip applying release actions to target repos because not a valid semver release tag", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName) + d.logger.Info("skip applying release actions to target repos because not a valid semver release tag", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName) return nil //nolint:nilerr } if parsedVersion.Prerelease() != "" { - d.logger.Infow("skip applying release actions to target repos because is a pre-release", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName) + d.logger.Info("skip applying release actions to target repos because is a pre-release", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName) return nil //nolint:nilerr } @@ -180,13 +180,13 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut hash, err := git.CommitAndPush(r, commitMessage) if err != nil { if errors.Is(err, git.NoChangesError) { - d.logger.Debugw("skip applying release actions to target repo because nothing changed", "source-repo", p.RepositoryName, "target-repo", targetRepoName, "tag", p.TagName) + d.logger.Debug("skip applying release actions to target repo because nothing changed", "source-repo", p.RepositoryName, "target-repo", targetRepoName, "tag", p.TagName) return nil } return fmt.Errorf("error applying release updates %w", err) } - d.logger.Infow("pushed to target repo", "source-repo", p.RepositoryName, "target-repo", targetRepoName, "release", tag, "branch", prBranch, "hash", hash) + d.logger.Info("pushed to target repo", "source-repo", p.RepositoryName, "target-repo", targetRepoName, "release", tag, "branch", prBranch, "hash", hash) once.Do(func() { lock.Unlock() }) @@ -202,7 +202,7 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut return err } } else { - d.logger.Infow("created pull request for target repo", "source-repo", p.RepositoryName, "target-repo", targetRepoName, "release", tag, "url", pr.GetURL()) + d.logger.Info("created pull request for target repo", "source-repo", p.RepositoryName, "target-repo", targetRepoName, "release", tag, "url", pr.GetURL()) } return nil @@ -210,7 +210,7 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut } if err := g.Wait(); err != nil { - d.logger.Errorw("errors occurred while applying release actions to target repos", "error", err) + d.logger.Error("errors occurred while applying release actions to target repos", "error", err) } return nil diff --git a/pkg/webhooks/github/actions/docs_preview_comment.go b/pkg/webhooks/github/actions/docs_preview_comment.go index f59c4f1..4f824af 100644 --- a/pkg/webhooks/github/actions/docs_preview_comment.go +++ b/pkg/webhooks/github/actions/docs_preview_comment.go @@ -3,18 +3,18 @@ package actions import ( "context" "fmt" + "log/slog" v3 "github.com/google/go-github/v57/github" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" ) const () type docsPreviewComment struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github commentTemplate string repositoryName string @@ -24,7 +24,7 @@ type docsPreviewCommentParams struct { PullRequestNumber int } -func newDocsPreviewComment(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*docsPreviewComment, error) { +func newDocsPreviewComment(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*docsPreviewComment, error) { var ( commentTemplate = "#%d" ) @@ -66,7 +66,7 @@ func (d *docsPreviewComment) AddDocsPreviewComment(ctx context.Context, p *docsP return fmt.Errorf("error creating pull request comment in docs repo %w", err) } - d.logger.Infow("added preview comment in docs repo", "url", c.GetURL()) + d.logger.Info("added preview comment in docs repo", "url", c.GetURL()) return nil } diff --git a/pkg/webhooks/github/actions/issues_handler.go b/pkg/webhooks/github/actions/issues_handler.go index f3063cd..f6d2045 100644 --- a/pkg/webhooks/github/actions/issues_handler.go +++ b/pkg/webhooks/github/actions/issues_handler.go @@ -3,6 +3,7 @@ package actions import ( "context" "fmt" + "log/slog" "net/url" "strings" @@ -10,7 +11,6 @@ import ( "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/git" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" ) type IssueCommentCommand string @@ -33,7 +33,7 @@ var ( ) type IssuesAction struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github targetRepos map[string]bool @@ -48,7 +48,7 @@ type IssuesActionParams struct { CommentID int64 } -func NewIssuesAction(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*IssuesAction, error) { +func NewIssuesAction(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*IssuesAction, error) { var typedConfig config.IssuesCommentHandlerConfig err := mapstructure.Decode(rawConfig, &typedConfig) if err != nil { @@ -70,13 +70,13 @@ func NewIssuesAction(logger *zap.SugaredLogger, client *clients.Github, rawConfi func (r *IssuesAction) HandleIssueComment(ctx context.Context, p *IssuesActionParams) error { _, ok := r.targetRepos[p.RepositoryName] if !ok { - r.logger.Debugw("skip handling issues comment action, not in list of target repositories", "source-repo", p.RepositoryName) + r.logger.Debug("skip handling issues comment action, not in list of target repositories", "source-repo", p.RepositoryName) return nil } _, ok = AllowedAuthorAssociations[p.AuthorAssociation] if !ok { - r.logger.Debugw("skip handling issues comment action, author is not allowed", "source-repo", p.RepositoryName, "association", p.AuthorAssociation) + r.logger.Debug("skip handling issues comment action, author is not allowed", "source-repo", p.RepositoryName, "association", p.AuthorAssociation) return nil } @@ -84,7 +84,7 @@ func (r *IssuesAction) HandleIssueComment(ctx context.Context, p *IssuesActionPa _, ok = IssueCommentCommands[IssueCommentCommand(comment)] if !ok { - r.logger.Debugw("skip handling issues comment action, message does not contain a valid command", "source-repo", p.RepositoryName) + r.logger.Debug("skip handling issues comment action, message does not contain a valid command", "source-repo", p.RepositoryName) return nil } @@ -92,7 +92,7 @@ func (r *IssuesAction) HandleIssueComment(ctx context.Context, p *IssuesActionPa case IssueCommentBuildFork: return r.buildForkPR(ctx, p) default: - r.logger.Debugw("skip handling issues comment action, message does not contain a valid command", "source-repo", p.RepositoryName) + r.logger.Debug("skip handling issues comment action, message does not contain a valid command", "source-repo", p.RepositoryName) return nil } } @@ -104,7 +104,7 @@ func (r *IssuesAction) buildForkPR(ctx context.Context, p *IssuesActionParams) e } if pullRequest.Head.Repo.Fork == nil || !*pullRequest.Head.Repo.Fork { - r.logger.Debugw("skip handling issues comment action, pull request is not from a fork", "source-repo", p.RepositoryName) + r.logger.Debug("skip handling issues comment action, pull request is not from a fork", "source-repo", p.RepositoryName) return nil } @@ -126,7 +126,7 @@ func (r *IssuesAction) buildForkPR(ctx context.Context, p *IssuesActionParams) e return fmt.Errorf("error pushing to target remote repository %w", err) } - r.logger.Infow("triggered fork build action by pushing to fork-build branch", "source-repo", p.RepositoryName, "branch", headRef) + r.logger.Info("triggered fork build action by pushing to fork-build branch", "source-repo", p.RepositoryName, "branch", headRef) _, _, err = r.client.GetV3Client().Reactions.CreateIssueCommentReaction(ctx, r.client.Organization(), p.RepositoryName, p.CommentID, "rocket") if err != nil { diff --git a/pkg/webhooks/github/actions/release_drafter.go b/pkg/webhooks/github/actions/release_drafter.go index 5d2cbdd..45e0afb 100644 --- a/pkg/webhooks/github/actions/release_drafter.go +++ b/pkg/webhooks/github/actions/release_drafter.go @@ -3,6 +3,7 @@ package actions import ( "context" "fmt" + "log/slog" "regexp" "strings" @@ -13,7 +14,6 @@ import ( "github.com/metal-stack/metal-robot/pkg/markdown" "github.com/metal-stack/metal-robot/pkg/utils" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" v3 "github.com/google/go-github/v57/github" ) @@ -38,7 +38,7 @@ type codeBlock struct { } type releaseDrafter struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github titleTemplate string draftHeadline string @@ -55,7 +55,7 @@ type releaseDrafterParams struct { ReleaseURL string } -func newReleaseDrafter(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*releaseDrafter, error) { +func newReleaseDrafter(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*releaseDrafter, error) { var ( releaseTitleTemplate = "%s" draftHeadline = "General" @@ -109,7 +109,7 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err // if there is an ACTIONS_REQUIRED block, we want to add it (even when it's not a release vector repository) if p.ComponentReleaseInfo == nil { - r.logger.Debugw("skip adding release draft because not a release vector repo and no special sections", "repo", p.RepositoryName, "release", p.TagName) + r.logger.Debug("skip adding release draft because not a release vector repo and no special sections", "repo", p.RepositoryName, "release", p.TagName) return nil } @@ -127,7 +127,7 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err } err = r.prependCodeBlocks(m, *p.ComponentReleaseInfo, releaseSuffix) if err != nil { - r.logger.Debugw("skip adding release draft", "reason", err, "repo", p.RepositoryName) + r.logger.Debug("skip adding release draft", "reason", err, "repo", p.RepositoryName) return nil } @@ -138,13 +138,13 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err componentTag := p.TagName if !strings.HasPrefix(componentTag, "v") { - r.logger.Debugw("skip adding release draft because tag not starting with v", "repo", p.RepositoryName, "release", componentTag) + r.logger.Debug("skip adding release draft because tag not starting with v", "repo", p.RepositoryName, "release", componentTag) return nil } trimmedVersion := strings.TrimPrefix(componentTag, "v") componentSemver, err := semver.NewVersion(trimmedVersion) if err != nil { - r.logger.Debugw("skip adding release draft because tag is not semver compatible", "repo", p.RepositoryName, "release", componentTag) + r.logger.Debug("skip adding release draft because tag is not semver compatible", "repo", p.RepositoryName, "release", componentTag) return nil //nolint:nilerr } @@ -231,7 +231,7 @@ func (r *releaseDrafter) appendMergedPR(ctx context.Context, title string, numbe // if there is an ACTIONS_REQUIRED block, we want to add it (even when it's a release vector handled repository) if p.ComponentReleaseInfo == nil { - r.logger.Debugw("skip adding merged pull request to release draft because of special handling in release vector", "repo", p.RepositoryName) + r.logger.Debug("skip adding merged pull request to release draft because of special handling in release vector", "repo", p.RepositoryName) return nil } @@ -245,7 +245,7 @@ func (r *releaseDrafter) appendMergedPR(ctx context.Context, title string, numbe issueSuffix := fmt.Sprintf("(%s/%s#%d)", r.client.Organization(), p.RepositoryName, number) err = r.prependCodeBlocks(m, *p.ComponentReleaseInfo, &issueSuffix) if err != nil { - r.logger.Debugw("skip adding merged pull request to release draft", "reason", err, "repo", p.RepositoryName) + r.logger.Debug("skip adding merged pull request to release draft", "reason", err, "repo", p.RepositoryName) return nil } @@ -406,7 +406,7 @@ func (r *releaseDrafter) guessNextVersionFromLatestRelease(ctx context.Context) t = strings.TrimPrefix(t, "v") latestTag, err := semver.NewVersion(t) if err != nil { - r.logger.Warnw("latest release of repository was not a semver tag", "repository", r.repoName, "latest-tag", *latest.TagName) + r.logger.Warn("latest release of repository was not a semver tag", "repository", r.repoName, "latest-tag", *latest.TagName) } else { return "v" + latestTag.IncPatch().String(), nil } @@ -447,7 +447,7 @@ func (r *releaseDrafter) createOrUpdateRelease(ctx context.Context, infos *relea if err != nil { return fmt.Errorf("unable to update release draft %w", err) } - r.logger.Infow("release draft updated", "repository", r.repoName, "trigger-component", p.RepositoryName, "version", p.TagName) + r.logger.Info("release draft updated", "repository", r.repoName, "trigger-component", p.RepositoryName, "version", p.TagName) } else { newDraft := &github.RepositoryRelease{ TagName: v3.String(infos.releaseTag), @@ -459,7 +459,7 @@ func (r *releaseDrafter) createOrUpdateRelease(ctx context.Context, infos *relea if err != nil { return fmt.Errorf("unable to create release draft %w", err) } - r.logger.Infow("new release draft created", "repository", r.repoName, "trigger-component", p.RepositoryName, "version", p.TagName) + r.logger.Info("new release draft created", "repository", r.repoName, "trigger-component", p.RepositoryName, "version", p.TagName) } return nil diff --git a/pkg/webhooks/github/actions/release_drafter_test.go b/pkg/webhooks/github/actions/release_drafter_test.go index cc9064d..7a082cd 100644 --- a/pkg/webhooks/github/actions/release_drafter_test.go +++ b/pkg/webhooks/github/actions/release_drafter_test.go @@ -1,12 +1,12 @@ package actions import ( + "log/slog" "testing" "github.com/Masterminds/semver/v3" "github.com/google/go-cmp/cmp" v3 "github.com/google/go-github/v57/github" - "go.uber.org/zap/zaptest" ) func TestReleaseDrafter_updateReleaseBody(t *testing.T) { @@ -191,7 +191,7 @@ Some description tt := tt t.Run(tt.name, func(t *testing.T) { r := &releaseDrafter{ - logger: zaptest.NewLogger(t).Sugar(), + logger: slog.Default(), client: nil, draftHeadline: tt.headline, } @@ -319,7 +319,7 @@ Some description t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) { r := &releaseDrafter{ - logger: zaptest.NewLogger(t).Sugar(), + logger: slog.Default(), client: nil, prHeadline: "Merged Pull Requests", draftHeadline: "General", diff --git a/pkg/webhooks/github/actions/repository_maintainers.go b/pkg/webhooks/github/actions/repository_maintainers.go index 2b06b8e..59f9797 100644 --- a/pkg/webhooks/github/actions/repository_maintainers.go +++ b/pkg/webhooks/github/actions/repository_maintainers.go @@ -3,17 +3,17 @@ package actions import ( "context" "fmt" + "log/slog" "strings" v3 "github.com/google/go-github/v57/github" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" ) type repositoryMaintainers struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github suffix string additionalTeams repositoryAdditionalMemberships @@ -31,7 +31,7 @@ type repositoryMaintainersParams struct { Creator string } -func newCreateRepositoryMaintainers(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*repositoryMaintainers, error) { +func newCreateRepositoryMaintainers(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*repositoryMaintainers, error) { var ( suffix = "-maintainers" ) @@ -78,12 +78,12 @@ func (r *repositoryMaintainers) CreateRepositoryMaintainers(ctx context.Context, }) if err != nil { if strings.Contains(err.Error(), "Name must be unique for this org") { - r.logger.Infow("maintainers team for repository already exists", "repository", p.RepositoryName, "team", name) + r.logger.Info("maintainers team for repository already exists", "repository", p.RepositoryName, "team", name) } else { return fmt.Errorf("error creating maintainers team %w", err) } } else { - r.logger.Infow("created new maintainers team for repository", "repository", p.RepositoryName, "team", name) + r.logger.Info("created new maintainers team for repository", "repository", p.RepositoryName, "team", name) } memberships := []repositoryTeamMembership{ @@ -103,7 +103,7 @@ func (r *repositoryMaintainers) CreateRepositoryMaintainers(ctx context.Context, if err != nil { return fmt.Errorf("error adding team membership: %w", err) } else { - r.logger.Infow("added team to repository", "repository", p.RepositoryName, "team", team.teamSlug, "permission", team.permission) + r.logger.Info("added team to repository", "repository", p.RepositoryName, "team", team.teamSlug, "permission", team.permission) } } diff --git a/pkg/webhooks/github/actions/yaml_translate_releases.go b/pkg/webhooks/github/actions/yaml_translate_releases.go index f15cf28..67035e9 100644 --- a/pkg/webhooks/github/actions/yaml_translate_releases.go +++ b/pkg/webhooks/github/actions/yaml_translate_releases.go @@ -3,6 +3,7 @@ package actions import ( "context" "fmt" + "log/slog" "net/url" "strings" "sync" @@ -17,11 +18,10 @@ import ( "github.com/metal-stack/metal-robot/pkg/git" filepatchers "github.com/metal-stack/metal-robot/pkg/webhooks/modifiers/file-patchers" "github.com/mitchellh/mapstructure" - "go.uber.org/zap" ) type yamlTranslateReleases struct { - logger *zap.SugaredLogger + logger *slog.Logger client *clients.Github branch string branchBase string @@ -50,7 +50,7 @@ type yamlTranslateReleaseParams struct { TagName string } -func newYAMLTranslateReleases(logger *zap.SugaredLogger, client *clients.Github, rawConfig map[string]any) (*yamlTranslateReleases, error) { +func newYAMLTranslateReleases(logger *slog.Logger, client *clients.Github, rawConfig map[string]any) (*yamlTranslateReleases, error) { var ( branch = "develop" branchBase = "master" @@ -133,7 +133,7 @@ func newYAMLTranslateReleases(logger *zap.SugaredLogger, client *clients.Github, func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTranslateReleaseParams) error { translations, ok := r.translationMap[p.RepositoryName] if !ok { - r.logger.Debugw("skip applying translate release actions to aggregation repo, not in list of source repositories", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) + r.logger.Debug("skip applying translate release actions to aggregation repo, not in list of source repositories", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) return nil } @@ -141,7 +141,7 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra trimmed := strings.TrimPrefix(tag, "v") _, err := semver.NewVersion(trimmed) if err != nil { - r.logger.Infow("skip applying translate release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) + r.logger.Info("skip applying translate release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) return nil //nolint:nilerr } @@ -208,13 +208,13 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra hash, err := git.CommitAndPush(targetRepository, commitMessage) if err != nil { if errors.Is(err, git.NoChangesError) { - r.logger.Debugw("skip push to target repository because nothing changed", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag) + r.logger.Debug("skip push to target repository because nothing changed", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag) return nil } return fmt.Errorf("error pushing to target repository %w", err) } - r.logger.Infow("pushed to translate target repo", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag, "branch", r.branch, "hash", hash) + r.logger.Info("pushed to translate target repo", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag, "branch", r.branch, "hash", hash) once.Do(func() { r.lock.Unlock() }) @@ -230,7 +230,7 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra return err } } else { - r.logger.Infow("created pull request", "target-repo", p.RepositoryName, "url", pr.GetURL()) + r.logger.Info("created pull request", "target-repo", p.RepositoryName, "url", pr.GetURL()) } return nil diff --git a/pkg/webhooks/github/github.go b/pkg/webhooks/github/github.go index 6bb3559..2efe379 100644 --- a/pkg/webhooks/github/github.go +++ b/pkg/webhooks/github/github.go @@ -3,13 +3,13 @@ package github import ( "context" "errors" + "log/slog" "net/http" ghwebhooks "github.com/go-playground/webhooks/v6/github" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/webhooks/github/actions" - "go.uber.org/zap" ) var listenEvents = []ghwebhooks.Event{ @@ -22,14 +22,14 @@ var listenEvents = []ghwebhooks.Event{ } type Webhook struct { - logger *zap.SugaredLogger + logger *slog.Logger cs clients.ClientMap hook *ghwebhooks.Webhook a *actions.WebhookActions } // NewGithubWebhook returns a new webhook controller -func NewGithubWebhook(logger *zap.SugaredLogger, w config.Webhook, cs clients.ClientMap) (*Webhook, error) { +func NewGithubWebhook(logger *slog.Logger, w config.Webhook, cs clients.ClientMap) (*Webhook, error) { hook, err := ghwebhooks.New(ghwebhooks.Options.Secret(w.Secret)) if err != nil { return nil, err @@ -55,10 +55,10 @@ func (w *Webhook) Handle(response http.ResponseWriter, request *http.Request) { payload, err := w.hook.Parse(request, listenEvents...) if err != nil { if errors.Is(err, ghwebhooks.ErrEventNotFound) { - w.logger.Warnw("received unregistered github event", "error", err) + w.logger.Warn("received unregistered github event", "error", err) response.WriteHeader(http.StatusOK) } else { - w.logger.Errorw("received malformed github event", "error", err) + w.logger.Error("received malformed github event", "error", err) response.WriteHeader(http.StatusInternalServerError) } return @@ -67,29 +67,29 @@ func (w *Webhook) Handle(response http.ResponseWriter, request *http.Request) { ctx := context.Background() switch payload := payload.(type) { case ghwebhooks.ReleasePayload: - w.logger.Debugw("received release event") + w.logger.Debug("received release event") // nolint:contextcheck go w.a.ProcessReleaseEvent(ctx, &payload) case ghwebhooks.PullRequestPayload: - w.logger.Debugw("received pull request event") + w.logger.Debug("received pull request event") // nolint:contextcheck go w.a.ProcessPullRequestEvent(ctx, &payload) case ghwebhooks.PushPayload: - w.logger.Debugw("received push event") + w.logger.Debug("received push event") // nolint:contextcheck go w.a.ProcessPushEvent(ctx, &payload) case ghwebhooks.IssuesPayload: - w.logger.Debugw("received issues event") + w.logger.Debug("received issues event") case ghwebhooks.IssueCommentPayload: - w.logger.Debugw("received issue comment event") + w.logger.Debug("received issue comment event") // nolint:contextcheck go w.a.ProcessIssueCommentEvent(ctx, &payload) case ghwebhooks.RepositoryPayload: - w.logger.Debugw("received repository event") + w.logger.Debug("received repository event") // nolint:contextcheck go w.a.ProcessRepositoryEvent(ctx, &payload) default: - w.logger.Warnw("missing handler", "payload", payload) + w.logger.Warn("missing handler", "payload", payload) } response.WriteHeader(http.StatusOK) diff --git a/pkg/webhooks/gitlab/actions/common.go b/pkg/webhooks/gitlab/actions/common.go index 64d5c89..aba4373 100644 --- a/pkg/webhooks/gitlab/actions/common.go +++ b/pkg/webhooks/gitlab/actions/common.go @@ -3,24 +3,24 @@ package actions import ( "context" "fmt" + "log/slog" "strings" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/webhooks/constants" ghactions "github.com/metal-stack/metal-robot/pkg/webhooks/github/actions" - "go.uber.org/zap" "golang.org/x/sync/errgroup" glwebhooks "github.com/go-playground/webhooks/v6/gitlab" ) type WebhookActions struct { - logger *zap.SugaredLogger + logger *slog.Logger ar []*ghactions.AggregateReleases } -func InitActions(logger *zap.SugaredLogger, cs clients.ClientMap, config config.WebhookActions) (*WebhookActions, error) { +func InitActions(logger *slog.Logger, cs clients.ClientMap, config config.WebhookActions) (*WebhookActions, error) { actions := WebhookActions{ logger: logger, } @@ -46,7 +46,7 @@ func InitActions(logger *zap.SugaredLogger, cs clients.ClientMap, config config. return nil, fmt.Errorf("handler type not supported: %s", t) } - logger.Debugw("initialized github webhook action", "name", ghactions.ActionAggregateReleases) + logger.Debug("initialized github webhook action", "name", ghactions.ActionAggregateReleases) } return &actions, nil @@ -66,8 +66,8 @@ func (w *WebhookActions) ProcessTagEvent(ctx context.Context, payload *glwebhook } err := a.AggregateRelease(ctx, params) if err != nil { - w.logger.Errorw("error in aggregate release action", "release-repo", params, "repo", params.RepositoryName, "tag", params.TagName, "error", err) - w.logger.Errorw("error adding release to release vector", "repo", params.RepositoryName, "tag", extractTag(payload), "error", err) + w.logger.Error("error in aggregate release action", "release-repo", params, "repo", params.RepositoryName, "tag", params.TagName, "error", err) + w.logger.Error("error adding release to release vector", "repo", params.RepositoryName, "tag", extractTag(payload), "error", err) return err } @@ -76,7 +76,7 @@ func (w *WebhookActions) ProcessTagEvent(ctx context.Context, payload *glwebhook } if err := g.Wait(); err != nil { - w.logger.Errorw("errors processing event", "error", err) + w.logger.Error("errors processing event", "error", err) } } diff --git a/pkg/webhooks/gitlab/gitlab.go b/pkg/webhooks/gitlab/gitlab.go index 2239208..9e4c805 100644 --- a/pkg/webhooks/gitlab/gitlab.go +++ b/pkg/webhooks/gitlab/gitlab.go @@ -3,13 +3,13 @@ package gitlab import ( "context" "errors" + "log/slog" "net/http" glwebhooks "github.com/go-playground/webhooks/v6/gitlab" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/webhooks/gitlab/actions" - "go.uber.org/zap" ) var ( @@ -19,14 +19,14 @@ var ( ) type Webhook struct { - logger *zap.SugaredLogger + logger *slog.Logger cs clients.ClientMap hook *glwebhooks.Webhook a *actions.WebhookActions } // NewGitlabWebhook returns a new webhook controller -func NewGitlabWebhook(logger *zap.SugaredLogger, w config.Webhook, cs clients.ClientMap) (*Webhook, error) { +func NewGitlabWebhook(logger *slog.Logger, w config.Webhook, cs clients.ClientMap) (*Webhook, error) { hook, err := glwebhooks.New(glwebhooks.Options.Secret(w.Secret)) if err != nil { return nil, err @@ -52,10 +52,10 @@ func (w *Webhook) Handle(response http.ResponseWriter, request *http.Request) { payload, err := w.hook.Parse(request, listenEvents...) if err != nil { if errors.Is(err, glwebhooks.ErrEventNotFound) { - w.logger.Warnw("received unregistered gitlab event", "error", err) + w.logger.Warn("received unregistered gitlab event", "error", err) response.WriteHeader(http.StatusOK) } else { - w.logger.Errorw("received malformed gitlab event", "error", err) + w.logger.Error("received malformed gitlab event", "error", err) response.WriteHeader(http.StatusInternalServerError) } return @@ -64,11 +64,11 @@ func (w *Webhook) Handle(response http.ResponseWriter, request *http.Request) { ctx := context.Background() switch payload := payload.(type) { case glwebhooks.TagEventPayload: - w.logger.Debugw("received tag push event") + w.logger.Debug("received tag push event") // nolint:contextcheck w.a.ProcessTagEvent(ctx, &payload) default: - w.logger.Warnw("missing handler", "payload", payload) + w.logger.Warn("missing handler", "payload", payload) } response.WriteHeader(http.StatusOK)