Add Pagination Options for List Subcomands (#204)
Add Pagination Options for List subcomands Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/204 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
parent
887495f38f
commit
cf2c18c32b
|
@ -22,6 +22,7 @@ import (
|
||||||
"code.gitea.io/tea/modules/utils"
|
"code.gitea.io/tea/modules/utils"
|
||||||
|
|
||||||
"github.com/muesli/termenv"
|
"github.com/muesli/termenv"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -271,3 +272,15 @@ func curGitRepoPath(path string) (*Login, string, error) {
|
||||||
|
|
||||||
return nil, "", errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository")
|
return nil, "", errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getListOptions(ctx *cli.Context) gitea.ListOptions {
|
||||||
|
page := ctx.Int("page")
|
||||||
|
limit := ctx.Int("limit")
|
||||||
|
if limit != 0 && page == 0 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
return gitea.ListOptions{
|
||||||
|
Page: page,
|
||||||
|
PageSize: limit,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
16
cmd/flags.go
16
cmd/flags.go
|
@ -60,6 +60,20 @@ var StateFlag = cli.StringFlag{
|
||||||
DefaultText: "open",
|
DefaultText: "open",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PaginationPageFlag provides flag for pagination options
|
||||||
|
var PaginationPageFlag = cli.StringFlag{
|
||||||
|
Name: "page",
|
||||||
|
Aliases: []string{"p"},
|
||||||
|
Usage: "specify page, default is 1",
|
||||||
|
}
|
||||||
|
|
||||||
|
// PaginationLimitFlag provides flag for pagination options
|
||||||
|
var PaginationLimitFlag = cli.StringFlag{
|
||||||
|
Name: "limit",
|
||||||
|
Aliases: []string{"lm"},
|
||||||
|
Usage: "specify limit of items per page",
|
||||||
|
}
|
||||||
|
|
||||||
// LoginOutputFlags defines login and output flags that should
|
// LoginOutputFlags defines login and output flags that should
|
||||||
// added to all subcommands and appended to the flags of the
|
// added to all subcommands and appended to the flags of the
|
||||||
// subcommand to work around issue and provide --login and --output:
|
// subcommand to work around issue and provide --login and --output:
|
||||||
|
@ -91,6 +105,8 @@ var AllDefaultFlags = append([]cli.Flag{
|
||||||
// IssuePRFlags defines flags that should be available on issue & pr listing flags.
|
// IssuePRFlags defines flags that should be available on issue & pr listing flags.
|
||||||
var IssuePRFlags = append([]cli.Flag{
|
var IssuePRFlags = append([]cli.Flag{
|
||||||
&StateFlag,
|
&StateFlag,
|
||||||
|
&PaginationPageFlag,
|
||||||
|
&PaginationLimitFlag,
|
||||||
}, AllDefaultFlags...)
|
}, AllDefaultFlags...)
|
||||||
|
|
||||||
// initCommand returns repository and *Login based on flags
|
// initCommand returns repository and *Login based on flags
|
||||||
|
|
|
@ -84,8 +84,9 @@ func runIssuesList(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
issues, _, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
issues, _, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||||
State: state,
|
ListOptions: getListOptions(ctx),
|
||||||
Type: gitea.IssueTypeIssue,
|
State: state,
|
||||||
|
Type: gitea.IssueTypeIssue,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,6 +35,8 @@ var CmdLabels = cli.Command{
|
||||||
Aliases: []string{"s"},
|
Aliases: []string{"s"},
|
||||||
Usage: "Save all the labels as a file",
|
Usage: "Save all the labels as a file",
|
||||||
},
|
},
|
||||||
|
&PaginationPageFlag,
|
||||||
|
&PaginationLimitFlag,
|
||||||
}, AllDefaultFlags...),
|
}, AllDefaultFlags...),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ func runLabels(ctx *cli.Context) error {
|
||||||
|
|
||||||
var values [][]string
|
var values [][]string
|
||||||
|
|
||||||
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{})
|
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: getListOptions(ctx)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ var CmdMilestonesIssues = cli.Command{
|
||||||
Name: "kind",
|
Name: "kind",
|
||||||
Usage: "Filter by kind (issue|pull)",
|
Usage: "Filter by kind (issue|pull)",
|
||||||
},
|
},
|
||||||
|
&PaginationPageFlag,
|
||||||
|
&PaginationLimitFlag,
|
||||||
}, AllDefaultFlags...),
|
}, AllDefaultFlags...),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,9 +91,10 @@ func runMilestoneIssueList(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
issues, _, err := client.ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
issues, _, err := client.ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||||
Milestones: []string{milestone},
|
ListOptions: getListOptions(ctx),
|
||||||
Type: kind,
|
Milestones: []string{milestone},
|
||||||
State: state,
|
Type: kind,
|
||||||
|
State: state,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -43,6 +43,8 @@ var CmdMilestonesList = cli.Command{
|
||||||
Usage: "Filter by milestone state (all|open|closed)",
|
Usage: "Filter by milestone state (all|open|closed)",
|
||||||
DefaultText: "open",
|
DefaultText: "open",
|
||||||
},
|
},
|
||||||
|
&PaginationPageFlag,
|
||||||
|
&PaginationLimitFlag,
|
||||||
}, AllDefaultFlags...),
|
}, AllDefaultFlags...),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +88,8 @@ func runMilestonesList(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
milestones, _, err := login.Client().ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{
|
milestones, _, err := login.Client().ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{
|
||||||
State: state,
|
ListOptions: getListOptions(ctx),
|
||||||
|
State: state,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -34,17 +34,8 @@ var CmdNotifications = cli.Command{
|
||||||
Aliases: []string{"pd"},
|
Aliases: []string{"pd"},
|
||||||
Usage: "show pinned notifications instead unread",
|
Usage: "show pinned notifications instead unread",
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&PaginationPageFlag,
|
||||||
Name: "page",
|
&PaginationLimitFlag,
|
||||||
Aliases: []string{"p"},
|
|
||||||
Usage: "specify page, default is 1",
|
|
||||||
Value: 1,
|
|
||||||
},
|
|
||||||
&cli.IntFlag{
|
|
||||||
Name: "limit",
|
|
||||||
Aliases: []string{"lm"},
|
|
||||||
Usage: "specify limit of items per page",
|
|
||||||
},
|
|
||||||
}, AllDefaultFlags...),
|
}, AllDefaultFlags...),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +43,9 @@ func runNotifications(ctx *cli.Context) error {
|
||||||
var news []*gitea.NotificationThread
|
var news []*gitea.NotificationThread
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
listOpts := gitea.ListOptions{
|
listOpts := getListOptions(ctx)
|
||||||
Page: ctx.Int("page"),
|
if listOpts.Page == 0 {
|
||||||
PageSize: ctx.Int("limit"),
|
listOpts.Page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var status []gitea.NotifyStatus
|
var status []gitea.NotifyStatus
|
||||||
|
|
|
@ -39,13 +39,16 @@ var CmdReleaseList = cli.Command{
|
||||||
Usage: "List Releases",
|
Usage: "List Releases",
|
||||||
Description: "List Releases",
|
Description: "List Releases",
|
||||||
Action: runReleases,
|
Action: runReleases,
|
||||||
Flags: AllDefaultFlags,
|
Flags: append([]cli.Flag{
|
||||||
|
&PaginationPageFlag,
|
||||||
|
&PaginationLimitFlag,
|
||||||
|
}, AllDefaultFlags...),
|
||||||
}
|
}
|
||||||
|
|
||||||
func runReleases(ctx *cli.Context) error {
|
func runReleases(ctx *cli.Context) error {
|
||||||
login, owner, repo := initCommand()
|
login, owner, repo := initCommand()
|
||||||
|
|
||||||
releases, _, err := login.Client().ListReleases(owner, repo, gitea.ListReleasesOptions{})
|
releases, _, err := login.Client().ListReleases(owner, repo, gitea.ListReleasesOptions{ListOptions: getListOptions(ctx)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
11
cmd/repos.go
11
cmd/repos.go
|
@ -59,6 +59,8 @@ var CmdReposList = cli.Command{
|
||||||
Required: false,
|
Required: false,
|
||||||
Usage: "Filter archived repos (true|false)",
|
Usage: "Filter archived repos (true|false)",
|
||||||
},
|
},
|
||||||
|
&PaginationPageFlag,
|
||||||
|
&PaginationLimitFlag,
|
||||||
}, LoginOutputFlags...),
|
}, LoginOutputFlags...),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,10 +191,11 @@ func runReposList(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
||||||
OwnerID: ownerID,
|
ListOptions: getListOptions(ctx),
|
||||||
IsPrivate: isPrivate,
|
OwnerID: ownerID,
|
||||||
IsArchived: isArchived,
|
IsPrivate: isPrivate,
|
||||||
Type: mode,
|
IsArchived: isArchived,
|
||||||
|
Type: mode,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue