mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
replace flag globals, require context for commands (#291)
introduce TeaContext clean up InitCommand move GetListOptions to TeaContext ensure context for each command so we fail early with a good error message instead of "Error: 404" etc make linter happy Merge branch 'master' into refactor-global-flags move TeaContext & InitCommand to modules/context Merge branch 'master' into refactor-global-flags CI.restart() Merge branch 'master' into refactor-global-flags Merge branch 'master' into refactor-global-flags Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/291 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -43,13 +43,14 @@ var CmdNotifications = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runNotifications(ctx *cli.Context) error {
|
||||
func runNotifications(cmd *cli.Context) error {
|
||||
var news []*gitea.NotificationThread
|
||||
var err error
|
||||
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
listOpts := flags.GetListOptions(ctx)
|
||||
listOpts := ctx.GetListOptions()
|
||||
if listOpts.Page == 0 {
|
||||
listOpts.Page = 1
|
||||
}
|
||||
@ -63,12 +64,13 @@ func runNotifications(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
if ctx.Bool("all") {
|
||||
news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{
|
||||
news, _, err = client.ListNotifications(gitea.ListNotificationOptions{
|
||||
ListOptions: listOpts,
|
||||
Status: status,
|
||||
})
|
||||
} else {
|
||||
news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
news, _, err = client.ListRepoNotifications(ctx.Owner, ctx.Repo, gitea.ListNotificationOptions{
|
||||
ListOptions: listOpts,
|
||||
Status: status,
|
||||
})
|
||||
@ -77,6 +79,6 @@ func runNotifications(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.NotificationsList(news, flags.GlobalOutputValue, ctx.Bool("all"))
|
||||
print.NotificationsList(news, ctx.Output, ctx.Bool("all"))
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user