Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cli/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ func pipelineOutput(c *cli.Command, pipelines []*woodpecker.Pipeline, fd ...io.W
if err := tmpl.Execute(out, pipelines); err != nil {
return err
}
case "go-format":
if len(outOpt) < 1 {
return fmt.Errorf("%w: missing template", output.ErrOutputOptionRequired)
}

tmpl, err := template.New("_").Parse(outOpt[0] + "\n")
if err != nil {
return err
}
for _, p := range pipelines {
if err := tmpl.Execute(out, p); err != nil {
return err
}
}
case "table":
fallthrough
default:
Expand Down
5 changes: 5 additions & 0 deletions cli/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func TestPipelineOutput(t *testing.T) {
args: []string{"output", "--output", "go-template={{range . }}{{.Number}} {{.Status}} {{.Branch}}{{end}}"},
expected: "1 success main\n",
},
{
name: "go-format output",
args: []string{"output", "--output", "go-format={{.Number}} {{.Status}} {{.Branch}}"},
expected: "1 success main\n",
},
{
name: "invalid go-template",
args: []string{"output", "--output", "go-template={{.InvalidField}}"},
Expand Down
14 changes: 14 additions & 0 deletions cli/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ func repoOutput(c *cli.Command, repos []*woodpecker.Repo, fd ...io.Writer) error
if err := tmpl.Execute(out, repos); err != nil {
return err
}
case "go-format":
Comment thread
qwerty287 marked this conversation as resolved.
if len(outOpt) < 1 {
return fmt.Errorf("%w: missing template", output.ErrOutputOptionRequired)
}

tmpl, err := template.New("_").Parse(outOpt[0] + "\n")
if err != nil {
return err
}
for _, r := range repos {
if err := tmpl.Execute(out, r); err != nil {
return err
}
}
case "table":
fallthrough
default:
Expand Down
10 changes: 10 additions & 0 deletions cli/repo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func TestRepoOutput(t *testing.T) {
args: []string{"output", "--output", "go-template={{range . }}{{.Name}} {{.ForgeURL}} {{.Trusted.Network}}{{end}}"},
expected: "repo1 git.example.com true\n",
},
{
name: "go-format output",
args: []string{"output", "--output", "go-format={{.Name}} {{.ForgeURL}} {{.Trusted.Network}}"},
expected: "repo1 git.example.com true\n",
},
{
name: "invalid go-template",
args: []string{"output", "--output", "go-template={{.InvalidField}}"},
wantErr: true,
},
}

repos := []*woodpecker.Repo{
Expand Down