Skip to content

Commit

Permalink
fix(cmd/logs): support paging (#431)
Browse files Browse the repository at this point in the history
* fix(cmd/logs): support paging

* pull in latest sdk
  • Loading branch information
wass3rw3rk authored Apr 7, 2023
1 parent 1bb410f commit 4612e32
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 50 deletions.
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
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ go 1.19

require (
github.com/Masterminds/semver/v3 v3.2.0
github.com/buildkite/yaml v0.0.0-20210326113714-4a3f40911396
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835
github.com/cli/browser v1.1.0
github.com/davecgh/go-spew v1.1.1
github.com/dustin/go-humanize v1.0.1
github.com/go-git/go-git/v5 v5.5.2
github.com/go-vela/sdk-go v0.18.1
github.com/go-vela/server v0.18.1
github.com/go-vela/types v0.18.1
github.com/go-vela/worker v0.18.1
github.com/go-vela/sdk-go v0.18.2-0.20230407134447-c34cd778f44a
github.com/go-vela/server v0.18.2-0.20230405140822-34164d0412e2
github.com/go-vela/types v0.18.2-0.20230321015315-6c723879639c
github.com/go-vela/worker v0.18.2-0.20230406165141-c76c2e460786
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/gosuri/uitable v0.0.4
github.com/manifoldco/promptui v0.9.0
Expand Down Expand Up @@ -102,6 +102,7 @@ require (
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
Expand All @@ -112,7 +113,7 @@ require (
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
Expand Down
28 changes: 15 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/buildkite/yaml v0.0.0-20210326113714-4a3f40911396 h1:qLN32md48xyTEqw6XEZMyNMre7njm0XXvDrea6NVwOM=
github.com/buildkite/yaml v0.0.0-20210326113714-4a3f40911396/go.mod h1:AV5wtJnn1/CRaRGlJ8xspkMWfKXV0/pkJVgGleTIrfk=
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835 h1:Zfkih+Opdv9y5AOob+8iMsaMYnans+Ozrkb8wiPHbj0=
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835/go.mod h1:AV5wtJnn1/CRaRGlJ8xspkMWfKXV0/pkJVgGleTIrfk=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA=
Expand Down Expand Up @@ -157,14 +157,14 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/go-vela/sdk-go v0.18.1 h1:qsm8XWjr9btNDL8c58JC93sstRUybL/TklWgeeft860=
github.com/go-vela/sdk-go v0.18.1/go.mod h1:QmfXBAdJ9prgE78TK13XJI8YjvGZA5hc+h79CbvgYGU=
github.com/go-vela/server v0.18.1 h1:INd+nwLh0c+WA+8diIh4scLkByGBGZHiyVd5doLSolQ=
github.com/go-vela/server v0.18.1/go.mod h1:WyJEXyJYYASfqN9PDuHqlBTbhsSRIzOn1E7tM2phZMA=
github.com/go-vela/types v0.18.1 h1:V/luHLnCEaJhD1m9PZCZicIasg8Op6MCK+utkz+gQiU=
github.com/go-vela/types v0.18.1/go.mod h1:6MzMhLaXKSZ9wiJveieqnBd2+4ZMS7yv7+POGSITyS8=
github.com/go-vela/worker v0.18.1 h1:2dIbi0LtI59apny6yR4xVbjTMZdDnmrpedrPQKO6F3s=
github.com/go-vela/worker v0.18.1/go.mod h1:3HtiTN5vzmnljsEGW65IikXEop/iL1ekZr3coyGysXA=
github.com/go-vela/sdk-go v0.18.2-0.20230407134447-c34cd778f44a h1:OCOrVvYm0QzOFyUy095aWlOjAzM7WBlhepqpxsOLKjc=
github.com/go-vela/sdk-go v0.18.2-0.20230407134447-c34cd778f44a/go.mod h1:fBWXDlvDaGhKgV5/gzTLR5MR6+4Um0RG25tlu/xOQHo=
github.com/go-vela/server v0.18.2-0.20230405140822-34164d0412e2 h1:KsxVnbFhpe8QcuqfA6/4UTDIMiKUkCCS3t3Egn52lns=
github.com/go-vela/server v0.18.2-0.20230405140822-34164d0412e2/go.mod h1:b+7XeGHO4ynIinY9mpWb6ye9psdwHpsAqMWy5oC+zJ0=
github.com/go-vela/types v0.18.2-0.20230321015315-6c723879639c h1:lnCL1knUGvgZQG4YBHSs/CZnxNBfqFUBlGhyq9LO9uk=
github.com/go-vela/types v0.18.2-0.20230321015315-6c723879639c/go.mod h1:6MzMhLaXKSZ9wiJveieqnBd2+4ZMS7yv7+POGSITyS8=
github.com/go-vela/worker v0.18.2-0.20230406165141-c76c2e460786 h1:cE3B/pCDJzr8CsFd+c1nGVviB+9VmW9nkZn69IrMlj0=
github.com/go-vela/worker v0.18.2-0.20230406165141-c76c2e460786/go.mod h1:IjSc7hc9uGSSw/TtPntIFbR25ftmiThJrQ588BgtYFk=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down Expand Up @@ -372,8 +372,10 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU=
Expand Down Expand Up @@ -560,8 +562,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down

0 comments on commit 4612e32

Please sign in to comment.