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"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
"github.com/urfave/cli/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")
|
||||
}
|
||||
|
||||
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",
|
||||
}
|
||||
|
||||
// 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
|
||||
// added to all subcommands and appended to the flags of the
|
||||
// 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.
|
||||
var IssuePRFlags = append([]cli.Flag{
|
||||
&StateFlag,
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...)
|
||||
|
||||
// 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{
|
||||
State: state,
|
||||
Type: gitea.IssueTypeIssue,
|
||||
ListOptions: getListOptions(ctx),
|
||||
State: state,
|
||||
Type: gitea.IssueTypeIssue,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -35,6 +35,8 @@ var CmdLabels = cli.Command{
|
|||
Aliases: []string{"s"},
|
||||
Usage: "Save all the labels as a file",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,7 @@ func runLabels(ctx *cli.Context) error {
|
|||
|
||||
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 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ var CmdMilestonesIssues = cli.Command{
|
|||
Name: "kind",
|
||||
Usage: "Filter by kind (issue|pull)",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
|
@ -89,9 +91,10 @@ func runMilestoneIssueList(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
issues, _, err := client.ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
Milestones: []string{milestone},
|
||||
Type: kind,
|
||||
State: state,
|
||||
ListOptions: getListOptions(ctx),
|
||||
Milestones: []string{milestone},
|
||||
Type: kind,
|
||||
State: state,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -43,6 +43,8 @@ var CmdMilestonesList = cli.Command{
|
|||
Usage: "Filter by milestone state (all|open|closed)",
|
||||
DefaultText: "open",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
|
@ -86,7 +88,8 @@ func runMilestonesList(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
milestones, _, err := login.Client().ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{
|
||||
State: state,
|
||||
ListOptions: getListOptions(ctx),
|
||||
State: state,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -34,17 +34,8 @@ var CmdNotifications = cli.Command{
|
|||
Aliases: []string{"pd"},
|
||||
Usage: "show pinned notifications instead unread",
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "page",
|
||||
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",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
|
@ -52,9 +43,9 @@ func runNotifications(ctx *cli.Context) error {
|
|||
var news []*gitea.NotificationThread
|
||||
var err error
|
||||
|
||||
listOpts := gitea.ListOptions{
|
||||
Page: ctx.Int("page"),
|
||||
PageSize: ctx.Int("limit"),
|
||||
listOpts := getListOptions(ctx)
|
||||
if listOpts.Page == 0 {
|
||||
listOpts.Page = 1
|
||||
}
|
||||
|
||||
var status []gitea.NotifyStatus
|
||||
|
|
|
@ -39,13 +39,16 @@ var CmdReleaseList = cli.Command{
|
|||
Usage: "List Releases",
|
||||
Description: "List Releases",
|
||||
Action: runReleases,
|
||||
Flags: AllDefaultFlags,
|
||||
Flags: append([]cli.Flag{
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleases(ctx *cli.Context) error {
|
||||
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 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
11
cmd/repos.go
11
cmd/repos.go
|
@ -59,6 +59,8 @@ var CmdReposList = cli.Command{
|
|||
Required: false,
|
||||
Usage: "Filter archived repos (true|false)",
|
||||
},
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, LoginOutputFlags...),
|
||||
}
|
||||
|
||||
|
@ -189,10 +191,11 @@ func runReposList(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
||||
OwnerID: ownerID,
|
||||
IsPrivate: isPrivate,
|
||||
IsArchived: isArchived,
|
||||
Type: mode,
|
||||
ListOptions: getListOptions(ctx),
|
||||
OwnerID: ownerID,
|
||||
IsPrivate: isPrivate,
|
||||
IsArchived: isArchived,
|
||||
Type: mode,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue