From 7b7055d558cc50be3757bf353b526e82ff3c381f Mon Sep 17 00:00:00 2001 From: smainz Date: Mon, 15 Jul 2024 22:22:29 +0200 Subject: [PATCH 01/15] Don't show 'pipeline' as optional argument --- cli/pipeline/logs.go | 2 +- cli/pipeline/ps.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 116d68a4d2d..c4dfc0698aa 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -26,7 +26,7 @@ import ( var pipelineLogsCmd = &cli.Command{ Name: "logs", Usage: "show pipeline logs", - ArgsUsage: " [pipeline] [stepID]", + ArgsUsage: " [stepID]", Action: pipelineLogs, } diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index bba6f404306..a12b8a7422a 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -28,7 +28,7 @@ import ( var pipelinePsCmd = &cli.Command{ Name: "ps", Usage: "show pipeline steps", - ArgsUsage: " [pipeline]", + ArgsUsage: " ", Action: pipelinePs, Flags: []cli.Flag{common.FormatFlag(tmplPipelinePs)}, } From f7e8c8b5f8ef1171d6e377f83fb4b252d5467d1e Mon Sep 17 00:00:00 2001 From: smainz Date: Mon, 15 Jul 2024 22:24:33 +0200 Subject: [PATCH 02/15] Print newline between log lines --- cli/pipeline/logs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index c4dfc0698aa..2e9c5863bb3 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -59,7 +59,7 @@ func pipelineLogs(c *cli.Context) error { } for _, log := range logs { - fmt.Print(string(log.Data)) + fmt.Println(string(log.Data)) } return nil From 1afb19a673077ff6ee0123c548e857002241dd76 Mon Sep 17 00:00:00 2001 From: smainz Date: Mon, 15 Jul 2024 22:27:32 +0200 Subject: [PATCH 03/15] Provide better error messages for false arguments --- cli/pipeline/logs.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 2e9c5863bb3..211b72b84ad 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -36,17 +36,26 @@ func pipelineLogs(c *cli.Context) error { if err != nil { return err } + 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 err + return fmt.Errorf("invalid repo-id or repo-full-name: '%s'", repoIDOrFullName) } - numberArgIndex := 1 - number, err := strconv.ParseInt(c.Args().Get(numberArgIndex), 10, 64) + pipelineArg := c.Args().Get(1) + if len(pipelineArg) == 0 { + return fmt.Errorf("missing required argument pipeline") + } + number, err := strconv.ParseInt(pipelineArg, 10, 64) if err != nil { - return err + return fmt.Errorf("invalid pipeline '%s'", pipelineArg) } + if err != nil { + return fmt.Errorf("invalid stepId '%s'", stepArg) + } stepArgIndex := 2 step, err := strconv.ParseInt(c.Args().Get(stepArgIndex), 10, 64) if err != nil { From 148009f402753e3693b301d04453731821e6f803 Mon Sep 17 00:00:00 2001 From: smainz Date: Mon, 15 Jul 2024 22:28:21 +0200 Subject: [PATCH 04/15] Add option to print complete pipeline log --- cli/pipeline/logs.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 211b72b84ad..86a4d2b7efd 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -21,6 +21,7 @@ import ( "github.com/urfave/cli/v2" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) var pipelineLogsCmd = &cli.Command{ @@ -53,15 +54,38 @@ func pipelineLogs(c *cli.Context) error { return fmt.Errorf("invalid pipeline '%s'", pipelineArg) } + stepArg := c.Args().Get(2) + if len(stepArg) == 0 { + return showPipelineLog(client, repoID, number) + } + + step, err := strconv.ParseInt(stepArg, 10, 64) if err != nil { return fmt.Errorf("invalid stepId '%s'", stepArg) } - stepArgIndex := 2 - step, err := strconv.ParseInt(c.Args().Get(stepArgIndex), 10, 64) + return showStepLog(client, repoID, number, step) +} + +func showPipelineLog(client woodpecker.Client, repoID, number int64) error { + pipeline, err := client.Pipeline(repoID, number) if err != nil { return err } + for _, workflow := range pipeline.Workflows { + for _, step := range workflow.Children { + fmt.Printf("\x1b[33mWorflow #%d\x1b[0m ('%s'), \x1b[33mStep #%d\x1b[0m ('%s'):\n", workflow.PID, workflow.Name, step.PID, step.Name) + err := showStepLog(client, repoID, number, step.ID) + if err != nil { + return err + } + } + } + + return nil +} + +func showStepLog(client woodpecker.Client, repoID, number, step int64) error { logs, err := client.StepLogEntries(repoID, number, step) if err != nil { return err From 528c331c4c2f762dc22556bfca88a5a314c05668 Mon Sep 17 00:00:00 2001 From: smainz Date: Mon, 15 Jul 2024 20:34:06 +0200 Subject: [PATCH 05/15] Print Workflow and ID of steps (e.g. for use in pipeline logs) --- cli/pipeline/ps.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index a12b8a7422a..10441a7cee5 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -15,6 +15,7 @@ package pipeline import ( + "fmt" "os" "strconv" "text/template" @@ -23,8 +24,14 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) +type workflowStep struct { + Workflow *woodpecker.Workflow + Step *woodpecker.Step +} + var pipelinePsCmd = &cli.Command{ Name: "ps", Usage: "show pipeline steps", @@ -41,7 +48,7 @@ func pipelinePs(c *cli.Context) error { } repoID, err := internal.ParseRepo(client, repoIDOrFullName) if err != nil { - return err + return fmt.Errorf("invalid repo-id or repo-full-name: '%s'", repoIDOrFullName) } pipelineArg := c.Args().Get(1) @@ -72,9 +79,9 @@ func pipelinePs(c *cli.Context) error { return err } - for _, step := range pipeline.Workflows { - for _, child := range step.Children { - if err := tmpl.Execute(os.Stdout, child); err != nil { + for _, workflow := range pipeline.Workflows { + for _, step := range workflow.Children { + if err := tmpl.Execute(os.Stdout, workflowStep{workflow, step}); err != nil { return err } } @@ -83,8 +90,9 @@ func pipelinePs(c *cli.Context) error { return nil } -// Template for pipeline ps information. -var tmplPipelinePs = "\x1b[33mStep #{{ .PID }} \x1b[0m" + ` -Step: {{ .Name }} -State: {{ .State }} +// template for pipeline ps information +var tmplPipelinePs = "\x1b[33mWorkflow #{{ .Workflow.ID }} ({{ .Workflow.Name }}), Step #{{ .Step.PID }} \x1b[0m" + ` +Id: {{ .Step.ID }} +Step: {{ .Step.Name }} +State: {{ .Step.State }} ` From 3bc784dc4813adc72bf06f47f2ca0a35061e5fcd Mon Sep 17 00:00:00 2001 From: smainz Date: Tue, 16 Jul 2024 18:34:18 +0200 Subject: [PATCH 06/15] Wrap error message --- cli/pipeline/logs.go | 6 +++--- cli/pipeline/ps.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 86a4d2b7efd..cb840104877 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -42,7 +42,7 @@ func pipelineLogs(c *cli.Context) error { } repoID, err := internal.ParseRepo(client, repoIDOrFullName) if err != nil { - return fmt.Errorf("invalid repo-id or repo-full-name: '%s'", repoIDOrFullName) + return fmt.Errorf("invalid repo '%s': %w ", repoIDOrFullName, err) } pipelineArg := c.Args().Get(1) @@ -51,7 +51,7 @@ func pipelineLogs(c *cli.Context) error { } number, err := strconv.ParseInt(pipelineArg, 10, 64) if err != nil { - return fmt.Errorf("invalid pipeline '%s'", pipelineArg) + return fmt.Errorf("invalid pipeline '%s': %w", pipelineArg, err) } stepArg := c.Args().Get(2) @@ -61,7 +61,7 @@ func pipelineLogs(c *cli.Context) error { step, err := strconv.ParseInt(stepArg, 10, 64) if err != nil { - return fmt.Errorf("invalid stepId '%s'", stepArg) + return fmt.Errorf("invalid stepId '%s': %w", stepArg, err) } return showStepLog(client, repoID, number, step) } diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index 10441a7cee5..161870120a8 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -48,7 +48,7 @@ func pipelinePs(c *cli.Context) error { } repoID, err := internal.ParseRepo(client, repoIDOrFullName) if err != nil { - return fmt.Errorf("invalid repo-id or repo-full-name: '%s'", repoIDOrFullName) + return fmt.Errorf("invalid repo '%s': %w", repoIDOrFullName, err) } pipelineArg := c.Args().Get(1) @@ -65,7 +65,7 @@ func pipelinePs(c *cli.Context) error { } else { number, err = strconv.ParseInt(pipelineArg, 10, 64) if err != nil { - return err + return fmt.Errorf("invalid pipeline '%s': %w", pipelineArg, err) } } From c94ab169060bbc149ca4efe62e877e2f321fd20a Mon Sep 17 00:00:00 2001 From: smainz Date: Tue, 16 Jul 2024 19:09:25 +0200 Subject: [PATCH 07/15] Change output template --- cli/pipeline/logs.go | 3 +++ cli/pipeline/ps.go | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index cb840104877..78c7c55660c 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -97,3 +97,6 @@ func showStepLog(client woodpecker.Client, repoID, number, step int64) error { return nil } + +// template for pipeline ps information +var tmplPipelineLogs = "\x1b[33m{{ .Workflow.Name }} > {{ .Step.Name }} (#{{ .Step.PID }}):\x1b[0m" diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index 161870120a8..be3f5554427 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -91,8 +91,10 @@ func pipelinePs(c *cli.Context) error { } // template for pipeline ps information -var tmplPipelinePs = "\x1b[33mWorkflow #{{ .Workflow.ID }} ({{ .Workflow.Name }}), Step #{{ .Step.PID }} \x1b[0m" + ` -Id: {{ .Step.ID }} +var tmplPipelinePs = "\x1b[33m{{ .Workflow.Name }} > {{ .Step.Name }} (#{{ .Step.PID }}):\x1b[0m" + ` Step: {{ .Step.Name }} +Started: {{ .Step.Started }} +Started: {{ .Step.Stopped }} +Type: {{ .Step.Type }} State: {{ .Step.State }} ` From 4873b93c354be0d266ca7f5f83b6a40d4ef4c10e Mon Sep 17 00:00:00 2001 From: smainz Date: Tue, 16 Jul 2024 19:10:48 +0200 Subject: [PATCH 08/15] Get rid of stepID, use step number (PID) or step name instead --- cli/pipeline/logs.go | 52 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 78c7c55660c..df42af46f2d 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -16,7 +16,9 @@ package pipeline import ( "fmt" + "os" "strconv" + "text/template" "github.com/urfave/cli/v2" @@ -27,7 +29,7 @@ import ( var pipelineLogsCmd = &cli.Command{ Name: "logs", Usage: "show pipeline logs", - ArgsUsage: " [stepID]", + ArgsUsage: " [step-number|step-name]", Action: pipelineLogs, } @@ -59,22 +61,64 @@ func pipelineLogs(c *cli.Context) error { return showPipelineLog(client, repoID, number) } - step, err := strconv.ParseInt(stepArg, 10, 64) + step, err := ParseStep(client, repoID, number, stepArg) if err != nil { - return fmt.Errorf("invalid stepId '%s': %w", stepArg, err) + return fmt.Errorf("invalid step '%s': %w", stepArg, err) } return showStepLog(client, repoID, number, step) } +/* +Parse stepArg into a steps ID for a given pipeline in a repo. Argument stepArg may either be the +name of a step or the PID of a step. Step PID take precedence over step name when searching for a match. +First match is used, is there are multiple steps with the same name. +*/ +func ParseStep(client woodpecker.Client, repoID, number int64, stepArg string) (int64, error) { + pipeline, err := client.Pipeline(repoID, number) + if err != nil { + return 0, err + } + + stepPID, err := strconv.ParseInt(stepArg, 10, 64) + if err != nil { + stepPID = -1 + } + + for _, wf := range pipeline.Workflows { + for _, step := range wf.Children { + if int64(step.PID) == stepPID { + return step.ID, nil + } + } + } + + for _, wf := range pipeline.Workflows { + for _, step := range wf.Children { + if step.Name == stepArg { + return step.ID, nil + } + } + } + + return 0, fmt.Errorf("no step with number or name '%s' found", stepArg) +} + func showPipelineLog(client woodpecker.Client, repoID, number int64) error { pipeline, err := client.Pipeline(repoID, number) if err != nil { return err } + tmpl, err := template.New("_").Parse(tmplPipelineLogs + "\n") + if err != nil { + return err + } + for _, workflow := range pipeline.Workflows { for _, step := range workflow.Children { - fmt.Printf("\x1b[33mWorflow #%d\x1b[0m ('%s'), \x1b[33mStep #%d\x1b[0m ('%s'):\n", workflow.PID, workflow.Name, step.PID, step.Name) + if err := tmpl.Execute(os.Stdout, workflowStep{workflow, step}); err != nil { + return err + } err := showStepLog(client, repoID, number, step.ID) if err != nil { return err From 4a32de41c49f95674081094179036f4d78beb733 Mon Sep 17 00:00:00 2001 From: smainz Date: Wed, 17 Jul 2024 10:57:02 +0200 Subject: [PATCH 09/15] Move ParseStep to internal --- cli/internal/util.go | 37 +++++++++++++++++++++++++++++++++++++ cli/pipeline/logs.go | 37 +------------------------------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/cli/internal/util.go b/cli/internal/util.go index 001752ed3d9..aece5b07573 100644 --- a/cli/internal/util.go +++ b/cli/internal/util.go @@ -161,3 +161,40 @@ func ParseKeyPair(p []string) map[string]string { } return params } + +/* +ParseStep parses the step id form a string which may eigher be the step PID (step number) or a step name. +These rules apply: + + - Step PID take precedence over step name when searching for a match. + - First match is used, when there are multiple steps with the same name. + +Strictly speaking, this is not parsing, but a lookup. +*/ +func ParseStep(client woodpecker.Client, repoID, number int64, stepArg string) (stepID int64, err error) { + pipeline, err := client.Pipeline(repoID, number) + if err != nil { + return 0, err + } + + stepPID, err := strconv.ParseInt(stepArg, 10, 64) + if err == nil { + for _, wf := range pipeline.Workflows { + for _, step := range wf.Children { + if int64(step.PID) == stepPID { + return step.ID, nil + } + } + } + } + + for _, wf := range pipeline.Workflows { + for _, step := range wf.Children { + if step.Name == stepArg { + return step.ID, nil + } + } + } + + return 0, fmt.Errorf("no step with number or name '%s' found", stepArg) +} diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index df42af46f2d..31334f09d56 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -61,48 +61,13 @@ func pipelineLogs(c *cli.Context) error { return showPipelineLog(client, repoID, number) } - step, err := ParseStep(client, repoID, number, stepArg) + 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) } -/* -Parse stepArg into a steps ID for a given pipeline in a repo. Argument stepArg may either be the -name of a step or the PID of a step. Step PID take precedence over step name when searching for a match. -First match is used, is there are multiple steps with the same name. -*/ -func ParseStep(client woodpecker.Client, repoID, number int64, stepArg string) (int64, error) { - pipeline, err := client.Pipeline(repoID, number) - if err != nil { - return 0, err - } - - stepPID, err := strconv.ParseInt(stepArg, 10, 64) - if err != nil { - stepPID = -1 - } - - for _, wf := range pipeline.Workflows { - for _, step := range wf.Children { - if int64(step.PID) == stepPID { - return step.ID, nil - } - } - } - - for _, wf := range pipeline.Workflows { - for _, step := range wf.Children { - if step.Name == stepArg { - return step.ID, nil - } - } - } - - return 0, fmt.Errorf("no step with number or name '%s' found", stepArg) -} - func showPipelineLog(client woodpecker.Client, repoID, number int64) error { pipeline, err := client.Pipeline(repoID, number) if err != nil { From 77680ccf825042b10f342401a39305ba8f6b347a Mon Sep 17 00:00:00 2001 From: smainz Date: Wed, 17 Jul 2024 13:56:29 +0200 Subject: [PATCH 10/15] Fix text. Co-authored-by: Thomas Anderson <127358482+zc-devs@users.noreply.github.com> --- cli/pipeline/ps.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index be3f5554427..df1da86a868 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -94,7 +94,7 @@ func pipelinePs(c *cli.Context) error { var tmplPipelinePs = "\x1b[33m{{ .Workflow.Name }} > {{ .Step.Name }} (#{{ .Step.PID }}):\x1b[0m" + ` Step: {{ .Step.Name }} Started: {{ .Step.Started }} -Started: {{ .Step.Stopped }} +Stopped: {{ .Step.Stopped }} Type: {{ .Step.Type }} State: {{ .Step.State }} ` From 358f254869e2e1266f7723011789ca078585747b Mon Sep 17 00:00:00 2001 From: smainz Date: Wed, 17 Jul 2024 20:57:05 +0200 Subject: [PATCH 11/15] Change struct to map for use in template. --- cli/pipeline/logs.go | 4 ++-- cli/pipeline/ps.go | 20 +++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 31334f09d56..931ce6a0c7a 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -81,7 +81,7 @@ func showPipelineLog(client woodpecker.Client, repoID, number int64) error { for _, workflow := range pipeline.Workflows { for _, step := range workflow.Children { - if err := tmpl.Execute(os.Stdout, workflowStep{workflow, step}); err != nil { + if err := tmpl.Execute(os.Stdout, map[string]any{"workflow": workflow, "step": step}); err != nil { return err } err := showStepLog(client, repoID, number, step.ID) @@ -108,4 +108,4 @@ func showStepLog(client woodpecker.Client, repoID, number, step int64) error { } // template for pipeline ps information -var tmplPipelineLogs = "\x1b[33m{{ .Workflow.Name }} > {{ .Step.Name }} (#{{ .Step.PID }}):\x1b[0m" +var tmplPipelineLogs = "\x1b[33m{{ .workflow.Name }} > {{ .step.Name }} (#{{ .step.PID }}):\x1b[0m" diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index df1da86a868..4d9f37ec00c 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -24,14 +24,8 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" - "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) -type workflowStep struct { - Workflow *woodpecker.Workflow - Step *woodpecker.Step -} - var pipelinePsCmd = &cli.Command{ Name: "ps", Usage: "show pipeline steps", @@ -81,7 +75,7 @@ func pipelinePs(c *cli.Context) error { for _, workflow := range pipeline.Workflows { for _, step := range workflow.Children { - if err := tmpl.Execute(os.Stdout, workflowStep{workflow, step}); err != nil { + if err := tmpl.Execute(os.Stdout, map[string]any{"workflow": workflow, "step": step}); err != nil { return err } } @@ -91,10 +85,10 @@ func pipelinePs(c *cli.Context) error { } // template for pipeline ps information -var tmplPipelinePs = "\x1b[33m{{ .Workflow.Name }} > {{ .Step.Name }} (#{{ .Step.PID }}):\x1b[0m" + ` -Step: {{ .Step.Name }} -Started: {{ .Step.Started }} -Stopped: {{ .Step.Stopped }} -Type: {{ .Step.Type }} -State: {{ .Step.State }} +var tmplPipelinePs = "\x1b[33m{{ .workflow.Name }} > {{ .step.Name }} (#{{ .step.PID }}):\x1b[0m" + ` +Step: {{ .step.Name }} +Started: {{ .step.Started }} +Stopped: {{ .step.Stopped }} +Type: {{ .step.Type }} +State: {{ .step.State }} ` From 6a3a920e4e29255ed1095a3ba363570229b71f19 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 18 Jul 2024 19:38:54 +0200 Subject: [PATCH 12/15] update docs --- docs/versioned_docs/version-2.7/40-cli.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/versioned_docs/version-2.7/40-cli.md b/docs/versioned_docs/version-2.7/40-cli.md index c3fe425ae8e..8e4e62358a7 100644 --- a/docs/versioned_docs/version-2.7/40-cli.md +++ b/docs/versioned_docs/version-2.7/40-cli.md @@ -345,9 +345,12 @@ Message: {{ .Message }} show pipeline steps -**--format**="": format output (default: Step #{{ .PID }}  -Step: {{ .Name }} -State: {{ .State }} +**--format**="": format output (default: {{ .workflow.Name }} > {{ .step.Name }} (#{{ .step.PID }}): +Step: {{ .step.Name }} +Started: {{ .step.Started }} +Stopped: {{ .step.Stopped }} +Type: {{ .step.Type }} +State: {{ .step.State }} ) ### create From 8090ebc5100aa678a06336d5580506724da8590a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 18 Jul 2024 19:43:24 +0200 Subject: [PATCH 13/15] fix linter errors --- cli/internal/util.go | 6 +++--- cli/pipeline/logs.go | 4 ++-- cli/pipeline/ps.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/internal/util.go b/cli/internal/util.go index 87c6f8f435c..e705dc9f994 100644 --- a/cli/internal/util.go +++ b/cli/internal/util.go @@ -163,11 +163,11 @@ func ParseKeyPair(p []string) map[string]string { } /* -ParseStep parses the step id form a string which may eigher be the step PID (step number) or a step name. +ParseStep parses the step id form a string which may either be the step PID (step number) or a step name. These rules apply: - - Step PID take precedence over step name when searching for a match. - - First match is used, when there are multiple steps with the same name. +- Step PID take precedence over step name when searching for a match. +- First match is used, when there are multiple steps with the same name. Strictly speaking, this is not parsing, but a lookup. */ diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index 5910a4a8100..f7725bc46ac 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -57,7 +57,7 @@ func pipelineLogs(ctx context.Context, c *cli.Command) error { return fmt.Errorf("invalid pipeline '%s': %w", pipelineArg, err) } - stepArg := c.Args().Get(2) + stepArg := c.Args().Get(2) //nolint:mnd if len(stepArg) == 0 { return showPipelineLog(client, repoID, number) } @@ -108,5 +108,5 @@ func showStepLog(client woodpecker.Client, repoID, number, step int64) error { return nil } -// template for pipeline ps information +// template for pipeline ps information. var tmplPipelineLogs = "\x1b[33m{{ .workflow.Name }} > {{ .step.Name }} (#{{ .step.PID }}):\x1b[0m" diff --git a/cli/pipeline/ps.go b/cli/pipeline/ps.go index 6369289d6c2..6aca08545d3 100644 --- a/cli/pipeline/ps.go +++ b/cli/pipeline/ps.go @@ -85,7 +85,7 @@ func pipelinePs(ctx context.Context, c *cli.Command) error { return nil } -// template for pipeline ps information +// template for pipeline ps information. var tmplPipelinePs = "\x1b[33m{{ .workflow.Name }} > {{ .step.Name }} (#{{ .step.PID }}):\x1b[0m" + ` Step: {{ .step.Name }} Started: {{ .step.Started }} From 3cf9a892cb6191eb4c2f5c28fde129a528846a3a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 18 Jul 2024 20:23:27 +0200 Subject: [PATCH 14/15] make non breaking --- cli/internal/util.go | 19 +++++++++++++------ cli/pipeline/logs.go | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cli/internal/util.go b/cli/internal/util.go index e705dc9f994..0ea1c488674 100644 --- a/cli/internal/util.go +++ b/cli/internal/util.go @@ -170,6 +170,8 @@ These rules apply: - First match is used, when there are multiple steps with the same name. Strictly speaking, this is not parsing, but a lookup. + +TODO: Use PID instead of StepID */ func ParseStep(client woodpecker.Client, repoID, number int64, stepArg string) (stepID int64, err error) { pipeline, err := client.Pipeline(repoID, number) @@ -177,15 +179,20 @@ func ParseStep(client woodpecker.Client, repoID, number int64, stepArg string) ( return 0, err } - stepPID, err := strconv.ParseInt(stepArg, 10, 64) + stepID, err = strconv.ParseInt(stepArg, 10, 64) + // TODO: for 3.0 do "stepPID, err := strconv.ParseInt(stepArg, 10, 64)" if err == nil { - for _, wf := range pipeline.Workflows { - for _, step := range wf.Children { - if int64(step.PID) == stepPID { - return step.ID, nil + return stepID, nil + /* + // TODO: for 3.0 + for _, wf := range pipeline.Workflows { + for _, step := range wf.Children { + if int64(step.PID) == stepPID { + return step.ID, nil + } } } - } + */ } for _, wf := range pipeline.Workflows { diff --git a/cli/pipeline/logs.go b/cli/pipeline/logs.go index f7725bc46ac..6ad19fc6f14 100644 --- a/cli/pipeline/logs.go +++ b/cli/pipeline/logs.go @@ -30,8 +30,9 @@ import ( var pipelineLogsCmd = &cli.Command{ Name: "logs", Usage: "show pipeline logs", - ArgsUsage: " [step-number|step-name]", - Action: pipelineLogs, + ArgsUsage: " [step-id|step-name]", + // TODO: for v3.0 do `ArgsUsage: " [step-number|step-name]",` + Action: pipelineLogs, } func pipelineLogs(ctx context.Context, c *cli.Command) error { From e714ab2506e35b6fed9550a0799ff37c51afed16 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 18 Jul 2024 20:24:41 +0200 Subject: [PATCH 15/15] nit --- cli/internal/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/internal/util.go b/cli/internal/util.go index 0ea1c488674..2e8cbb63e4c 100644 --- a/cli/internal/util.go +++ b/cli/internal/util.go @@ -166,7 +166,7 @@ func ParseKeyPair(p []string) map[string]string { ParseStep parses the step id form a string which may either be the step PID (step number) or a step name. These rules apply: -- Step PID take precedence over step name when searching for a match. +- Step ID take precedence over step name when searching for a match. - First match is used, when there are multiple steps with the same name. Strictly speaking, this is not parsing, but a lookup.