Merge branch 'origin/main' into 'next-release/main'

This commit is contained in:
oauth
2026-01-20 11:58:04 +00:00
4 changed files with 43 additions and 0 deletions

View File

@@ -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:

View File

@@ -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}}"},

View File

@@ -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":
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:

View File

@@ -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{