mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-02-13 21:00:00 +00:00
Merge branch 'origin/main' into 'next-release/main'
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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}}"},
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user