replace flag globals, require context for commands #291
|
@ -5,7 +5,6 @@
|
|||
package flags
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -92,16 +91,3 @@ var IssuePRFlags = append([]cli.Flag{
|
|||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...)
|
||||
|
||||
// GetListOptions return ListOptions based on PaginationFlags
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func RunIssuesList(cmd *cli.Context) error {
|
|||
}
|
||||
|
||||
issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
State: state,
|
||||
Type: gitea.IssueTypeIssue,
|
||||
})
|
||||
|
|
|
@ -39,7 +39,7 @@ func RunLabelsList(cmd *cli.Context) error {
|
|||
ctx := config.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
labels, _, err := client.ListRepoLabels(ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -95,7 +95,7 @@ func runMilestoneIssueList(cmd *cli.Context) error {
|
|||
}
|
||||
|
||||
issues, _, err := client.ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
Milestones: []string{milestone},
|
||||
Type: kind,
|
||||
State: state,
|
||||
|
|
|
@ -47,7 +47,7 @@ func RunMilestonesList(cmd *cli.Context) error {
|
|||
|
||||
client := ctx.Login.Client()
|
||||
milestones, _, err := client.ListRepoMilestones(ctx.Owner, ctx.Repo, gitea.ListMilestoneOption{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
State: state,
|
||||
})
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ func runNotifications(cmd *cli.Context) error {
|
|||
ctx := config.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
listOpts := flags.GetListOptions(cmd)
|
||||
listOpts := ctx.GetListOptions()
|
||||
if listOpts.Page == 0 {
|
||||
listOpts.Page = 1
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func RunOrganizationList(cmd *cli.Context) error {
|
|||
client := ctx.Login.Client()
|
||||
|
||||
userOrganizations, _, err := client.ListUserOrgs(ctx.Login.User, gitea.ListOrgsOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -34,7 +34,7 @@ func RunReleasesList(cmd *cli.Context) error {
|
|||
ctx := config.InitCommand(cmd)
|
||||
|
||||
releases, _, err := ctx.Login.Client().ListReleases(ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -60,14 +60,14 @@ func RunReposList(cmd *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
rps, _, err = client.SearchRepos(gitea.SearchRepoOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
StarredByUserID: user.ID,
|
||||
})
|
||||
} else if ctx.Bool("watched") {
|
||||
rps, _, err = client.GetMyWatchedRepos() // TODO: this does not expose pagination..
|
||||
} else {
|
||||
rps, _, err = client.ListMyRepos(gitea.ListReposOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ func runReposSearch(cmd *cli.Context) error {
|
|||
}
|
||||
|
||||
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
OwnerID: ownerID,
|
||||
IsPrivate: isPrivate,
|
||||
IsArchived: isArchived,
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/modules/git"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
|
@ -29,6 +30,19 @@ type TeaContext struct {
|
|||
LocalRepo *git.TeaRepo // maybe, we have opened it already anyway
|
||||
}
|
||||
|
||||
// GetListOptions return ListOptions based on PaginationFlags
|
||||
func (ctx *TeaContext) GetListOptions() gitea.ListOptions {
|
||||
page := ctx.Int("page")
|
||||
limit := ctx.Int("limit")
|
||||
if limit != 0 && page == 0 {
|
||||
page = 1
|
||||
}
|
||||
return gitea.ListOptions{
|
||||
Page: page,
|
||||
PageSize: limit,
|
||||
}
|
||||
}
|
||||
|
||||
// InitCommand resolves the application context, and returns the active login, and if
|
||||
// available the repo slug. It does this by reading the config file for logins, parsing
|
||||
// the remotes of the .git repo specified in repoFlag or $PWD, and using overrides from
|
||||
|
|
Loading…
Reference in New Issue
Block a user