mirror of https://gitlab.com/gitlab-org/cli.git
feat(pagination): add pagination to user events
This commit is contained in:
parent
4cc98286f4
commit
9b80e44bf6
|
@ -4,12 +4,16 @@ import (
|
|||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
var CurrentUserEvents = func(client *gitlab.Client) ([]*gitlab.ContributionEvent, error) {
|
||||
var CurrentUserEvents = func(client *gitlab.Client, opts *gitlab.ListContributionEventsOptions) ([]*gitlab.ContributionEvent, error) {
|
||||
if client == nil {
|
||||
client = apiClient.Lab()
|
||||
}
|
||||
|
||||
events, _, err := client.Events.ListCurrentUserContributionEvents(&gitlab.ListContributionEventsOptions{})
|
||||
if opts.PerPage == 0 {
|
||||
opts.PerPage = DefaultListLimit
|
||||
}
|
||||
|
||||
events, _, err := client.Events.ListCurrentUserContributionEvents(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ func NewCmdEvents(f *cmdutils.Factory) *cobra.Command {
|
|||
cmd := &cobra.Command{
|
||||
Use: "events",
|
||||
Short: "View user events",
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
Args: cobra.ExactArgs(0),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
apiClient, err := f.HttpClient()
|
||||
if err != nil {
|
||||
|
@ -27,7 +27,16 @@ func NewCmdEvents(f *cmdutils.Factory) *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
events, err := api.CurrentUserEvents(apiClient)
|
||||
l := &gitlab.ListContributionEventsOptions{}
|
||||
|
||||
if p, _ := cmd.Flags().GetInt("page"); p != 0 {
|
||||
l.Page = p
|
||||
}
|
||||
if p, _ := cmd.Flags().GetInt("per-page"); p != 0 {
|
||||
l.PerPage = p
|
||||
}
|
||||
|
||||
events, err := api.CurrentUserEvents(apiClient, l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -65,6 +74,8 @@ func NewCmdEvents(f *cmdutils.Factory) *cobra.Command {
|
|||
}
|
||||
|
||||
cmd.Flags().BoolP("all", "a", false, "Get events from all projects")
|
||||
cmd.Flags().IntP("page", "p", 1, "Page number")
|
||||
cmd.Flags().IntP("per-page", "P", 30, "Number of items to list per page")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ glab user events [flags]
|
|||
## Options
|
||||
|
||||
```plaintext
|
||||
-a, --all Get events from all projects
|
||||
-a, --all Get events from all projects
|
||||
-p, --page int Page number (default 1)
|
||||
-P, --per-page int Number of items to list per page (default 30)
|
||||
```
|
||||
|
||||
## Options inherited from parent commands
|
||||
|
|
Loading…
Reference in New Issue