From 35f54042ce57ba1eed65f4399746fb103fc13f31 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 30 Nov 2024 10:18:17 +0100 Subject: [PATCH 01/22] Move pipeline logs command (#4480) --- cli/pipeline/log/log.go | 1 + cli/pipeline/{logs.go => log/log_show.go} | 20 ++++++++++---------- cli/pipeline/pipeline.go | 1 - docs/src/pages/migrations.md | 1 + 4 files changed, 12 insertions(+), 11 deletions(-) rename cli/pipeline/{logs.go => log/log_show.go} (84%) diff --git a/cli/pipeline/log/log.go b/cli/pipeline/log/log.go index 2ca1e1c90..4ea569d79 100644 --- a/cli/pipeline/log/log.go +++ b/cli/pipeline/log/log.go @@ -23,6 +23,7 @@ var Command = &cli.Command{ Name: "log", Usage: "manage logs", Commands: []*cli.Command{ + logShowCmd, logPurgeCmd, }, } diff --git a/cli/pipeline/logs.go b/cli/pipeline/log/log_show.go similarity index 84% rename from cli/pipeline/logs.go rename to cli/pipeline/log/log_show.go index f7725bc46..e9de7a747 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/log/log_show.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package pipeline +package log import ( "context" @@ -27,14 +27,14 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) -var pipelineLogsCmd = &cli.Command{ - Name: "logs", +var logShowCmd = &cli.Command{ + Name: "show", Usage: "show pipeline logs", ArgsUsage: " [step-number|step-name]", - Action: pipelineLogs, + Action: logShow, } -func pipelineLogs(ctx context.Context, c *cli.Command) error { +func logShow(ctx context.Context, c *cli.Command) error { repoIDOrFullName := c.Args().First() client, err := internal.NewClient(ctx, c) if err != nil { @@ -59,17 +59,17 @@ func pipelineLogs(ctx context.Context, c *cli.Command) error { stepArg := c.Args().Get(2) //nolint:mnd if len(stepArg) == 0 { - return showPipelineLog(client, repoID, number) + return pipelineLog(client, repoID, number) } step, err := internal.ParseStep(client, repoID, number, stepArg) if err != nil { return fmt.Errorf("invalid step '%s': %w", stepArg, err) } - return showStepLog(client, repoID, number, step) + return stepLog(client, repoID, number, step) } -func showPipelineLog(client woodpecker.Client, repoID, number int64) error { +func pipelineLog(client woodpecker.Client, repoID, number int64) error { pipeline, err := client.Pipeline(repoID, number) if err != nil { return err @@ -85,7 +85,7 @@ func showPipelineLog(client woodpecker.Client, repoID, number int64) error { if err := tmpl.Execute(os.Stdout, map[string]any{"workflow": workflow, "step": step}); err != nil { return err } - err := showStepLog(client, repoID, number, step.ID) + err := stepLog(client, repoID, number, step.ID) if err != nil { return err } @@ -95,7 +95,7 @@ func showPipelineLog(client woodpecker.Client, repoID, number int64) error { return nil } -func showStepLog(client woodpecker.Client, repoID, number, step int64) error { +func stepLog(client woodpecker.Client, repoID, number, step int64) error { logs, err := client.StepLogEntries(repoID, number, step) if err != nil { return err diff --git a/cli/pipeline/pipeline.go b/cli/pipeline/pipeline.go index c49107652..abc892600 100644 --- a/cli/pipeline/pipeline.go +++ b/cli/pipeline/pipeline.go @@ -35,7 +35,6 @@ var Command = &cli.Command{ Commands: []*cli.Command{ buildPipelineListCmd(), pipelineLastCmd, - pipelineLogsCmd, pipelineInfoCmd, pipelineStopCmd, pipelineStartCmd, diff --git a/docs/src/pages/migrations.md b/docs/src/pages/migrations.md index 0de359e06..a45c6cca1 100644 --- a/docs/src/pages/migrations.md +++ b/docs/src/pages/migrations.md @@ -42,6 +42,7 @@ This will be the next version of Woodpecker. - `woodpecker-cli log` is now `woodpecker-cli pipeline log` - `woodpecker-cli cron` is now `woodpecker-cli repo cron` - `woodpecker-cli secret [add|rm|...] --repository` is now `woodpecker-cli repo secret [add|rm|...]` + - `woodpecker-cli pipeline logs` is now `woodpecker-cli pipeline log show` ## Admin migrations From 3c938e2b4680b6be84e47cc44e526703a782f0c8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 30 Nov 2024 11:57:50 +0100 Subject: [PATCH 02/22] fix(deps): update golang-packages (#4477) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: qwerty287 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e71e692a5..5eb7972e7 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( github.com/swaggo/gin-swagger v1.6.0 github.com/swaggo/swag v1.16.4 github.com/urfave/cli-docs/v3 v3.0.0-alpha6 - github.com/urfave/cli/v3 v3.0.0-alpha9.6 + github.com/urfave/cli/v3 v3.0.0-alpha9.10 github.com/xanzy/go-gitlab v0.114.0 github.com/xeipuuv/gojsonschema v1.2.0 github.com/yaronf/httpsign v0.3.1 diff --git a/go.sum b/go.sum index 9b7c27b46..9095124ff 100644 --- a/go.sum +++ b/go.sum @@ -545,8 +545,8 @@ github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1 github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -github.com/urfave/cli/v3 v3.0.0-alpha9.6 h1:MvGvMfcbnEBNBDkH7melypUZ9Rc1RYnQuLvNRTZFsbs= -github.com/urfave/cli/v3 v3.0.0-alpha9.6/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= +github.com/urfave/cli/v3 v3.0.0-alpha9.10 h1:whPwidq9cUh18NBqzSR8N3tts8NiQDsTmt9s7AyX85c= +github.com/urfave/cli/v3 v3.0.0-alpha9.10/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xanzy/go-gitlab v0.114.0 h1:0wQr/KBckwrZPfEMjRqpUz0HmsKKON9UhCYv9KDy19M= From 5149d3eda47643e8c9d73f8435469a325a7acd69 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 30 Nov 2024 13:57:59 +0100 Subject: [PATCH 03/22] Add pipeline purge command to cli (#4470) --- cli/pipeline/kill.go | 2 +- cli/pipeline/list.go | 4 +- cli/pipeline/list_test.go | 4 +- cli/pipeline/pipeline.go | 1 + cli/pipeline/purge.go | 156 +++++++++++++++++++++++ cli/pipeline/purge_test.go | 105 +++++++++++++++ woodpecker-go/woodpecker/interface.go | 5 +- woodpecker-go/woodpecker/mocks/client.go | 6 +- woodpecker-go/woodpecker/repo.go | 14 +- 9 files changed, 279 insertions(+), 18 deletions(-) create mode 100644 cli/pipeline/purge.go create mode 100644 cli/pipeline/purge_test.go diff --git a/cli/pipeline/kill.go b/cli/pipeline/kill.go index 872719765..839d7c75e 100644 --- a/cli/pipeline/kill.go +++ b/cli/pipeline/kill.go @@ -48,7 +48,7 @@ func pipelineKill(ctx context.Context, c *cli.Command) (err error) { return err } - err = client.PipelineKill(repoID, number) + err = client.PipelineDelete(repoID, number) if err != nil { return err } diff --git a/cli/pipeline/list.go b/cli/pipeline/list.go index ceadc9777..bfd24981b 100644 --- a/cli/pipeline/list.go +++ b/cli/pipeline/list.go @@ -77,14 +77,14 @@ func List(ctx context.Context, c *cli.Command) error { if err != nil { return err } - resources, err := pipelineList(ctx, c, client) + resources, err := pipelineList(c, client) if err != nil { return err } return pipelineOutput(c, resources) } -func pipelineList(_ context.Context, c *cli.Command, client woodpecker.Client) ([]woodpecker.Pipeline, error) { +func pipelineList(c *cli.Command, client woodpecker.Client) ([]woodpecker.Pipeline, error) { resources := make([]woodpecker.Pipeline, 0) repoIDOrFullName := c.Args().First() diff --git a/cli/pipeline/list_test.go b/cli/pipeline/list_test.go index 20ebefb30..e73bffe57 100644 --- a/cli/pipeline/list_test.go +++ b/cli/pipeline/list_test.go @@ -112,8 +112,8 @@ func TestPipelineList(t *testing.T) { command := buildPipelineListCmd() command.Writer = io.Discard - command.Action = func(ctx context.Context, c *cli.Command) error { - pipelines, err := pipelineList(ctx, c, mockClient) + command.Action = func(_ context.Context, c *cli.Command) error { + pipelines, err := pipelineList(c, mockClient) if tt.wantErr != nil { assert.EqualError(t, err, tt.wantErr.Error()) return nil diff --git a/cli/pipeline/pipeline.go b/cli/pipeline/pipeline.go index abc892600..866158e88 100644 --- a/cli/pipeline/pipeline.go +++ b/cli/pipeline/pipeline.go @@ -46,6 +46,7 @@ var Command = &cli.Command{ pipelineCreateCmd, log.Command, deploy.Command, + pipelinePurgeCmd, }, } diff --git a/cli/pipeline/purge.go b/cli/pipeline/purge.go new file mode 100644 index 000000000..759b9cbf2 --- /dev/null +++ b/cli/pipeline/purge.go @@ -0,0 +1,156 @@ +// Copyright 2022 Woodpecker Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pipeline + +import ( + "context" + "fmt" + "time" + + "github.com/rs/zerolog/log" + "github.com/urfave/cli/v3" + + "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + shared_utils "go.woodpecker-ci.org/woodpecker/v2/shared/utils" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" +) + +//nolint:mnd +var pipelinePurgeCmd = &cli.Command{ + Name: "purge", + Usage: "purge pipelines", + ArgsUsage: "", + Action: Purge, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "older-than", + Usage: "remove pipelines older than the specified time limit", + Required: true, + }, + &cli.IntFlag{ + Name: "keep-min", + Usage: "minimum number of pipelines to keep", + Value: 10, + }, + &cli.BoolFlag{ + Name: "dry-run", + Usage: "disable non-read api calls", + Value: false, + }, + }, +} + +func Purge(ctx context.Context, c *cli.Command) error { + client, err := internal.NewClient(ctx, c) + if err != nil { + return err + } + return pipelinePurge(c, client) +} + +func pipelinePurge(c *cli.Command, client woodpecker.Client) (err error) { + repoIDOrFullName := c.Args().First() + if len(repoIDOrFullName) == 0 { + return fmt.Errorf("missing required argument repo-id / repo-full-name") + } + repoID, err := internal.ParseRepo(client, repoIDOrFullName) + if err != nil { + return fmt.Errorf("invalid repo '%s': %w", repoIDOrFullName, err) + } + + olderThan := c.String("older-than") + keepMin := c.Int("keep-min") + dryRun := c.Bool("dry-run") + + duration, err := time.ParseDuration(olderThan) + if err != nil { + return err + } + + var pipelinesKeep []*woodpecker.Pipeline + + if keepMin > 0 { + pipelinesKeep, err = fetchPipelinesToKeep(client, repoID, int(keepMin)) + if err != nil { + return err + } + } + + pipelines, err := fetchPipelines(client, repoID, duration) + if err != nil { + return err + } + + // Create a map of pipeline IDs to keep + keepMap := make(map[int64]struct{}) + for _, p := range pipelinesKeep { + keepMap[p.ID] = struct{}{} + } + + // Filter pipelines to only include those not in keepMap + var pipelinesToPurge []*woodpecker.Pipeline + for _, p := range pipelines { + if _, exists := keepMap[p.ID]; !exists { + pipelinesToPurge = append(pipelinesToPurge, p) + } + } + + msgPrefix := "" + if dryRun { + msgPrefix = "DRY-RUN: " + } + + for i, p := range pipelinesToPurge { + log.Debug().Msgf("%sprune %v/%v pipelines from repo '%v'", msgPrefix, i+1, len(pipelinesToPurge), repoIDOrFullName) + if dryRun { + continue + } + + err := client.PipelineDelete(repoID, p.ID) + if err != nil { + return err + } + } + + return nil +} + +func fetchPipelinesToKeep(client woodpecker.Client, repoID int64, keepMin int) ([]*woodpecker.Pipeline, error) { + if keepMin <= 0 { + return nil, nil + } + return shared_utils.Paginate(func(page int) ([]*woodpecker.Pipeline, error) { + return client.PipelineList(repoID, + woodpecker.PipelineListOptions{ + ListOptions: woodpecker.ListOptions{ + Page: page, + }, + }, + ) + }, keepMin) +} + +func fetchPipelines(client woodpecker.Client, repoID int64, duration time.Duration) ([]*woodpecker.Pipeline, error) { + return shared_utils.Paginate(func(page int) ([]*woodpecker.Pipeline, error) { + return client.PipelineList(repoID, + woodpecker.PipelineListOptions{ + ListOptions: woodpecker.ListOptions{ + Page: page, + }, + After: time.Now().Add(-duration), + }, + ) + }, -1) +} diff --git a/cli/pipeline/purge_test.go b/cli/pipeline/purge_test.go new file mode 100644 index 000000000..be185277b --- /dev/null +++ b/cli/pipeline/purge_test.go @@ -0,0 +1,105 @@ +package pipeline + +import ( + "context" + "errors" + "io" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/urfave/cli/v3" + + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker/mocks" +) + +func TestPipelinePurge(t *testing.T) { + tests := []struct { + name string + repoID int64 + args []string + pipelinesKeep []*woodpecker.Pipeline + pipelines []*woodpecker.Pipeline + wantDelete int + wantErr error + }{ + { + name: "success with no pipelines to purge", + repoID: 1, + args: []string{"purge", "--older-than", "1h", "repo/name"}, + pipelinesKeep: []*woodpecker.Pipeline{ + {ID: 1}, + }, + pipelines: []*woodpecker.Pipeline{}, + }, + { + name: "success with pipelines to purge", + repoID: 1, + args: []string{"purge", "--older-than", "1h", "repo/name"}, + pipelinesKeep: []*woodpecker.Pipeline{ + {ID: 1}, + }, + pipelines: []*woodpecker.Pipeline{ + {ID: 1}, + {ID: 2}, + {ID: 3}, + }, + wantDelete: 2, + }, + { + name: "error on invalid duration", + repoID: 1, + args: []string{"purge", "--older-than", "invalid", "repo/name"}, + wantErr: errors.New("time: invalid duration \"invalid\""), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mockClient := mocks.NewClient(t) + mockClient.On("RepoLookup", mock.Anything).Maybe().Return(&woodpecker.Repo{ID: tt.repoID}, nil) + + mockClient.On("PipelineList", mock.Anything, mock.Anything).Return(func(_ int64, opt woodpecker.PipelineListOptions) ([]*woodpecker.Pipeline, error) { + // Return keep pipelines for first call + if opt.After.IsZero() { + if opt.Page == 1 { + return tt.pipelinesKeep, nil + } + return []*woodpecker.Pipeline{}, nil + } + + // Return pipelines to purge for calls with After filter + if !opt.After.IsZero() { + if opt.Page == 1 { + return tt.pipelines, nil + } + return []*woodpecker.Pipeline{}, nil + } + + return []*woodpecker.Pipeline{}, nil + }).Maybe() + + if tt.wantDelete > 0 { + mockClient.On("PipelineDelete", tt.repoID, mock.Anything).Return(nil).Times(tt.wantDelete) + } + + command := pipelinePurgeCmd + command.Writer = io.Discard + command.Action = func(_ context.Context, c *cli.Command) error { + err := pipelinePurge(c, mockClient) + + if tt.wantErr != nil { + assert.EqualError(t, err, tt.wantErr.Error()) + return nil + } + + assert.NoError(t, err) + + return nil + } + + _ = command.Run(context.Background(), tt.args) + }) + } +} diff --git a/woodpecker-go/woodpecker/interface.go b/woodpecker-go/woodpecker/interface.go index 611318e31..4f29717fd 100644 --- a/woodpecker-go/woodpecker/interface.go +++ b/woodpecker-go/woodpecker/interface.go @@ -84,6 +84,8 @@ type Client interface { // the specified repository. PipelineList(repoID int64, opt PipelineListOptions) ([]*Pipeline, error) + PipelineDelete(repoID, pipeline int64) error + // PipelineQueue returns a list of enqueued pipelines. PipelineQueue() ([]*Feed, error) @@ -102,9 +104,6 @@ type Client interface { // PipelineDecline declines a blocked pipeline. PipelineDecline(repoID, pipeline int64) (*Pipeline, error) - // PipelineKill force kills the running pipeline. - PipelineKill(repoID, pipeline int64) error - // PipelineMetadata returns metadata for a pipeline. PipelineMetadata(repoID int64, pipelineNumber int) ([]byte, error) diff --git a/woodpecker-go/woodpecker/mocks/client.go b/woodpecker-go/woodpecker/mocks/client.go index 0ce17b6e0..0a2e72f87 100644 --- a/woodpecker-go/woodpecker/mocks/client.go +++ b/woodpecker-go/woodpecker/mocks/client.go @@ -1133,12 +1133,12 @@ func (_m *Client) PipelineDecline(repoID int64, pipeline int64) (*woodpecker.Pip return r0, r1 } -// PipelineKill provides a mock function with given fields: repoID, pipeline -func (_m *Client) PipelineKill(repoID int64, pipeline int64) error { +// PipelineDelete provides a mock function with given fields: repoID, pipeline +func (_m *Client) PipelineDelete(repoID int64, pipeline int64) error { ret := _m.Called(repoID, pipeline) if len(ret) == 0 { - panic("no return value specified for PipelineKill") + panic("no return value specified for PipelineDelete") } var r0 error diff --git a/woodpecker-go/woodpecker/repo.go b/woodpecker-go/woodpecker/repo.go index af5d0ca95..5c24b228d 100644 --- a/woodpecker-go/woodpecker/repo.go +++ b/woodpecker-go/woodpecker/repo.go @@ -321,6 +321,13 @@ func (c *client) PipelineList(repoID int64, opt PipelineListOptions) ([]*Pipelin return out, err } +// PipelineDelete deletes a pipeline by the specified repository ID and pipeline ID. +func (c *client) PipelineDelete(repoID, pipeline int64) error { + uri := fmt.Sprintf(pathPipeline, c.addr, repoID, pipeline) + err := c.delete(uri) + return err +} + // PipelineCreate creates a new pipeline for the specified repository. func (c *client) PipelineCreate(repoID int64, options *PipelineOptions) (*Pipeline, error) { var out *Pipeline @@ -361,13 +368,6 @@ func (c *client) PipelineDecline(repoID, pipeline int64) (*Pipeline, error) { return out, err } -// PipelineKill force kills the running pipeline. -func (c *client) PipelineKill(repoID, pipeline int64) error { - uri := fmt.Sprintf(pathPipeline, c.addr, repoID, pipeline) - err := c.delete(uri) - return err -} - // LogsPurge purges the pipeline all steps logs for the specified pipeline. func (c *client) LogsPurge(repoID, pipeline int64) error { uri := fmt.Sprintf(pathPipelineLogs, c.addr, repoID, pipeline) From 1d7cfad166caa6bfcccbd7bdf857fb0dea3f040d Mon Sep 17 00:00:00 2001 From: Fjuro Date: Sat, 30 Nov 2024 10:37:09 +0000 Subject: [PATCH 04/22] Translated using Weblate (Czech) Currently translated at 60.8% (216 of 355 strings) Translation: Woodpecker CI/UI Translate-URL: http://translate.woodpecker-ci.org/projects/woodpecker-ci/ui/cs/ --- web/src/assets/locales/cs.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/src/assets/locales/cs.json b/web/src/assets/locales/cs.json index a342567b0..242e2aa2f 100644 --- a/web/src/assets/locales/cs.json +++ b/web/src/assets/locales/cs.json @@ -17,7 +17,7 @@ "delete_agent": "Odstranit agent", "delete_confirm": "Opravdu chcete tohoto agenta odstranit? Už se nebude moci připojit k serveru.", "deleted": "Agent smazán", - "desc": "Agenti registrovaní pro tento server", + "desc": "Agenti registrovaní na tomto serveru.", "edit_agent": "Upravit agent", "id": "ID", "last_contact": "Poslední kontakt", @@ -41,12 +41,12 @@ "token": "Tokeny", "version": "Verze" }, - "not_allowed": "Nemáte povolen přístup k nastavení serveru", + "not_allowed": "K nastavení serveru nemáte přístup.", "orgs": { "delete_confirm": "Opravdu chcete tuto organizaci smazat? Tím se odstraní také všechna úložiště vlastněná touto organizací.", "delete_org": "Odstranit organizaci", "deleted": "Organizace vymazána", - "desc": "Organizace vlastnící úložiště na tomto serveru", + "desc": "Organizace vlastnící repozitáře na tomto serveru.", "none": "Zatím neexistují žádné organizace.", "org_settings": "Organizační nastavení", "orgs": "Organizace", @@ -74,7 +74,7 @@ "waiting_for": "čekání na" }, "repos": { - "desc": "Úložiště, která jsou nebo byla na tomto serveru povolena", + "desc": "Repozitáře, které jsou nebo byly na tomto serveru povoleny.", "disabled": "Bezbariérový", "none": "Zatím neexistují žádná úložiště.", "repos": "Repozitáře", @@ -198,7 +198,7 @@ "success": "Repozitář povoleno" }, "manual_pipeline": { - "select_branch": "Vyberte pobočku", + "select_branch": "Vyberte větev", "title": "Spuštění ručního spuštění potrubí", "trigger": "Spustit potrubí", "variables": { From 7309ba0a825e66e7a97e6b151956e3c33fb3dc01 Mon Sep 17 00:00:00 2001 From: Tamas Kiss Date: Sat, 30 Nov 2024 09:58:42 +0000 Subject: [PATCH 05/22] Translated using Weblate (Hungarian) Currently translated at 9.2% (33 of 355 strings) Translation: Woodpecker CI/UI Translate-URL: http://translate.woodpecker-ci.org/projects/woodpecker-ci/ui/hu/ --- web/src/assets/locales/hu.json | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/web/src/assets/locales/hu.json b/web/src/assets/locales/hu.json index 0967ef424..1a2be04bf 100644 --- a/web/src/assets/locales/hu.json +++ b/web/src/assets/locales/hu.json @@ -1 +1,67 @@ -{} +{ + "back": "Vissza", + "logout": "Kijelentkezés", + "search": "Keresés…", + "username": "Felhasználónév", + "unknown_error": "Ismeretlen hiba történt", + "password": "Jelszó", + "repo": { + "visibility": { + "public": { + "public": "Nyilvános" + }, + "private": { + "private": "Privát", + "desc": "Csak te és a többi tulajdonos láthatjátok ezt a projektet a tárolóban." + }, + "internal": { + "internal": "Belső" + } + }, + "settings": { + "general": { + "timeout": { + "minutes": "percek" + }, + "save": "Beállítások mentése", + "project": "Projekt beállítások", + "success": "Projekt beállítások frissítve" + }, + "actions": { + "disable": { + "disable": "Tároló inaktiválása" + }, + "delete": { + "delete": "Tároló törlése" + } + } + }, + "pipeline": { + "loading": "Betöltés…" + } + }, + "admin": { + "settings": { + "users": { + "show": "Mutasd a felhasználokat", + "cancel": "Mégse", + "save": "Felhasználó mentése", + "add": "Felhasználó hozzáadása", + "deleted": "Felhasználó törölve", + "created": "Felhasználó létrehozva", + "saved": "Felhasználó mentve", + "delete_user": "Felhasználó törlése", + "edit_user": "Felhasználó szerkesztése" + }, + "orgs": { + "orgs": "Szervezetek", + "delete_org": "Szervezet törlése" + } + } + }, + "cancel": "Mégse", + "login": "Bejelentkezés", + "internal_error": "Valamilyen belső hiba történt", + "info": "Információ", + "registration_closed": "A regisztráció zárva" +} From 9a8d7d883857035c924520e174ed1de0ae8ce91b Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Sat, 30 Nov 2024 16:17:59 +0200 Subject: [PATCH 06/22] Use JS-native date/time formatting (#4488) --- web/.gitignore | 1 - web/.prettierignore | 1 - web/eslint.config.js | 1 - web/package.json | 2 - web/pnpm-lock.yaml | 28 --------- web/src/assets/locales/en.json | 4 +- web/src/compositions/useDate.ts | 102 ++++++++++++++++++++++++-------- web/vite.config.ts | 41 +------------ 8 files changed, 79 insertions(+), 101 deletions(-) diff --git a/web/.gitignore b/web/.gitignore index 4998cb543..d451ff16c 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -3,4 +3,3 @@ node_modules dist dist-ssr *.local -src/assets/dayjsLocales diff --git a/web/.prettierignore b/web/.prettierignore index 203898907..2087370c5 100644 --- a/web/.prettierignore +++ b/web/.prettierignore @@ -4,5 +4,4 @@ coverage/ LICENSE components.d.ts src/assets/locales/*.json -src/assets/dayjsLocales/ !src/assets/locales/en.json diff --git a/web/eslint.config.js b/web/eslint.config.js index 1b704b719..ac3bf0827 100644 --- a/web/eslint.config.js +++ b/web/eslint.config.js @@ -106,7 +106,6 @@ export default antfu( 'tsconfig.json', 'src/assets/locales/**/*', '!src/assets/locales/en.json', - 'src/assets/dayjsLocales/', 'components.d.ts', ], }, diff --git a/web/package.json b/web/package.json index 83ff5fb20..8cd959870 100644 --- a/web/package.json +++ b/web/package.json @@ -23,7 +23,6 @@ "@mdi/js": "^7.4.47", "@vueuse/core": "^12.0.0", "ansi_up": "^6.0.2", - "dayjs": "^1.11.12", "dompurify": "^3.2.0", "fuse.js": "^7.0.0", "js-base64": "^3.7.7", @@ -57,7 +56,6 @@ "eslint-plugin-vue-scoped-css": "^2.8.1", "jsdom": "^25.0.0", "prettier": "^3.3.3", - "replace-in-file": "^8.1.0", "tinycolor2": "^1.6.0", "typescript": "5.6.3", "vite": "^5.4.1", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index de6da3438..369877a2c 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: ansi_up: specifier: ^6.0.2 version: 6.0.2 - dayjs: - specifier: ^1.11.12 - version: 1.11.13 dompurify: specifier: ^3.2.0 version: 3.2.1 @@ -123,9 +120,6 @@ importers: prettier: specifier: ^3.3.3 version: 3.3.3 - replace-in-file: - specifier: ^8.1.0 - version: 8.2.0 tinycolor2: specifier: ^1.6.0 version: 1.6.0 @@ -1107,10 +1101,6 @@ packages: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} engines: {node: '>=10'} - chalk@5.3.0: - resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} - engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - char-regex@1.0.2: resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} engines: {node: '>=10'} @@ -1214,9 +1204,6 @@ packages: resolution: {integrity: sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==} engines: {node: '>=18'} - dayjs@1.11.13: - resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==} - de-indent@1.0.2: resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} @@ -2295,11 +2282,6 @@ packages: resolution: {integrity: sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==} hasBin: true - replace-in-file@8.2.0: - resolution: {integrity: sha512-hMsQtdYHwWviQT5ZbNsgfu0WuCiNlcUSnnD+aHAL081kbU9dPkPocDaHlDvAHKydTWWpx1apfcEcmvIyQk3CpQ==} - engines: {node: '>=18'} - hasBin: true - require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -3798,8 +3780,6 @@ snapshots: ansi-styles: 4.3.0 supports-color: 7.2.0 - chalk@5.3.0: {} - char-regex@1.0.2: {} character-entities@2.0.2: {} @@ -3898,8 +3878,6 @@ snapshots: whatwg-mimetype: 4.0.0 whatwg-url: 14.0.0 - dayjs@1.11.13: {} - de-indent@1.0.2: {} debug@3.2.7: @@ -5205,12 +5183,6 @@ snapshots: dependencies: jsesc: 0.5.0 - replace-in-file@8.2.0: - dependencies: - chalk: 5.3.0 - glob: 10.4.5 - yargs: 17.7.2 - require-directory@2.1.1: {} resolve-from@4.0.0: {} diff --git a/web/src/assets/locales/en.json b/web/src/assets/locales/en.json index cba931e00..f02638fea 100644 --- a/web/src/assets/locales/en.json +++ b/web/src/assets/locales/en.json @@ -24,8 +24,8 @@ "not_found": "Server could not find requested object" }, "time": { - "template": "MMM D, YYYY, HH:mm z", - "not_started": "not started yet" + "not_started": "not started yet", + "just_now": "just now" }, "repo": { "manual_pipeline": { diff --git a/web/src/compositions/useDate.ts b/web/src/compositions/useDate.ts index c467a244e..0c1a75821 100644 --- a/web/src/compositions/useDate.ts +++ b/web/src/compositions/useDate.ts @@ -1,44 +1,94 @@ -import dayjs from 'dayjs'; -import advancedFormat from 'dayjs/plugin/advancedFormat'; -import duration from 'dayjs/plugin/duration'; -import relativeTime from 'dayjs/plugin/relativeTime'; -import timezone from 'dayjs/plugin/timezone'; -import utc from 'dayjs/plugin/utc'; import { useI18n } from 'vue-i18n'; -dayjs.extend(timezone); -dayjs.extend(utc); -dayjs.extend(advancedFormat); -dayjs.extend(relativeTime); -dayjs.extend(duration); +let currentLocale = 'en'; -function toLocaleString(date: Date) { - return dayjs(date).format(useI18n().t('time.template')); +function splitDuration(durationMs: number) { + const totalSeconds = durationMs / 1000; + const totalMinutes = totalSeconds / 60; + const totalHours = totalMinutes / 60; + + const seconds = Math.floor(totalSeconds) % 60; + const minutes = Math.floor(totalMinutes) % 60; + const hours = Math.floor(totalHours) % 24; + + return { + seconds, + minutes, + hours, + totalHours, + totalMinutes, + totalSeconds, + }; } -function timeAgo(date: Date | string | number) { - return dayjs().to(dayjs(date)); +function toLocaleString(date: Date) { + return date.toLocaleString(currentLocale, { + dateStyle: 'short', + timeStyle: 'short', + }); +} + +function timeAgo(date: number) { + const seconds = Math.floor((new Date().getTime() - date) / 1000); + + const formatter = new Intl.RelativeTimeFormat(currentLocale); + + let interval = seconds / 31536000; + if (interval > 1) { + return formatter.format(-Math.round(interval), 'year'); + } + interval = seconds / 2592000; + if (interval > 1) { + return formatter.format(-Math.round(interval), 'month'); + } + interval = seconds / 86400; + if (interval > 1) { + return formatter.format(-Math.round(interval), 'day'); + } + interval = seconds / 3600; + if (interval > 1) { + return formatter.format(-Math.round(interval), 'hour'); + } + interval = seconds / 60; + if (interval > 0.5) { + return formatter.format(-Math.round(interval), 'minute'); + } + return useI18n().t('time.just_now'); } function prettyDuration(durationMs: number) { - return dayjs.duration(durationMs).humanize(); + const t = splitDuration(durationMs); + + if (t.totalHours > 1) { + return Intl.NumberFormat(currentLocale, { style: 'unit', unit: 'hour', unitDisplay: 'long' }).format( + Math.round(t.totalHours), + ); + } + if (t.totalMinutes > 1) { + return Intl.NumberFormat(currentLocale, { style: 'unit', unit: 'minute', unitDisplay: 'long' }).format( + Math.round(t.totalMinutes), + ); + } + return Intl.NumberFormat(currentLocale, { style: 'unit', unit: 'second', unitDisplay: 'long' }).format( + Math.round(t.totalSeconds), + ); } function durationAsNumber(durationMs: number): string { - const dur = dayjs.duration(durationMs); - return dur.format(dur.hours() > 1 ? 'HH:mm:ss' : 'mm:ss'); + const { seconds, minutes, hours } = splitDuration(durationMs); + + const minSecFormat = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; + + if (hours > 0) { + return `${hours.toString().padStart(2, '0')}:${minSecFormat}`; + } + + return minSecFormat; } export function useDate() { - const addedLocales = ['en']; - async function setDayjsLocale(locale: string) { - if (!addedLocales.includes(locale)) { - const l = (await import(`~/assets/dayjsLocales/${locale}.js`)) as { default: string }; - dayjs.locale(l.default); - } else { - dayjs.locale(locale); - } + currentLocale = locale; } return { diff --git a/web/vite.config.ts b/web/vite.config.ts index 45fe7ba40..1b71b4bf9 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,9 +1,8 @@ -import { copyFile, existsSync, mkdirSync, readdirSync } from 'node:fs'; +import { readdirSync } from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'; import vue from '@vitejs/plugin-vue'; -import { replaceInFileSync } from 'replace-in-file'; import type { Plugin } from 'vite'; import prismjs from 'vite-plugin-prismjs'; import WindiCSS from 'vite-plugin-windicss'; @@ -54,44 +53,6 @@ export default defineConfig({ const filenames = readdirSync('src/assets/locales/').map((filename) => filename.replace('.json', '')); - if (!existsSync('src/assets/dayjsLocales')) { - mkdirSync('src/assets/dayjsLocales'); - } - - filenames.forEach((name) => { - // English is always directly loaded (compiled by Vite) and thus not copied - if (name === 'en') { - return; - } - let langName = name; - - // copy dayjs language - if (name === 'zh-Hans') { - // zh-Hans is called zh in dayjs - langName = 'zh'; - } else if (name === 'zh-Hant') { - // zh-Hant is called zh-cn in dayjs - langName = 'zh-cn'; - } - - copyFile( - `node_modules/dayjs/esm/locale/${langName}.js`, - `src/assets/dayjsLocales/${name}.js`, - // eslint-disable-next-line promise/prefer-await-to-callbacks - (err) => { - if (err) { - throw err; - } - }, - ); - }); - replaceInFileSync({ - files: 'src/assets/dayjsLocales/*.js', - // remove any dayjs import and any dayjs.locale call - from: /(?:import dayjs.*'|dayjs\.locale.*);/g, - to: '', - }); - return { name: 'vue-i18n-supported-locales', From 57e7572b6f64aa6904a6c5dd731e6899b5c27f68 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 30 Nov 2024 15:23:44 +0100 Subject: [PATCH 07/22] Unify cli commands and flags (#4481) - Unify command and flag descriptions - Unify logs - Rename `woodpecker-cli [registry|ssecret|...] info` commands to `woodpecker-cli [registry|ssecret|...] show` --- cli/admin/loglevel/loglevel.go | 4 ++-- cli/admin/registry/registry.go | 2 +- cli/admin/registry/registry_add.go | 2 +- .../{registry_info.go => registry_show.go} | 10 +++++----- cli/admin/secret/secret.go | 2 +- cli/admin/secret/secret_add.go | 2 +- .../secret/{secret_info.go => secret_show.go} | 10 +++++----- cli/admin/user/user.go | 2 +- cli/admin/user/user_add.go | 2 +- cli/admin/user/{user_info.go => user_show.go} | 10 +++++----- cli/common/hooks.go | 10 +++++----- cli/internal/config/config.go | 16 ++++++++-------- cli/lint/lint.go | 4 ++-- cli/org/registry/registry.go | 2 +- cli/org/registry/registry_add.go | 2 +- .../{registry_info.go => registry_show.go} | 10 +++++----- cli/org/secret/secret.go | 2 +- cli/org/secret/secret_add.go | 2 +- cli/org/secret/secret_set.go | 4 ++-- .../secret/{secret_info.go => secret_show.go} | 10 +++++----- cli/pipeline/deploy/deploy.go | 2 +- cli/pipeline/last.go | 2 +- cli/pipeline/list.go | 4 ++-- cli/pipeline/pipeline.go | 2 +- cli/pipeline/{info.go => show.go} | 10 +++++----- cli/pipeline/start.go | 2 +- cli/repo/cron/cron.go | 2 +- cli/repo/cron/{cron_info.go => cron_show.go} | 10 +++++----- cli/repo/registry/registry.go | 2 +- cli/repo/registry/registry_add.go | 2 +- .../{registry_info.go => registry_show.go} | 10 +++++----- cli/repo/repo.go | 2 +- cli/repo/{repo_info.go => repo_show.go} | 10 +++++----- cli/repo/repo_update.go | 4 ++-- cli/repo/secret/secret.go | 2 +- cli/repo/secret/secret_add.go | 6 +++--- cli/repo/secret/secret_set.go | 4 ++-- .../secret/{secret_info.go => secret_show.go} | 10 +++++----- cli/setup/setup.go | 8 ++++---- cli/setup/token_fetcher.go | 8 ++++---- cli/update/command.go | 10 +++++----- cli/update/updater.go | 16 ++++++++-------- docs/src/pages/migrations.md | 1 + 43 files changed, 119 insertions(+), 118 deletions(-) rename cli/admin/registry/{registry_info.go => registry_show.go} (88%) rename cli/admin/secret/{secret_info.go => secret_show.go} (88%) rename cli/admin/user/{user_info.go => user_show.go} (88%) rename cli/org/registry/{registry_info.go => registry_show.go} (88%) rename cli/org/secret/{secret_info.go => secret_show.go} (89%) rename cli/pipeline/{info.go => show.go} (90%) rename cli/repo/cron/{cron_info.go => cron_show.go} (89%) rename cli/repo/registry/{registry_info.go => registry_show.go} (88%) rename cli/repo/{repo_info.go => repo_show.go} (90%) rename cli/repo/secret/{secret_info.go => secret_show.go} (89%) diff --git a/cli/admin/loglevel/loglevel.go b/cli/admin/loglevel/loglevel.go index 947e99eaf..323974d01 100644 --- a/cli/admin/loglevel/loglevel.go +++ b/cli/admin/loglevel/loglevel.go @@ -29,7 +29,7 @@ import ( var Command = &cli.Command{ Name: "log-level", ArgsUsage: "[level]", - Usage: "get the logging level of the server, or set it with [level]", + Usage: "retrieve log level from server, or set it with [level]", Action: logLevel, } @@ -59,6 +59,6 @@ func logLevel(ctx context.Context, c *cli.Command) error { } } - log.Info().Msgf("logging level: %s", ll.Level) + log.Info().Msgf("log level: %s", ll.Level) return nil } diff --git a/cli/admin/registry/registry.go b/cli/admin/registry/registry.go index 3d9c4de50..1717803c6 100644 --- a/cli/admin/registry/registry.go +++ b/cli/admin/registry/registry.go @@ -26,7 +26,7 @@ var Command = &cli.Command{ registryCreateCmd, registryDeleteCmd, registryUpdateCmd, - registryInfoCmd, + registryShowCmd, registryListCmd, }, } diff --git a/cli/admin/registry/registry_add.go b/cli/admin/registry/registry_add.go index a378a8a2f..b09f8a74e 100644 --- a/cli/admin/registry/registry_add.go +++ b/cli/admin/registry/registry_add.go @@ -27,7 +27,7 @@ import ( var registryCreateCmd = &cli.Command{ Name: "add", - Usage: "adds a registry", + Usage: "add a registry", Action: registryCreate, Flags: []cli.Flag{ &cli.StringFlag{ diff --git a/cli/admin/registry/registry_info.go b/cli/admin/registry/registry_show.go similarity index 88% rename from cli/admin/registry/registry_info.go rename to cli/admin/registry/registry_show.go index 80b78546f..c7ae1359d 100644 --- a/cli/admin/registry/registry_info.go +++ b/cli/admin/registry/registry_show.go @@ -25,10 +25,10 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var registryInfoCmd = &cli.Command{ - Name: "info", - Usage: "display registry info", - Action: registryInfo, +var registryShowCmd = &cli.Command{ + Name: "show", + Usage: "show registry information", + Action: registryShow, Flags: []cli.Flag{ &cli.StringFlag{ Name: "hostname", @@ -39,7 +39,7 @@ var registryInfoCmd = &cli.Command{ }, } -func registryInfo(ctx context.Context, c *cli.Command) error { +func registryShow(ctx context.Context, c *cli.Command) error { var ( hostname = c.String("hostname") format = c.String("format") + "\n" diff --git a/cli/admin/secret/secret.go b/cli/admin/secret/secret.go index ffd466f94..b3496b076 100644 --- a/cli/admin/secret/secret.go +++ b/cli/admin/secret/secret.go @@ -26,7 +26,7 @@ var Command = &cli.Command{ secretCreateCmd, secretDeleteCmd, secretUpdateCmd, - secretInfoCmd, + secretShowCmd, secretListCmd, }, } diff --git a/cli/admin/secret/secret_add.go b/cli/admin/secret/secret_add.go index f2cf88c8c..07afa8134 100644 --- a/cli/admin/secret/secret_add.go +++ b/cli/admin/secret/secret_add.go @@ -27,7 +27,7 @@ import ( var secretCreateCmd = &cli.Command{ Name: "add", - Usage: "adds a secret", + Usage: "add a secret", ArgsUsage: "[repo-id|repo-full-name]", Action: secretCreate, Flags: []cli.Flag{ diff --git a/cli/admin/secret/secret_info.go b/cli/admin/secret/secret_show.go similarity index 88% rename from cli/admin/secret/secret_info.go rename to cli/admin/secret/secret_show.go index 7efdacc25..09ce610b8 100644 --- a/cli/admin/secret/secret_info.go +++ b/cli/admin/secret/secret_show.go @@ -26,11 +26,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var secretInfoCmd = &cli.Command{ - Name: "info", - Usage: "display secret info", +var secretShowCmd = &cli.Command{ + Name: "show", + Usage: "show secret information", ArgsUsage: "[repo-id|repo-full-name]", - Action: secretInfo, + Action: secretShow, Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", @@ -40,7 +40,7 @@ var secretInfoCmd = &cli.Command{ }, } -func secretInfo(ctx context.Context, c *cli.Command) error { +func secretShow(ctx context.Context, c *cli.Command) error { var ( secretName = c.String("name") format = c.String("format") + "\n" diff --git a/cli/admin/user/user.go b/cli/admin/user/user.go index 78b552b36..fe68e5d47 100644 --- a/cli/admin/user/user.go +++ b/cli/admin/user/user.go @@ -24,7 +24,7 @@ var Command = &cli.Command{ Usage: "manage users", Commands: []*cli.Command{ userListCmd, - userInfoCmd, + userShowCmd, userAddCmd, userRemoveCmd, }, diff --git a/cli/admin/user/user_add.go b/cli/admin/user/user_add.go index 80012158e..b05b5f6a9 100644 --- a/cli/admin/user/user_add.go +++ b/cli/admin/user/user_add.go @@ -26,7 +26,7 @@ import ( var userAddCmd = &cli.Command{ Name: "add", - Usage: "adds a user", + Usage: "add a user", ArgsUsage: "", Action: userAdd, } diff --git a/cli/admin/user/user_info.go b/cli/admin/user/user_show.go similarity index 88% rename from cli/admin/user/user_info.go rename to cli/admin/user/user_show.go index bfebed93f..6ed453fc8 100644 --- a/cli/admin/user/user_info.go +++ b/cli/admin/user/user_show.go @@ -26,15 +26,15 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var userInfoCmd = &cli.Command{ - Name: "info", - Usage: "show user details", +var userShowCmd = &cli.Command{ + Name: "show", + Usage: "show user information", ArgsUsage: "", - Action: userInfo, + Action: userShow, Flags: []cli.Flag{common.FormatFlag(tmplUserInfo)}, } -func userInfo(ctx context.Context, c *cli.Command) error { +func userShow(ctx context.Context, c *cli.Command) error { client, err := internal.NewClient(ctx, c) if err != nil { return err diff --git a/cli/common/hooks.go b/cli/common/hooks.go index 9ff74d1ad..d35dd2fd6 100644 --- a/cli/common/hooks.go +++ b/cli/common/hooks.go @@ -35,18 +35,18 @@ func Before(ctx context.Context, c *cli.Command) (context.Context, error) { waitForUpdateCheck, cancelWaitForUpdate = context.WithCancelCause(context.Background()) defer cancelWaitForUpdate(errors.New("update check finished")) - log.Debug().Msg("Checking for updates ...") + log.Debug().Msg("checking for updates ...") newVersion, err := update.CheckForUpdate(waitForUpdateCheck, false) //nolint:contextcheck if err != nil { - log.Error().Err(err).Msgf("Failed to check for updates") + log.Error().Err(err).Msgf("failed to check for updates") return } if newVersion != nil { - log.Warn().Msgf("A new version of woodpecker-cli is available: %s. Update by running: %s update", newVersion.Version, c.Root().Name) + log.Warn().Msgf("new version of woodpecker-cli is available: %s, update with: %s update", newVersion.Version, c.Root().Name) } else { - log.Debug().Msgf("No update required") + log.Debug().Msgf("no update required") } }(ctx) @@ -59,7 +59,7 @@ func After(_ context.Context, _ *cli.Command) error { case <-waitForUpdateCheck.Done(): // When the actual command already finished, we still wait 500ms for the update check to finish case <-time.After(time.Millisecond * 500): - log.Debug().Msg("Update check stopped due to timeout") + log.Debug().Msg("update check stopped due to timeout") cancelWaitForUpdate(errors.New("update check timeout")) } } diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index 817a859c3..274572c67 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -44,7 +44,7 @@ func Load(ctx context.Context, c *cli.Command) error { } if config.ServerURL == "" || config.Token == "" { - log.Info().Msg("The woodpecker-cli is not yet set up. Please run `woodpecker-cli setup` or provide the required environment variables / flags.") + log.Info().Msg("woodpecker-cli is not set up, run `woodpecker-cli setup` or provide required environment variables/flags") return errors.New("woodpecker-cli is not configured") } @@ -63,7 +63,7 @@ func Load(ctx context.Context, c *cli.Command) error { return err } - log.Debug().Any("config", config).Msg("Loaded config") + log.Debug().Any("config", config).Msg("loaded config") return nil } @@ -93,16 +93,16 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error) return nil, err } - log.Debug().Str("configPath", configPath).Msg("Checking for config file") + log.Debug().Str("configPath", configPath).Msg("checking for config file") content, err := os.ReadFile(configPath) switch { case err != nil && !os.IsNotExist(err): - log.Debug().Err(err).Msg("Failed to read the config file") + log.Debug().Err(err).Msg("failed to read the config file") return nil, err case err != nil && os.IsNotExist(err): - log.Debug().Msg("The config file does not exist") + log.Debug().Msg("config file does not exist") default: configFromFile := &Config{} @@ -111,7 +111,7 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error) return nil, err } conf.MergeIfNotSet(configFromFile) - log.Debug().Msg("Loaded config from file") + log.Debug().Msg("loaded config from file") } // if server or token are explicitly set, use them @@ -123,11 +123,11 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error) service := c.Root().Name secret, err := keyring.Get(service, conf.ServerURL) if errors.Is(err, keyring.ErrUnsupportedPlatform) { - log.Warn().Msg("Keyring is not supported on this platform") + log.Warn().Msg("keyring is not supported on this platform") return conf, nil } if errors.Is(err, keyring.ErrNotFound) { - log.Warn().Msg("Token not found in keyring") + log.Warn().Msg("token not found in keyring") return conf, nil } conf.Token = secret diff --git a/cli/lint/lint.go b/cli/lint/lint.go index 3872ef093..b52175daa 100644 --- a/cli/lint/lint.go +++ b/cli/lint/lint.go @@ -40,12 +40,12 @@ var Command = &cli.Command{ &cli.StringSliceFlag{ Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"), Name: "plugins-privileged", - Usage: "Allow plugins to run in privileged mode, if environment variable is defined but empty there will be none", + Usage: "allow plugins to run in privileged mode, if set empty, there is no", }, &cli.StringSliceFlag{ Sources: cli.EnvVars("WOODPECKER_PLUGINS_TRUSTED_CLONE"), Name: "plugins-trusted-clone", - Usage: "Plugins which are trusted to handle Git credentials in clone steps", + Usage: "plugins that are trusted to handle Git credentials in cloning steps", Value: constant.TrustedClonePlugins, }, &cli.BoolFlag{ diff --git a/cli/org/registry/registry.go b/cli/org/registry/registry.go index aa4f9f23b..ed8051bd9 100644 --- a/cli/org/registry/registry.go +++ b/cli/org/registry/registry.go @@ -30,7 +30,7 @@ var Command = &cli.Command{ registryCreateCmd, registryDeleteCmd, registryUpdateCmd, - registryInfoCmd, + registryShowCmd, registryListCmd, }, } diff --git a/cli/org/registry/registry_add.go b/cli/org/registry/registry_add.go index d82859f00..e6b184bcf 100644 --- a/cli/org/registry/registry_add.go +++ b/cli/org/registry/registry_add.go @@ -28,7 +28,7 @@ import ( var registryCreateCmd = &cli.Command{ Name: "add", - Usage: "adds a registry", + Usage: "add a registry", ArgsUsage: "[org-id|org-full-name]", Action: registryCreate, Flags: []cli.Flag{ diff --git a/cli/org/registry/registry_info.go b/cli/org/registry/registry_show.go similarity index 88% rename from cli/org/registry/registry_info.go rename to cli/org/registry/registry_show.go index 752c54c18..8fd7a77f0 100644 --- a/cli/org/registry/registry_info.go +++ b/cli/org/registry/registry_show.go @@ -25,11 +25,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var registryInfoCmd = &cli.Command{ - Name: "info", - Usage: "display registry info", +var registryShowCmd = &cli.Command{ + Name: "show", + Usage: "show registry information", ArgsUsage: "[org-id|org-full-name]", - Action: registryInfo, + Action: registryShow, Flags: []cli.Flag{ common.OrgFlag, &cli.StringFlag{ @@ -41,7 +41,7 @@ var registryInfoCmd = &cli.Command{ }, } -func registryInfo(ctx context.Context, c *cli.Command) error { +func registryShow(ctx context.Context, c *cli.Command) error { var ( hostname = c.String("hostname") format = c.String("format") + "\n" diff --git a/cli/org/secret/secret.go b/cli/org/secret/secret.go index 11206be53..21579993b 100644 --- a/cli/org/secret/secret.go +++ b/cli/org/secret/secret.go @@ -30,7 +30,7 @@ var Command = &cli.Command{ secretCreateCmd, secretDeleteCmd, secretUpdateCmd, - secretInfoCmd, + secretShowCmd, secretListCmd, }, } diff --git a/cli/org/secret/secret_add.go b/cli/org/secret/secret_add.go index 97b901cdd..d356773f1 100644 --- a/cli/org/secret/secret_add.go +++ b/cli/org/secret/secret_add.go @@ -28,7 +28,7 @@ import ( var secretCreateCmd = &cli.Command{ Name: "add", - Usage: "adds a secret", + Usage: "add a secret", ArgsUsage: "[repo-id|repo-full-name]", Action: secretCreate, Flags: []cli.Flag{ diff --git a/cli/org/secret/secret_set.go b/cli/org/secret/secret_set.go index 2e25655aa..4357d3296 100644 --- a/cli/org/secret/secret_set.go +++ b/cli/org/secret/secret_set.go @@ -43,11 +43,11 @@ var secretUpdateCmd = &cli.Command{ }, &cli.StringSliceFlag{ Name: "event", - Usage: "secret limited to these events", + Usage: "limit secret to these event", }, &cli.StringSliceFlag{ Name: "image", - Usage: "secret limited to these images", + Usage: "limit secret to these image", }, }, } diff --git a/cli/org/secret/secret_info.go b/cli/org/secret/secret_show.go similarity index 89% rename from cli/org/secret/secret_info.go rename to cli/org/secret/secret_show.go index 8025a977f..9a78741c2 100644 --- a/cli/org/secret/secret_info.go +++ b/cli/org/secret/secret_show.go @@ -26,11 +26,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var secretInfoCmd = &cli.Command{ - Name: "info", - Usage: "display secret info", +var secretShowCmd = &cli.Command{ + Name: "show", + Usage: "show secret information", ArgsUsage: "[repo-id|repo-full-name]", - Action: secretInfo, + Action: secretShow, Flags: []cli.Flag{ common.OrgFlag, &cli.StringFlag{ @@ -41,7 +41,7 @@ var secretInfoCmd = &cli.Command{ }, } -func secretInfo(ctx context.Context, c *cli.Command) error { +func secretShow(ctx context.Context, c *cli.Command) error { var ( secretName = c.String("name") format = c.String("format") + "\n" diff --git a/cli/pipeline/deploy/deploy.go b/cli/pipeline/deploy/deploy.go index 8a742fc8a..199310ac6 100644 --- a/cli/pipeline/deploy/deploy.go +++ b/cli/pipeline/deploy/deploy.go @@ -53,7 +53,7 @@ var Command = &cli.Command{ &cli.StringSliceFlag{ Name: "param", Aliases: []string{"p"}, - Usage: "custom parameters to be injected into the step environment. Format: KEY=value", + Usage: "custom parameters to inject into the step environment. Format: KEY=value", }, }, } diff --git a/cli/pipeline/last.go b/cli/pipeline/last.go index 131c20902..49f161142 100644 --- a/cli/pipeline/last.go +++ b/cli/pipeline/last.go @@ -26,7 +26,7 @@ import ( var pipelineLastCmd = &cli.Command{ Name: "last", - Usage: "show latest pipeline details", + Usage: "show latest pipeline information", ArgsUsage: "", Action: pipelineLast, Flags: append(common.OutputFlags("table"), []cli.Flag{ diff --git a/cli/pipeline/list.go b/cli/pipeline/list.go index bfd24981b..afe1f3803 100644 --- a/cli/pipeline/list.go +++ b/cli/pipeline/list.go @@ -52,7 +52,7 @@ func buildPipelineListCmd() *cli.Command { }, &cli.TimestampFlag{ Name: "before", - Usage: "only return pipelines before this RFC3339 date", + Usage: "only return pipelines before this date (RFC3339)", Config: cli.TimestampConfig{ Layouts: []string{ time.RFC3339, @@ -61,7 +61,7 @@ func buildPipelineListCmd() *cli.Command { }, &cli.TimestampFlag{ Name: "after", - Usage: "only return pipelines after this RFC3339 date", + Usage: "only return pipelines after this date (RFC3339)", Config: cli.TimestampConfig{ Layouts: []string{ time.RFC3339, diff --git a/cli/pipeline/pipeline.go b/cli/pipeline/pipeline.go index 866158e88..454e7064d 100644 --- a/cli/pipeline/pipeline.go +++ b/cli/pipeline/pipeline.go @@ -35,7 +35,7 @@ var Command = &cli.Command{ Commands: []*cli.Command{ buildPipelineListCmd(), pipelineLastCmd, - pipelineInfoCmd, + pipelineShowCmd, pipelineStopCmd, pipelineStartCmd, pipelineApproveCmd, diff --git a/cli/pipeline/info.go b/cli/pipeline/show.go similarity index 90% rename from cli/pipeline/info.go rename to cli/pipeline/show.go index 27d05a244..165c6a70a 100644 --- a/cli/pipeline/info.go +++ b/cli/pipeline/show.go @@ -25,15 +25,15 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) -var pipelineInfoCmd = &cli.Command{ - Name: "info", - Usage: "show pipeline details", +var pipelineShowCmd = &cli.Command{ + Name: "show", + Usage: "show pipeline information", ArgsUsage: " [pipeline]", - Action: pipelineInfo, + Action: pipelineShow, Flags: common.OutputFlags("table"), } -func pipelineInfo(ctx context.Context, c *cli.Command) error { +func pipelineShow(ctx context.Context, c *cli.Command) error { repoIDOrFullName := c.Args().First() client, err := internal.NewClient(ctx, c) if err != nil { diff --git a/cli/pipeline/start.go b/cli/pipeline/start.go index 4a9b380a2..02c3e3de0 100644 --- a/cli/pipeline/start.go +++ b/cli/pipeline/start.go @@ -35,7 +35,7 @@ var pipelineStartCmd = &cli.Command{ &cli.StringSliceFlag{ Name: "param", Aliases: []string{"p"}, - Usage: "custom parameters to be injected into the step environment. Format: KEY=value", + Usage: "custom parameters to inject into the step environment. Format: KEY=value", }, }, } diff --git a/cli/repo/cron/cron.go b/cli/repo/cron/cron.go index efcfa2c17..364813876 100644 --- a/cli/repo/cron/cron.go +++ b/cli/repo/cron/cron.go @@ -26,7 +26,7 @@ var Command = &cli.Command{ cronCreateCmd, cronDeleteCmd, cronUpdateCmd, - cronInfoCmd, + cronShowCmd, cronListCmd, }, } diff --git a/cli/repo/cron/cron_info.go b/cli/repo/cron/cron_show.go similarity index 89% rename from cli/repo/cron/cron_info.go rename to cli/repo/cron/cron_show.go index 276ed15a9..2e8b86650 100644 --- a/cli/repo/cron/cron_info.go +++ b/cli/repo/cron/cron_show.go @@ -25,11 +25,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var cronInfoCmd = &cli.Command{ - Name: "info", - Usage: "display info about a cron job", +var cronShowCmd = &cli.Command{ + Name: "show", + Usage: "show cron job information", ArgsUsage: "[repo-id|repo-full-name]", - Action: cronInfo, + Action: cronShow, Flags: []cli.Flag{ common.RepoFlag, &cli.StringFlag{ @@ -41,7 +41,7 @@ var cronInfoCmd = &cli.Command{ }, } -func cronInfo(ctx context.Context, c *cli.Command) error { +func cronShow(ctx context.Context, c *cli.Command) error { var ( cronID = c.Int("id") repoIDOrFullName = c.String("repository") diff --git a/cli/repo/registry/registry.go b/cli/repo/registry/registry.go index df3f09446..98b4ef84a 100644 --- a/cli/repo/registry/registry.go +++ b/cli/repo/registry/registry.go @@ -29,7 +29,7 @@ var Command = &cli.Command{ registryCreateCmd, registryDeleteCmd, registryUpdateCmd, - registryInfoCmd, + registryShowCmd, registryListCmd, }, } diff --git a/cli/repo/registry/registry_add.go b/cli/repo/registry/registry_add.go index e894a698c..50eecffa0 100644 --- a/cli/repo/registry/registry_add.go +++ b/cli/repo/registry/registry_add.go @@ -28,7 +28,7 @@ import ( var registryCreateCmd = &cli.Command{ Name: "add", - Usage: "adds a registry", + Usage: "add a registry", ArgsUsage: "[repo-id|repo-full-name]", Action: registryCreate, Flags: []cli.Flag{ diff --git a/cli/repo/registry/registry_info.go b/cli/repo/registry/registry_show.go similarity index 88% rename from cli/repo/registry/registry_info.go rename to cli/repo/registry/registry_show.go index f171d1d23..d3b50b9f2 100644 --- a/cli/repo/registry/registry_info.go +++ b/cli/repo/registry/registry_show.go @@ -25,11 +25,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var registryInfoCmd = &cli.Command{ - Name: "info", - Usage: "display registry info", +var registryShowCmd = &cli.Command{ + Name: "show", + Usage: "show registry information", ArgsUsage: "[repo-id|repo-full-name]", - Action: registryInfo, + Action: registryShow, Flags: []cli.Flag{ common.RepoFlag, &cli.StringFlag{ @@ -41,7 +41,7 @@ var registryInfoCmd = &cli.Command{ }, } -func registryInfo(ctx context.Context, c *cli.Command) error { +func registryShow(ctx context.Context, c *cli.Command) error { var ( hostname = c.String("hostname") format = c.String("format") + "\n" diff --git a/cli/repo/repo.go b/cli/repo/repo.go index 6eeda1ddd..e9467694c 100644 --- a/cli/repo/repo.go +++ b/cli/repo/repo.go @@ -28,7 +28,7 @@ var Command = &cli.Command{ Usage: "manage repositories", Commands: []*cli.Command{ repoListCmd, - repoInfoCmd, + repoShowCmd, repoAddCmd, repoUpdateCmd, repoRemoveCmd, diff --git a/cli/repo/repo_info.go b/cli/repo/repo_show.go similarity index 90% rename from cli/repo/repo_info.go rename to cli/repo/repo_show.go index 648766940..af8a45153 100644 --- a/cli/repo/repo_info.go +++ b/cli/repo/repo_show.go @@ -25,15 +25,15 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var repoInfoCmd = &cli.Command{ - Name: "info", - Usage: "show repository details", +var repoShowCmd = &cli.Command{ + Name: "show", + Usage: "show repository information", ArgsUsage: "", - Action: repoInfo, + Action: repoShow, Flags: []cli.Flag{common.FormatFlag(tmplRepoInfo)}, } -func repoInfo(ctx context.Context, c *cli.Command) error { +func repoShow(ctx context.Context, c *cli.Command) error { repoIDOrFullName := c.Args().First() client, err := internal.NewClient(ctx, c) if err != nil { diff --git a/cli/repo/repo_update.go b/cli/repo/repo_update.go index c5fe2a232..b6a2e5846 100644 --- a/cli/repo/repo_update.go +++ b/cli/repo/repo_update.go @@ -53,7 +53,7 @@ var repoUpdateCmd = &cli.Command{ }, &cli.StringFlag{ Name: "config", - Usage: "repository configuration path (e.g. .woodpecker.yml)", + Usage: "repository configuration path. Example: .woodpecker.yml", }, &cli.IntFlag{ Name: "pipeline-counter", @@ -61,7 +61,7 @@ var repoUpdateCmd = &cli.Command{ }, &cli.BoolFlag{ Name: "unsafe", - Usage: "validate updating the pipeline-counter is unsafe", + Usage: "allow unsafe operations", }, }, } diff --git a/cli/repo/secret/secret.go b/cli/repo/secret/secret.go index 1ea67ea99..3284539d3 100644 --- a/cli/repo/secret/secret.go +++ b/cli/repo/secret/secret.go @@ -29,7 +29,7 @@ var Command = &cli.Command{ secretCreateCmd, secretDeleteCmd, secretUpdateCmd, - secretInfoCmd, + secretShowCmd, secretListCmd, }, } diff --git a/cli/repo/secret/secret_add.go b/cli/repo/secret/secret_add.go index ee883c064..cc4251e20 100644 --- a/cli/repo/secret/secret_add.go +++ b/cli/repo/secret/secret_add.go @@ -28,7 +28,7 @@ import ( var secretCreateCmd = &cli.Command{ Name: "add", - Usage: "adds a secret", + Usage: "add a secret", ArgsUsage: "[repo-id|repo-full-name]", Action: secretCreate, Flags: []cli.Flag{ @@ -43,11 +43,11 @@ var secretCreateCmd = &cli.Command{ }, &cli.StringSliceFlag{ Name: "event", - Usage: "secret limited to these events", + Usage: "limit secret to these events", }, &cli.StringSliceFlag{ Name: "image", - Usage: "secret limited to these images", + Usage: "limit secret to these images", }, }, } diff --git a/cli/repo/secret/secret_set.go b/cli/repo/secret/secret_set.go index 0b21d4b66..60c0fcc8d 100644 --- a/cli/repo/secret/secret_set.go +++ b/cli/repo/secret/secret_set.go @@ -43,11 +43,11 @@ var secretUpdateCmd = &cli.Command{ }, &cli.StringSliceFlag{ Name: "event", - Usage: "secret limited to these events", + Usage: "limit secret to these events", }, &cli.StringSliceFlag{ Name: "image", - Usage: "secret limited to these images", + Usage: "limit secret to these images", }, }, } diff --git a/cli/repo/secret/secret_info.go b/cli/repo/secret/secret_show.go similarity index 89% rename from cli/repo/secret/secret_info.go rename to cli/repo/secret/secret_show.go index fcb30db83..8387f4054 100644 --- a/cli/repo/secret/secret_info.go +++ b/cli/repo/secret/secret_show.go @@ -26,11 +26,11 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/internal" ) -var secretInfoCmd = &cli.Command{ - Name: "info", - Usage: "display secret info", +var secretShowCmd = &cli.Command{ + Name: "show", + Usage: "show secret information", ArgsUsage: "[repo-id|repo-full-name]", - Action: secretInfo, + Action: secretShow, Flags: []cli.Flag{ common.RepoFlag, &cli.StringFlag{ @@ -41,7 +41,7 @@ var secretInfoCmd = &cli.Command{ }, } -func secretInfo(ctx context.Context, c *cli.Command) error { +func secretShow(ctx context.Context, c *cli.Command) error { var ( secretName = c.String("name") format = c.String("format") + "\n" diff --git a/cli/setup/setup.go b/cli/setup/setup.go index 6705482e9..c0be0006a 100644 --- a/cli/setup/setup.go +++ b/cli/setup/setup.go @@ -20,11 +20,11 @@ var Command = &cli.Command{ Flags: []cli.Flag{ &cli.StringFlag{ Name: "server", - Usage: "The URL of the woodpecker server", + Usage: "URL of the woodpecker server", }, &cli.StringFlag{ Name: "token", - Usage: "The token to authenticate with the woodpecker server", + Usage: "token to authenticate with the woodpecker server", }, }, Action: setup, @@ -41,7 +41,7 @@ func setup(ctx context.Context, c *cli.Command) error { } if !setupAgain { - log.Info().Msg("Configuration skipped") + log.Info().Msg("configuration skipped") return nil } } @@ -87,7 +87,7 @@ func setup(ctx context.Context, c *cli.Command) error { return err } - log.Info().Msg("The woodpecker-cli has been successfully setup") + log.Info().Msg("woodpecker-cli has been successfully setup") return nil } diff --git a/cli/setup/token_fetcher.go b/cli/setup/token_fetcher.go index 59be6b08d..05305e7ca 100644 --- a/cli/setup/token_fetcher.go +++ b/cli/setup/token_fetcher.go @@ -24,12 +24,12 @@ func receiveTokenFromUI(c context.Context, serverURL string) (string, error) { srv.Handler = setupRouter(tokenReceived) go func() { - log.Debug().Msgf("Listening for token response on :%d", port) + log.Debug().Msgf("listening for token response on :%d", port) _ = srv.ListenAndServe() }() defer func() { - log.Debug().Msg("Shutting down server") + log.Debug().Msg("shutting down server") _ = srv.Shutdown(c) }() @@ -90,7 +90,7 @@ func setupRouter(tokenReceived chan string) *gin.Engine { err := c.BindJSON(&data) if err != nil { - log.Debug().Err(err).Msg("Failed to bind JSON") + log.Debug().Err(err).Msg("failed to bind JSON") c.JSON(http.StatusBadRequest, gin.H{ "error": "invalid request", }) @@ -110,7 +110,7 @@ func setupRouter(tokenReceived chan string) *gin.Engine { func openBrowser(url string) error { var err error - log.Debug().Msgf("Opening browser with URL: %s", url) + log.Debug().Msgf("opening browser with URL: %s", url) switch runtime.GOOS { case "linux": diff --git a/cli/update/command.go b/cli/update/command.go index ad856402f..a4dad8530 100644 --- a/cli/update/command.go +++ b/cli/update/command.go @@ -24,7 +24,7 @@ var Command = &cli.Command{ } func update(ctx context.Context, c *cli.Command) error { - log.Info().Msg("Checking for updates ...") + log.Info().Msg("checking for updates ...") newVersion, err := CheckForUpdate(ctx, c.Bool("force")) if err != nil { @@ -32,11 +32,11 @@ func update(ctx context.Context, c *cli.Command) error { } if newVersion == nil { - fmt.Println("You are using the latest version of woodpecker-cli") + fmt.Println("you are using the latest version of woodpecker-cli") return nil } - log.Info().Msgf("New version %s is available! Updating ...", newVersion.Version) + log.Info().Msgf("new version %s is available! Updating ...", newVersion.Version) var tarFilePath string tarFilePath, err = downloadNewVersion(ctx, newVersion.AssetURL) @@ -44,14 +44,14 @@ func update(ctx context.Context, c *cli.Command) error { return err } - log.Debug().Msgf("New version %s has been downloaded successfully! Installing ...", newVersion.Version) + log.Debug().Msgf("new version %s has been downloaded successfully! Installing ...", newVersion.Version) binFile, err := extractNewVersion(tarFilePath) if err != nil { return err } - log.Debug().Msgf("New version %s has been extracted to %s", newVersion.Version, binFile) + log.Debug().Msgf("new version %s has been extracted to %s", newVersion.Version, binFile) executablePathOrSymlink, err := os.Executable() if err != nil { diff --git a/cli/update/updater.go b/cli/update/updater.go index 9071e2605..d77bad6a4 100644 --- a/cli/update/updater.go +++ b/cli/update/updater.go @@ -22,10 +22,10 @@ func CheckForUpdate(ctx context.Context, force bool) (*NewVersion, error) { } func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVersion, error) { - log.Debug().Msgf("Current version: %s", version.String()) + log.Debug().Msgf("current version: %s", version.String()) if (version.String() == "dev" || strings.HasPrefix(version.String(), "next-")) && !force { - log.Debug().Msgf("Skipping update check for development & next versions") + log.Debug().Msgf("skipping update check for development/next versions") return nil, nil } @@ -61,11 +61,11 @@ func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVer // using the latest release if installedVersion == upstreamVersion && !force { - log.Debug().Msgf("No new version available") + log.Debug().Msgf("no new version available") return nil, nil } - log.Debug().Msgf("New version available: %s", upstreamVersion) + log.Debug().Msgf("new version available: %s", upstreamVersion) assetURL := fmt.Sprintf(githubBinaryURL, upstreamVersion, runtime.GOOS, runtime.GOARCH) return &NewVersion{ @@ -75,7 +75,7 @@ func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVer } func downloadNewVersion(ctx context.Context, downloadURL string) (string, error) { - log.Debug().Msgf("Downloading new version from %s ...", downloadURL) + log.Debug().Msgf("downloading new version from %s ...", downloadURL) req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadURL, nil) if err != nil { @@ -102,13 +102,13 @@ func downloadNewVersion(ctx context.Context, downloadURL string) (string, error) return "", err } - log.Debug().Msgf("New version downloaded to %s", file.Name()) + log.Debug().Msgf("new version downloaded to %s", file.Name()) return file.Name(), nil } func extractNewVersion(tarFilePath string) (string, error) { - log.Debug().Msgf("Extracting new version from %s ...", tarFilePath) + log.Debug().Msgf("extracting new version from %s ...", tarFilePath) tarFile, err := os.Open(tarFilePath) if err != nil { @@ -132,7 +132,7 @@ func extractNewVersion(tarFilePath string) (string, error) { return "", err } - log.Debug().Msgf("New version extracted to %s", tmpDir) + log.Debug().Msgf("new version extracted to %s", tmpDir) return path.Join(tmpDir, "woodpecker-cli"), nil } diff --git a/docs/src/pages/migrations.md b/docs/src/pages/migrations.md index a45c6cca1..dcafbd831 100644 --- a/docs/src/pages/migrations.md +++ b/docs/src/pages/migrations.md @@ -43,6 +43,7 @@ This will be the next version of Woodpecker. - `woodpecker-cli cron` is now `woodpecker-cli repo cron` - `woodpecker-cli secret [add|rm|...] --repository` is now `woodpecker-cli repo secret [add|rm|...]` - `woodpecker-cli pipeline logs` is now `woodpecker-cli pipeline log show` + - `woodpecker-cli [registry|secret|...] info` is now `woodpecker-cli [registry|secret|...] show` ## Admin migrations From bb1461d5d8c6797c06edb73fb30bd3091d842557 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 30 Nov 2024 18:00:11 +0100 Subject: [PATCH 08/22] Fix spellcheck in purge log (#4491) --- cli/pipeline/purge.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/pipeline/purge.go b/cli/pipeline/purge.go index 759b9cbf2..a9c5e39d1 100644 --- a/cli/pipeline/purge.go +++ b/cli/pipeline/purge.go @@ -113,7 +113,8 @@ func pipelinePurge(c *cli.Command, client woodpecker.Client) (err error) { } for i, p := range pipelinesToPurge { - log.Debug().Msgf("%sprune %v/%v pipelines from repo '%v'", msgPrefix, i+1, len(pipelinesToPurge), repoIDOrFullName) + // cspell:words spurge + log.Debug().Msgf("%spurge %v/%v pipelines from repo '%v'", msgPrefix, i+1, len(pipelinesToPurge), repoIDOrFullName) if dryRun { continue } From 0f87ddc0578f27a4b89395fbc84729e2cf0b93bf Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Sat, 30 Nov 2024 20:11:57 +0200 Subject: [PATCH 09/22] Sort cli commands alphabetically (#4489) Co-authored-by: Robert Kaussow --- cli/admin/admin.go | 6 +++--- cli/admin/registry/registry.go | 4 ++-- cli/admin/secret/secret.go | 4 ++-- cli/admin/user/user.go | 4 ++-- cli/org/registry/registry.go | 4 ++-- cli/org/secret/secret.go | 4 ++-- cli/pipeline/log/log.go | 2 +- cli/pipeline/pipeline.go | 20 ++++++++++---------- cli/repo/cron/cron.go | 4 ++-- cli/repo/registry/registry.go | 4 ++-- cli/repo/repo.go | 14 +++++++------- cli/repo/secret/secret.go | 4 ++-- cmd/cli/app.go | 6 +++--- 13 files changed, 40 insertions(+), 40 deletions(-) diff --git a/cli/admin/admin.go b/cli/admin/admin.go index f96c5fd0b..f99b79f0f 100644 --- a/cli/admin/admin.go +++ b/cli/admin/admin.go @@ -28,9 +28,9 @@ var Command = &cli.Command{ Name: "admin", Usage: "manage server settings", Commands: []*cli.Command{ - secret.Command, - registry.Command, - user.Command, loglevel.Command, + registry.Command, + secret.Command, + user.Command, }, } diff --git a/cli/admin/registry/registry.go b/cli/admin/registry/registry.go index 1717803c6..7055c2873 100644 --- a/cli/admin/registry/registry.go +++ b/cli/admin/registry/registry.go @@ -25,8 +25,8 @@ var Command = &cli.Command{ Commands: []*cli.Command{ registryCreateCmd, registryDeleteCmd, - registryUpdateCmd, - registryShowCmd, registryListCmd, + registryShowCmd, + registryUpdateCmd, }, } diff --git a/cli/admin/secret/secret.go b/cli/admin/secret/secret.go index b3496b076..da805a98e 100644 --- a/cli/admin/secret/secret.go +++ b/cli/admin/secret/secret.go @@ -25,8 +25,8 @@ var Command = &cli.Command{ Commands: []*cli.Command{ secretCreateCmd, secretDeleteCmd, - secretUpdateCmd, - secretShowCmd, secretListCmd, + secretShowCmd, + secretUpdateCmd, }, } diff --git a/cli/admin/user/user.go b/cli/admin/user/user.go index fe68e5d47..29951a635 100644 --- a/cli/admin/user/user.go +++ b/cli/admin/user/user.go @@ -23,9 +23,9 @@ var Command = &cli.Command{ Name: "user", Usage: "manage users", Commands: []*cli.Command{ - userListCmd, - userShowCmd, userAddCmd, + userListCmd, userRemoveCmd, + userShowCmd, }, } diff --git a/cli/org/registry/registry.go b/cli/org/registry/registry.go index ed8051bd9..38ca0454e 100644 --- a/cli/org/registry/registry.go +++ b/cli/org/registry/registry.go @@ -29,9 +29,9 @@ var Command = &cli.Command{ Commands: []*cli.Command{ registryCreateCmd, registryDeleteCmd, - registryUpdateCmd, - registryShowCmd, registryListCmd, + registryShowCmd, + registryUpdateCmd, }, } diff --git a/cli/org/secret/secret.go b/cli/org/secret/secret.go index 21579993b..b50880c91 100644 --- a/cli/org/secret/secret.go +++ b/cli/org/secret/secret.go @@ -29,9 +29,9 @@ var Command = &cli.Command{ Commands: []*cli.Command{ secretCreateCmd, secretDeleteCmd, - secretUpdateCmd, - secretShowCmd, secretListCmd, + secretShowCmd, + secretUpdateCmd, }, } diff --git a/cli/pipeline/log/log.go b/cli/pipeline/log/log.go index 4ea569d79..4227288dc 100644 --- a/cli/pipeline/log/log.go +++ b/cli/pipeline/log/log.go @@ -23,7 +23,7 @@ var Command = &cli.Command{ Name: "log", Usage: "manage logs", Commands: []*cli.Command{ - logShowCmd, logPurgeCmd, + logShowCmd, }, } diff --git a/cli/pipeline/pipeline.go b/cli/pipeline/pipeline.go index 454e7064d..cc86ddf07 100644 --- a/cli/pipeline/pipeline.go +++ b/cli/pipeline/pipeline.go @@ -33,20 +33,20 @@ var Command = &cli.Command{ Name: "pipeline", Usage: "manage pipelines", Commands: []*cli.Command{ - buildPipelineListCmd(), - pipelineLastCmd, - pipelineShowCmd, - pipelineStopCmd, - pipelineStartCmd, pipelineApproveCmd, - pipelineDeclineCmd, - pipelineQueueCmd, - pipelineKillCmd, - pipelinePsCmd, pipelineCreateCmd, - log.Command, + pipelineDeclineCmd, deploy.Command, + pipelineKillCmd, + pipelineLastCmd, + buildPipelineListCmd(), + log.Command, + pipelinePsCmd, pipelinePurgeCmd, + pipelineQueueCmd, + pipelineShowCmd, + pipelineStartCmd, + pipelineStopCmd, }, } diff --git a/cli/repo/cron/cron.go b/cli/repo/cron/cron.go index 364813876..90edf8f9c 100644 --- a/cli/repo/cron/cron.go +++ b/cli/repo/cron/cron.go @@ -25,8 +25,8 @@ var Command = &cli.Command{ Commands: []*cli.Command{ cronCreateCmd, cronDeleteCmd, - cronUpdateCmd, - cronShowCmd, cronListCmd, + cronShowCmd, + cronUpdateCmd, }, } diff --git a/cli/repo/registry/registry.go b/cli/repo/registry/registry.go index 98b4ef84a..ab362934a 100644 --- a/cli/repo/registry/registry.go +++ b/cli/repo/registry/registry.go @@ -28,9 +28,9 @@ var Command = &cli.Command{ Commands: []*cli.Command{ registryCreateCmd, registryDeleteCmd, - registryUpdateCmd, - registryShowCmd, registryListCmd, + registryShowCmd, + registryUpdateCmd, }, } diff --git a/cli/repo/repo.go b/cli/repo/repo.go index e9467694c..8bb3b612a 100644 --- a/cli/repo/repo.go +++ b/cli/repo/repo.go @@ -27,16 +27,16 @@ var Command = &cli.Command{ Name: "repo", Usage: "manage repositories", Commands: []*cli.Command{ - repoListCmd, - repoShowCmd, repoAddCmd, - repoUpdateCmd, + repoChownCmd, + cron.Command, + repoListCmd, + registry.Command, repoRemoveCmd, repoRepairCmd, - repoChownCmd, - repoSyncCmd, - registry.Command, secret.Command, - cron.Command, + repoShowCmd, + repoSyncCmd, + repoUpdateCmd, }, } diff --git a/cli/repo/secret/secret.go b/cli/repo/secret/secret.go index 3284539d3..2d5d965e6 100644 --- a/cli/repo/secret/secret.go +++ b/cli/repo/secret/secret.go @@ -28,9 +28,9 @@ var Command = &cli.Command{ Commands: []*cli.Command{ secretCreateCmd, secretDeleteCmd, - secretUpdateCmd, - secretShowCmd, secretListCmd, + secretShowCmd, + secretUpdateCmd, }, } diff --git a/cmd/cli/app.go b/cmd/cli/app.go index 347513b1c..2784b08a3 100644 --- a/cmd/cli/app.go +++ b/cmd/cli/app.go @@ -43,12 +43,12 @@ func newApp() *cli.Command { app.Suggest = true app.Commands = []*cli.Command{ admin.Command, - org.Command, - repo.Command, - pipeline.Command, exec.Command, info.Command, lint.Command, + org.Command, + pipeline.Command, + repo.Command, setup.Command, update.Command, } From 6c96040aa590143a403a6fbaf592a909ebb29f5d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:59:06 +0100 Subject: [PATCH 10/22] chore(deps): update dependency isomorphic-dompurify to v2.18.0 (#4493) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- docs/pnpm-lock.yaml | 63 +++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/docs/pnpm-lock.yaml b/docs/pnpm-lock.yaml index e403a7234..eeefea251 100644 --- a/docs/pnpm-lock.yaml +++ b/docs/pnpm-lock.yaml @@ -119,7 +119,7 @@ importers: version: 9.1.0 isomorphic-dompurify: specifier: ^2.16.0 - version: 2.17.0 + version: 2.18.0 marked: specifier: ^15.0.2 version: 15.0.3 @@ -2753,8 +2753,8 @@ packages: resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==} engines: {node: '>= 4'} - dompurify@3.2.1: - resolution: {integrity: sha512-NBHEsc0/kzRYQd+AY6HR6B/IgsqzBABrqJbpCDQII/OK6h7B7LXzweZTDsqSW2LkTRpoxf18YUP+YjGySk6B3w==} + dompurify@3.2.2: + resolution: {integrity: sha512-YMM+erhdZ2nkZ4fTNRTSI94mb7VG7uVF5vj5Zde7tImgnhZE3R6YW/IACGIHb2ux+QkEXMhe591N+5jWOmL4Zw==} domutils@2.8.0: resolution: {integrity: sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==} @@ -3233,6 +3233,10 @@ packages: gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} + gopd@1.1.0: + resolution: {integrity: sha512-FQoVQnqcdk4hVM4JN1eromaun4iuS34oStkdlLENLdpULsuQcTyXj8w7ayhuUfPwEYZ1ZOooOTT6fdA9Vmx/RA==} + engines: {node: '>= 0.4'} + got@14.4.5: resolution: {integrity: sha512-sq+uET8TnNKRNnjEOPJzMcxeI0irT8BBNmf+GtZcJpmhYsQM1DSKmCROUjPWKsXZ5HzwD5Cf5/RV+QD9BSTxJg==} engines: {node: '>=20'} @@ -3658,6 +3662,10 @@ packages: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} + is-regex@1.2.0: + resolution: {integrity: sha512-B6ohK4ZmoftlUe+uvenXSbPJFo6U37BH7oO1B3nQH8f/7h27N56s85MhUtbFJAziz5dcmuR3i8ovUl35zp8pFA==} + engines: {node: '>= 0.4'} + is-regexp@1.0.0: resolution: {integrity: sha512-7zjFAPO4/gwyQAAgRRmqeEeyIICSdmCqa3tsVHMdBzaXXRiqopZL4Cyghg/XulGWrtABTpbnYYzzIRffLkP4oA==} engines: {node: '>=0.10.0'} @@ -3732,8 +3740,8 @@ packages: resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==} engines: {node: '>=0.10.0'} - isomorphic-dompurify@2.17.0: - resolution: {integrity: sha512-W9RC9aPgEAFF55VMo/9AUQ+GYkQ68gTRMLqS8fP9rw1VoYCsI7RdrRMAePhhqyCLfZS3JNjA4ahFi1L4aczUUg==} + isomorphic-dompurify@2.18.0: + resolution: {integrity: sha512-e0AaROtWPy6ofSTCnUuBvXFidt1eFmrwEbi+Acpz0du6v2H+fq+3svPBn0g/AfBXz24FTWA9ccle7HSFT3HG7A==} engines: {node: '>=18'} jest-util@29.7.0: @@ -4319,8 +4327,8 @@ packages: peerDependencies: webpack: ^4.0.0 || ^5.0.0 - nwsapi@2.2.13: - resolution: {integrity: sha512-cTGB9ptp9dY9A5VbMSe7fQBcl/tt22Vcqdq8+eN93rblOuE0aCFu4aZ2vMwct/2t+lFnosm8RkQW1I0Omb1UtQ==} + nwsapi@2.2.16: + resolution: {integrity: sha512-F1I/bimDpj3ncaNDhfyMWuFqmQDBwDB0Fogc2qpL3BWvkQteFD/8BzWuIRl83rq0DXfm8SGt/HFhLXZyljTXcQ==} oas-kit-common@1.0.8: resolution: {integrity: sha512-pJTS2+T0oGIwgjGpw7sIRU8RQMcUoKCDWFLdBqKB2BNmGpbBMH2sdqAaOXUg8OzonZHU0L7vfJu1mJFEiYDWOQ==} @@ -5702,11 +5710,11 @@ packages: tiny-warning@1.0.3: resolution: {integrity: sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==} - tldts-core@6.1.64: - resolution: {integrity: sha512-uqnl8vGV16KsyflHOzqrYjjArjfXaU6rMPXYy2/ZWoRKCkXtghgB4VwTDXUG+t0OTGeSewNAG31/x1gCTfLt+Q==} + tldts-core@6.1.65: + resolution: {integrity: sha512-Uq5t0N0Oj4nQSbU8wFN1YYENvMthvwU13MQrMJRspYCGLSAZjAfoBOJki5IQpnBM/WFskxxC/gIOTwaedmHaSg==} - tldts@6.1.64: - resolution: {integrity: sha512-ph4AE5BXWIOsSy9stpoeo7bYe/Cy7VfpciIH4RhVZUPItCJmhqWCN0EVzxd8BOHiyNb42vuJc6NWTjJkg91Tuw==} + tldts@6.1.65: + resolution: {integrity: sha512-xU9gLTfAGsADQ2PcWee6Hg8RFAv0DnjMGVJmDnUmI8a9+nYmapMQix4afwrdaCtT+AqP4MaxEzu7cCrYmBPbzQ==} hasBin: true to-regex-range@5.0.1: @@ -9793,7 +9801,7 @@ snapshots: dependencies: domelementtype: 2.3.0 - dompurify@3.2.1: + dompurify@3.2.2: optionalDependencies: '@types/trusted-types': 2.0.7 @@ -9870,7 +9878,7 @@ snapshots: is-boolean-object: 1.1.2 is-callable: 1.2.7 is-number-object: 1.0.7 - is-regex: 1.1.4 + is-regex: 1.2.0 is-string: 1.0.7 is-subset: 0.1.1 lodash.escape: 4.0.1 @@ -10414,6 +10422,10 @@ snapshots: dependencies: get-intrinsic: 1.2.4 + gopd@1.1.0: + dependencies: + get-intrinsic: 1.2.4 + got@14.4.5: dependencies: '@sindresorhus/is': 7.0.1 @@ -10898,6 +10910,13 @@ snapshots: call-bind: 1.0.7 has-tostringtag: 1.0.2 + is-regex@1.2.0: + dependencies: + call-bind: 1.0.7 + gopd: 1.1.0 + has-tostringtag: 1.0.2 + hasown: 2.0.2 + is-regexp@1.0.0: {} is-root@2.1.0: {} @@ -10953,9 +10972,9 @@ snapshots: isobject@3.0.1: {} - isomorphic-dompurify@2.17.0: + isomorphic-dompurify@2.18.0: dependencies: - dompurify: 3.2.1 + dompurify: 3.2.2 jsdom: 25.0.1 transitivePeerDependencies: - bufferutil @@ -11018,7 +11037,7 @@ snapshots: http-proxy-agent: 7.0.2 https-proxy-agent: 7.0.5 is-potential-custom-element-name: 1.0.1 - nwsapi: 2.2.13 + nwsapi: 2.2.16 parse5: 7.2.1 rrweb-cssom: 0.7.1 saxes: 6.0.0 @@ -11799,7 +11818,7 @@ snapshots: schema-utils: 3.3.0 webpack: 5.96.1 - nwsapi@2.2.13: {} + nwsapi@2.2.16: {} oas-kit-common@1.0.8: dependencies: @@ -12750,7 +12769,7 @@ snapshots: classnames: 2.5.1 core-js: 3.39.0 decko: 1.2.0 - dompurify: 3.2.1 + dompurify: 3.2.2 eventemitter3: 5.0.1 json-pointer: 0.6.2 lunr: 2.3.9 @@ -13453,11 +13472,11 @@ snapshots: tiny-warning@1.0.3: {} - tldts-core@6.1.64: {} + tldts-core@6.1.65: {} - tldts@6.1.64: + tldts@6.1.65: dependencies: - tldts-core: 6.1.64 + tldts-core: 6.1.65 to-regex-range@5.0.1: dependencies: @@ -13469,7 +13488,7 @@ snapshots: tough-cookie@5.0.0: dependencies: - tldts: 6.1.64 + tldts: 6.1.65 tr46@0.0.3: {} From 4af899c4889c3fdb07601c79a1563c6d9a1ec953 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:16:08 +0100 Subject: [PATCH 11/22] chore(deps): update docker.io/woodpeckerci/plugin-surge-preview docker tag to v1.3.3 (#4495) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .woodpecker/docs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/docs.yaml b/.woodpecker/docs.yaml index bc2849f05..979fb4f2a 100644 --- a/.woodpecker/docs.yaml +++ b/.woodpecker/docs.yaml @@ -59,7 +59,7 @@ steps: - event: manual deploy-preview: - image: docker.io/woodpeckerci/plugin-surge-preview:1.3.2 + image: docker.io/woodpeckerci/plugin-surge-preview:1.3.3 settings: path: 'docs/build/' surge_token: From 289239d1b3bbd7e10d85a426375784c407972fa9 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 1 Dec 2024 05:35:05 +0100 Subject: [PATCH 12/22] Add status filter to list pipeline API (#4494) --- cmd/server/openapi/docs.go | 6 +++++ server/api/pipeline.go | 10 +++++++++ server/model/const.go | 11 ++++++++++ server/model/pipeline.go | 1 + server/store/datastore/pipeline.go | 4 ++++ server/store/datastore/pipeline_test.go | 29 +++++++++++++++++++++++++ 6 files changed, 61 insertions(+) diff --git a/cmd/server/openapi/docs.go b/cmd/server/openapi/docs.go index 59e148fc4..8b7c33c60 100644 --- a/cmd/server/openapi/docs.go +++ b/cmd/server/openapi/docs.go @@ -2984,6 +2984,12 @@ const docTemplate = `{ "description": "filter pipelines by strings contained in ref", "name": "ref", "in": "query" + }, + { + "type": "string", + "description": "filter pipelines by status", + "name": "status", + "in": "query" } ], "responses": { diff --git a/server/api/pipeline.go b/server/api/pipeline.go index fa9d4ce6c..400eaf357 100644 --- a/server/api/pipeline.go +++ b/server/api/pipeline.go @@ -120,6 +120,7 @@ func createTmpPipeline(event model.WebhookEvent, commit *model.Commit, user *mod // @Param branch query string false "filter pipelines by branch" // @Param event query string false "filter pipelines by webhook events (comma separated)" // @Param ref query string false "filter pipelines by strings contained in ref" +// @Param status query string false "filter pipelines by status" func GetPipelines(c *gin.Context) { repo := session.Repo(c) @@ -142,6 +143,15 @@ func GetPipelines(c *gin.Context) { filter.Events = wel } + if status := c.Query("status"); status != "" { + ps := model.StatusValue(status) + if err := ps.Validate(); err != nil { + _ = c.AbortWithError(http.StatusBadRequest, err) + return + } + filter.Status = ps + } + if before := c.Query("before"); before != "" { beforeDt, err := time.Parse(time.RFC3339, before) if err != nil { diff --git a/server/model/const.go b/server/model/const.go index 0707473b8..e37171259 100644 --- a/server/model/const.go +++ b/server/model/const.go @@ -66,6 +66,17 @@ const ( StatusCreated StatusValue = "created" // created / internal use only ) +var ErrInvalidStatusValue = errors.New("invalid status value") + +func (s StatusValue) Validate() error { + switch s { + case StatusSkipped, StatusPending, StatusRunning, StatusSuccess, StatusFailure, StatusKilled, StatusError, StatusBlocked, StatusDeclined, StatusCreated: + return nil + default: + return fmt.Errorf("%w: %s", ErrInvalidStatusValue, s) + } +} + // SCMKind represent different version control systems. type SCMKind string // @name SCMKind diff --git a/server/model/pipeline.go b/server/model/pipeline.go index 85270ce19..6268e08a6 100644 --- a/server/model/pipeline.go +++ b/server/model/pipeline.go @@ -66,6 +66,7 @@ type PipelineFilter struct { Branch string Events []WebhookEvent RefContains string + Status StatusValue } // IsMultiPipeline checks if step list contain more than one parent step. diff --git a/server/store/datastore/pipeline.go b/server/store/datastore/pipeline.go index 33a68e5bb..9a32bf482 100644 --- a/server/store/datastore/pipeline.go +++ b/server/store/datastore/pipeline.go @@ -70,6 +70,10 @@ func (s storage) GetPipelineList(repo *model.Repo, p *model.ListOptions, f *mode cond = cond.And(builder.Eq{"branch": f.Branch}) } + if f.Status != "" { + cond = cond.And(builder.Eq{"status": f.Status}) + } + if len(f.Events) != 0 { cond = cond.And(builder.In("event", f.Events)) } diff --git a/server/store/datastore/pipeline_test.go b/server/store/datastore/pipeline_test.go index fa18a085d..3382faf73 100644 --- a/server/store/datastore/pipeline_test.go +++ b/server/store/datastore/pipeline_test.go @@ -277,6 +277,35 @@ func TestPipelines(t *testing.T) { g.Assert(pipelines[0].ID).Equal(pipeline1.ID) g.Assert(pipelines[0].RepoID).Equal(pipeline1.RepoID) }) + + g.It("Should get pipelines filtered by status", func() { + pipeline1 := &model.Pipeline{ + RepoID: repo.ID, + Status: model.StatusSuccess, + } + pipeline2 := &model.Pipeline{ + RepoID: repo.ID, + Status: model.StatusFailure, + } + pipeline3 := &model.Pipeline{ + RepoID: repo.ID, + Status: model.StatusRunning, + } + err1 := store.CreatePipeline(pipeline1, []*model.Step{}...) + g.Assert(err1).IsNil() + err2 := store.CreatePipeline(pipeline2, []*model.Step{}...) + g.Assert(err2).IsNil() + err3 := store.CreatePipeline(pipeline3, []*model.Step{}...) + g.Assert(err3).IsNil() + + pipelines, err := store.GetPipelineList(&model.Repo{ID: 1}, nil, &model.PipelineFilter{ + Status: model.StatusSuccess, + }) + g.Assert(err).IsNil() + g.Assert(len(pipelines)).Equal(1) + g.Assert(pipelines[0].ID).Equal(pipeline1.ID) + g.Assert(pipelines[0].Status).Equal(model.StatusSuccess) + }) }) } From 7189cd61bf1a1ce27259a45b3e94bfe5b2b911c4 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:39:00 +0200 Subject: [PATCH 13/22] Some UI improvements (#4497) Co-authored-by: Robert Kaussow --- web/src/components/atomic/Badge.vue | 7 +++++-- web/src/views/org/settings/OrgSettingsWrapper.vue | 8 ++++---- web/src/views/user/UserCLIAndAPI.vue | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/web/src/components/atomic/Badge.vue b/web/src/components/atomic/Badge.vue index c8bd5d5be..64e31ddf0 100644 --- a/web/src/components/atomic/Badge.vue +++ b/web/src/components/atomic/Badge.vue @@ -1,14 +1,17 @@