Add PipelineListsOptions to woodpecker-go (#3652)

This commit is contained in:
Robert Kaussow
2024-11-26 11:50:48 +01:00
committed by GitHub
parent f829c07f3a
commit bf1750a291
18 changed files with 861 additions and 160 deletions

View File

@@ -87,7 +87,7 @@ func deploy(ctx context.Context, c *cli.Command) error {
var number int64
if pipelineArg == "last" {
// Fetch the pipeline number from the last pipeline
pipelines, err := client.PipelineList(repoID)
pipelines, err := client.PipelineList(repoID, woodpecker.PipelineListOptions{})
if err != nil {
return err
}
@@ -121,9 +121,12 @@ func deploy(ctx context.Context, c *cli.Command) error {
return fmt.Errorf("please specify the target environment (i.e. production)")
}
params := internal.ParseKeyPair(c.StringSlice("param"))
opt := woodpecker.DeployOptions{
DeployTo: env,
Params: internal.ParseKeyPair(c.StringSlice("param")),
}
deploy, err := client.Deploy(repoID, number, env, params)
deploy, err := client.Deploy(repoID, number, opt)
if err != nil {
return err
}

View File

@@ -48,7 +48,7 @@ func pipelineInfo(ctx context.Context, c *cli.Command) error {
var number int64
if pipelineArg == "last" || len(pipelineArg) == 0 {
// Fetch the pipeline number from the last pipeline
pipeline, err := client.PipelineLast(repoID, "")
pipeline, err := client.PipelineLast(repoID, woodpecker.PipelineLastOptions{})
if err != nil {
return err
}

View File

@@ -49,7 +49,11 @@ func pipelineLast(ctx context.Context, c *cli.Command) error {
return err
}
pipeline, err := client.PipelineLast(repoID, c.String("branch"))
opt := woodpecker.PipelineLastOptions{
Branch: c.String("branch"),
}
pipeline, err := client.PipelineLast(repoID, opt)
if err != nil {
return err
}

View File

@@ -16,6 +16,7 @@ package pipeline
import (
"context"
"time"
"github.com/urfave/cli/v3"
@@ -24,6 +25,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
)
//nolint:mnd
func buildPipelineListCmd() *cli.Command {
return &cli.Command{
Name: "ls",
@@ -46,9 +48,26 @@ func buildPipelineListCmd() *cli.Command {
&cli.IntFlag{
Name: "limit",
Usage: "limit the list size",
//nolint:mnd
Value: 25,
},
&cli.TimestampFlag{
Name: "before",
Usage: "only return pipelines before this RFC3339 date",
Config: cli.TimestampConfig{
Layouts: []string{
time.RFC3339,
},
},
},
&cli.TimestampFlag{
Name: "after",
Usage: "only return pipelines after this RFC3339 date",
Config: cli.TimestampConfig{
Layouts: []string{
time.RFC3339,
},
},
},
}...),
}
}
@@ -74,7 +93,18 @@ func pipelineList(_ context.Context, c *cli.Command, client woodpecker.Client) (
return resources, err
}
pipelines, err := client.PipelineList(repoID)
opt := woodpecker.PipelineListOptions{}
before := c.Timestamp("before")
after := c.Timestamp("after")
if !before.IsZero() {
opt.Before = before
}
if !after.IsZero() {
opt.After = after
}
pipelines, err := client.PipelineList(repoID, opt)
if err != nil {
return resources, err
}

View File

@@ -107,7 +107,7 @@ func TestPipelineList(t *testing.T) {
for _, tt := range testtases {
t.Run(tt.name, func(t *testing.T) {
mockClient := mocks.NewClient(t)
mockClient.On("PipelineList", mock.Anything).Return(tt.pipelines, tt.pipelineErr)
mockClient.On("PipelineList", mock.Anything, mock.Anything).Return(tt.pipelines, tt.pipelineErr)
mockClient.On("RepoLookup", mock.Anything).Return(&woodpecker.Repo{ID: tt.repoID}, nil)
command := buildPipelineListCmd()

View File

@@ -25,6 +25,7 @@ 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"
)
var pipelinePsCmd = &cli.Command{
@@ -51,7 +52,7 @@ func pipelinePs(ctx context.Context, c *cli.Command) error {
if pipelineArg == "last" || len(pipelineArg) == 0 {
// Fetch the pipeline number from the last pipeline
pipeline, err := client.PipelineLast(repoID, "")
pipeline, err := client.PipelineLast(repoID, woodpecker.PipelineLastOptions{})
if err != nil {
return err
}

View File

@@ -23,6 +23,7 @@ import (
"github.com/urfave/cli/v3"
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
)
var pipelineStartCmd = &cli.Command{
@@ -54,7 +55,7 @@ func pipelineStart(ctx context.Context, c *cli.Command) (err error) {
var number int64
if pipelineArg == "last" {
// Fetch the pipeline number from the last pipeline
pipeline, err := client.PipelineLast(repoID, "")
pipeline, err := client.PipelineLast(repoID, woodpecker.PipelineLastOptions{})
if err != nil {
return err
}
@@ -69,9 +70,11 @@ func pipelineStart(ctx context.Context, c *cli.Command) (err error) {
}
}
params := internal.ParseKeyPair(c.StringSlice("param"))
opt := woodpecker.PipelineStartOptions{
Params: internal.ParseKeyPair(c.StringSlice("param")),
}
pipeline, err := client.PipelineStart(repoID, number, params)
pipeline, err := client.PipelineStart(repoID, number, opt)
if err != nil {
return err
}

View File

@@ -22,6 +22,7 @@ import (
"github.com/urfave/cli/v3"
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
)
var repoAddCmd = &cli.Command{
@@ -43,7 +44,11 @@ func repoAdd(ctx context.Context, c *cli.Command) error {
return err
}
repo, err := client.RepoPost(int64(forgeRemoteID))
opt := woodpecker.RepoPostOptions{
ForgeRemoteID: int64(forgeRemoteID),
}
repo, err := client.RepoPost(opt)
if err != nil {
return err
}

View File

@@ -23,6 +23,7 @@ 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"
)
var repoListCmd = &cli.Command{
@@ -36,6 +37,10 @@ var repoListCmd = &cli.Command{
Name: "org",
Usage: "filter by organization",
},
&cli.BoolFlag{
Name: "all",
Usage: "query all repos, including inactive ones",
},
},
}
@@ -45,7 +50,11 @@ func repoList(ctx context.Context, c *cli.Command) error {
return err
}
repos, err := client.RepoList()
opt := woodpecker.RepoListOptions{
All: c.Bool("all"),
}
repos, err := client.RepoList(opt)
if err != nil || len(repos) == 0 {
return err
}
@@ -68,4 +77,4 @@ func repoList(ctx context.Context, c *cli.Command) error {
}
// Template for repository list items.
var tmplRepoList = "\x1b[33m{{ .FullName }}\x1b[0m (id: {{ .ID }}, forgeRemoteID: {{ .ForgeRemoteID }})"
var tmplRepoList = "\x1b[33m{{ .FullName }}\x1b[0m (id: {{ .ID }}, forgeRemoteID: {{ .ForgeRemoteID }}, isActive: {{ .IsActive }})"

View File

@@ -23,6 +23,7 @@ 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"
)
var repoSyncCmd = &cli.Command{
@@ -40,7 +41,11 @@ func repoSync(ctx context.Context, c *cli.Command) error {
return err
}
repos, err := client.RepoListOpts(true)
opt := woodpecker.RepoListOptions{
All: true,
}
repos, err := client.RepoList(opt)
if err != nil || len(repos) == 0 {
return err
}