Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(cmd/logs): support paging
  • Loading branch information
wass3rw3rk committed Apr 7, 2023
commit 5c37715adbd638e434094506ff6794a5f9717e97
8 changes: 7 additions & 1 deletion action/log/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ func (c *Config) Get(client *vela.Client) error {

logrus.Tracef("capturing logs for build %s/%s/%d", c.Org, c.Repo, c.Build)

// create list options for logs call
opts := &vela.ListOptions{
Page: c.Page,
PerPage: c.PerPage,
}

// send API call to capture a list of build logs
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#BuildService.GetLogs
logs, _, err := client.Build.GetLogs(c.Org, c.Repo, c.Build)
logs, _, err := client.Build.GetLogs(c.Org, c.Repo, c.Build, opts)
if err != nil {
return err
}
Expand Down
60 changes: 35 additions & 25 deletions action/log/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,61 @@ func TestLog_Config_Get(t *testing.T) {
{
failure: false,
config: &Config{
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Output: "",
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Page: 1,
PerPage: 10,
Output: "",
},
},
{
failure: false,
config: &Config{
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Output: "dump",
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Page: 1,
PerPage: 10,
Output: "dump",
},
},
{
failure: false,
config: &Config{
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Output: "json",
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Page: 1,
PerPage: 10,
Output: "json",
},
},
{
failure: false,
config: &Config{
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Output: "spew",
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Page: 1,
PerPage: 10,
Output: "spew",
},
},
{
failure: false,
config: &Config{
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Output: "yaml",
Action: "get",
Org: "github",
Repo: "octocat",
Build: 1,
Page: 1,
PerPage: 10,
Output: "yaml",
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions action/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Config struct {
Org string
Repo string
Build int
Page int
PerPage int
Service int
Step int
Output string
Expand Down
29 changes: 24 additions & 5 deletions command/log/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ var CommandGet = &cli.Command{
Usage: "provide the build for the log",
},

// Pagination Flags

&cli.IntFlag{
EnvVars: []string{"VELA_PAGE", "BUILD_PAGE"},
Name: internal.FlagPage,
Aliases: []string{"p"},
Usage: "print a specific page of logs",
Value: 1,
},
&cli.IntFlag{
EnvVars: []string{"VELA_PER_PAGE", "BUILD_PER_PAGE"},
Name: internal.FlagPerPage,
Aliases: []string{"pp"},
Usage: "number of logs to print per page",
Value: 100,
},

// Output Flags

&cli.StringFlag{
Expand Down Expand Up @@ -96,11 +113,13 @@ func get(c *cli.Context) error {
//
// https://pkg.go.dev/github.com/go-vela/cli/action/log?tab=doc#Config
l := &log.Config{
Action: internal.ActionGet,
Org: c.String(internal.FlagOrg),
Repo: c.String(internal.FlagRepo),
Build: c.Int(internal.FlagBuild),
Output: c.String(internal.FlagOutput),
Action: internal.ActionGet,
Org: c.String(internal.FlagOrg),
Repo: c.String(internal.FlagRepo),
Build: c.Int(internal.FlagBuild),
Page: c.Int(internal.FlagPage),
PerPage: c.Int(internal.FlagPerPage),
Output: c.String(internal.FlagOutput),
}

// validate log configuration
Expand Down
2 changes: 2 additions & 0 deletions command/log/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func TestLog_Get(t *testing.T) {
fullSet.String("org", "github", "doc")
fullSet.String("repo", "octocat", "doc")
fullSet.Int("build", 1, "doc")
fullSet.Int("page", 1, "doc")
fullSet.Int("per.page", 10, "doc")
fullSet.String("output", "json", "doc")

// setup tests
Expand Down