From 74047bee0d5b08a24fbe5f986758a47fc08fc4b6 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Tue, 8 Dec 2020 19:07:43 +0100 Subject: [PATCH 1/7] add subcomands for notifications Fix #243 Signed-off-by: Karl Heinz Marbaise --- cmd/notifications.go | 31 ++++++++++--------- cmd/notifications/list.go | 40 ++++++++++++++++++++++++ cmd/notifications/pinned.go | 41 +++++++++++++++++++++++++ cmd/notifications/read.go | 41 +++++++++++++++++++++++++ cmd/notifications/unread.go | 41 +++++++++++++++++++++++++ modules/task/notifications_list.go | 49 ++++++++++++++++++++++++++++++ 6 files changed, 228 insertions(+), 15 deletions(-) create mode 100644 cmd/notifications/list.go create mode 100644 cmd/notifications/pinned.go create mode 100644 cmd/notifications/read.go create mode 100644 cmd/notifications/unread.go create mode 100644 modules/task/notifications_list.go diff --git a/cmd/notifications.go b/cmd/notifications.go index 3cab988..b72d605 100644 --- a/cmd/notifications.go +++ b/cmd/notifications.go @@ -5,7 +5,9 @@ package cmd import ( - "code.gitea.io/tea/cmd/flags" + "log" + + "code.gitea.io/tea/cmd/notifications" "code.gitea.io/tea/modules/context" "code.gitea.io/tea/modules/print" @@ -18,27 +20,21 @@ var CmdNotifications = cli.Command{ Name: "notifications", Aliases: []string{"notification", "n"}, Usage: "Show notifications", - Description: "Show notifications, by default based of the current repo and unread one", + Description: "Show notifications, by default based of the current repo", Action: runNotifications, + Subcommands: []*cli.Command{ + ¬ifications.CmdNotificationsList, + ¬ifications.CmdNotificationsPinned, + ¬ifications.CmdNotificationsRead, + ¬ifications.CmdNotificationsUnread, + }, Flags: append([]cli.Flag{ &cli.BoolFlag{ Name: "all", Aliases: []string{"a"}, Usage: "show all notifications of related gitea instance", }, - &cli.BoolFlag{ - Name: "read", - Aliases: []string{"rd"}, - Usage: "show read notifications instead unread", - }, - &cli.BoolFlag{ - Name: "pinned", - Aliases: []string{"pd"}, - Usage: "show pinned notifications instead unread", - }, - &flags.PaginationPageFlag, - &flags.PaginationLimitFlag, - }, flags.AllDefaultFlags...), + }), } func runNotifications(cmd *cli.Context) error { @@ -80,3 +76,8 @@ func runNotifications(cmd *cli.Context) error { print.NotificationsList(news, ctx.Output, ctx.Bool("all")) return nil } + +func runNotificationsDetails(ctx *cli.Context) error { + log.Fatal("Not yet implemented.") + return nil +} diff --git a/cmd/notifications/list.go b/cmd/notifications/list.go new file mode 100644 index 0000000..caf5bb5 --- /dev/null +++ b/cmd/notifications/list.go @@ -0,0 +1,40 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package notifications + +import ( + "code.gitea.io/sdk/gitea" + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/task" + "github.com/urfave/cli/v2" +) + +// CmdNotificationsList represents a sub command of notifications to list notifications +var CmdNotificationsList = cli.Command{ + Name: "ls", + Aliases: []string{"list"}, + Usage: "List notifications....", + Description: `List notification....`, + Action: RunNotificationsList, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "show all notifications of related gitea instance", + }, + &cli.StringFlag{ + Name: "state", + Usage: "Filter by milestone state (all|open|closed)", + DefaultText: "open", + }, + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, + }, flags.AllDefaultFlags...), +} + +// RunNotificationsList list notifications +func RunNotificationsList(ctx *cli.Context) error { + return task.ListNotifications(ctx, []gitea.NotifyStatus{}) +} diff --git a/cmd/notifications/pinned.go b/cmd/notifications/pinned.go new file mode 100644 index 0000000..85432ed --- /dev/null +++ b/cmd/notifications/pinned.go @@ -0,0 +1,41 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package notifications + +import ( + "code.gitea.io/sdk/gitea" + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/task" + "github.com/urfave/cli/v2" +) + +// CmdNotificationsPinned represents a sub command of notifications to list pinned notifications +var CmdNotificationsPinned = cli.Command{ + Name: "pinned", + Aliases: []string{"pin"}, + Usage: "show pinned notifications", + Description: `show pinned notifications`, + Action: RunNotificationsPinned, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "show all notifications of related gitea instance", + }, + &cli.StringFlag{ + Name: "state", + Usage: "Filter by milestone state (all|open|closed)", + DefaultText: "open", + }, + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, + }, flags.AllDefaultFlags...), +} + +// RunNotificationsPinned will show notifications with status pinned. +func RunNotificationsPinned(ctx *cli.Context) error { + var statuses = []gitea.NotifyStatus{gitea.NotifyStatusPinned} + return task.ListNotifications(ctx, statuses) +} diff --git a/cmd/notifications/read.go b/cmd/notifications/read.go new file mode 100644 index 0000000..c4dc810 --- /dev/null +++ b/cmd/notifications/read.go @@ -0,0 +1,41 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package notifications + +import ( + "code.gitea.io/sdk/gitea" + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/task" + "github.com/urfave/cli/v2" +) + +// CmdNotificationsRead represents a sub command of notifications to list read notifications +var CmdNotificationsRead = cli.Command{ + Name: "read", + Aliases: []string{}, + Usage: "show read notifications instead", + Description: `show read notifications instead`, + Action: RunNotificationsRead, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "show all notifications of related gitea instance", + }, + &cli.StringFlag{ + Name: "state", + Usage: "Filter by milestone state (all|open|closed)", + DefaultText: "open", + }, + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, + }, flags.AllDefaultFlags...), +} + +// RunNotificationsList list notifications +func RunNotificationsRead(ctx *cli.Context) error { + var statuses = []gitea.NotifyStatus{gitea.NotifyStatusRead} + return task.ListNotifications(ctx, statuses) +} diff --git a/cmd/notifications/unread.go b/cmd/notifications/unread.go new file mode 100644 index 0000000..4a41756 --- /dev/null +++ b/cmd/notifications/unread.go @@ -0,0 +1,41 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package notifications + +import ( + "code.gitea.io/sdk/gitea" + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/task" + "github.com/urfave/cli/v2" +) + +// CmdNotificationsUnread represents a sub command of notifications to list unread notifications. +var CmdNotificationsUnread = cli.Command{ + Name: "unread", + Aliases: []string{}, + Usage: "show unread notifications", + Description: `show unread notifications`, + Action: RunNotificationsUnread, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "show all notifications of related gitea instance", + }, + &cli.StringFlag{ + Name: "state", + Usage: "Filter by milestone state (all|open|closed)", + DefaultText: "open", + }, + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, + }, flags.AllDefaultFlags...), +} + +// RunNotificationsList list notifications +func RunNotificationsUnread(ctx *cli.Context) error { + var statuses = []gitea.NotifyStatus{gitea.NotifyStatusUnread} + return task.ListNotifications(ctx, statuses) +} diff --git a/modules/task/notifications_list.go b/modules/task/notifications_list.go new file mode 100644 index 0000000..b27c2d3 --- /dev/null +++ b/modules/task/notifications_list.go @@ -0,0 +1,49 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package task + +import ( + "log" + + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/config" + "code.gitea.io/tea/modules/print" + + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli/v2" +) + +func ListNotifications(ctx *cli.Context, status []gitea.NotifyStatus) error { + + //TODO: What is the purpose of the following? + listOpts := flags.GetListOptions(ctx) + if listOpts.Page == 0 { + listOpts.Page = 1 + } + + var news []*gitea.NotificationThread + var err error + + var allRelated = ctx.Bool("all") + if allRelated { + login := config.InitCommandLoginOnly(flags.GlobalLoginValue) + news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{ + ListOptions: listOpts, + Status: status, + }) + } else { + login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue) + news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{ + ListOptions: listOpts, + Status: status, + }) + } + if err != nil { + log.Fatal(err) + } + + print.NotificationsList(news, flags.GlobalOutputValue, allRelated) + return nil +} -- 2.40.1 From 75ad6b84848403a8303ef9af2de819b79533b455 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Tue, 8 Dec 2020 20:59:21 +0100 Subject: [PATCH 2/7] Added missing comment on exported function. --- modules/task/notifications_list.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/task/notifications_list.go b/modules/task/notifications_list.go index b27c2d3..58d6151 100644 --- a/modules/task/notifications_list.go +++ b/modules/task/notifications_list.go @@ -15,6 +15,7 @@ import ( "github.com/urfave/cli/v2" ) +//ListNotifications will get the notifications based on status func ListNotifications(ctx *cli.Context, status []gitea.NotifyStatus) error { //TODO: What is the purpose of the following? -- 2.40.1 From f9787139286e8a29a83d0ae02523577061389b68 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Tue, 8 Dec 2020 21:06:15 +0100 Subject: [PATCH 3/7] Fixed exported function comments. Signed-off-by: Karl Heinz Marbaise --- cmd/notifications/read.go | 2 +- cmd/notifications/unread.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/notifications/read.go b/cmd/notifications/read.go index c4dc810..95112ca 100644 --- a/cmd/notifications/read.go +++ b/cmd/notifications/read.go @@ -34,7 +34,7 @@ var CmdNotificationsRead = cli.Command{ }, flags.AllDefaultFlags...), } -// RunNotificationsList list notifications +// RunNotificationsRead will show notifications with status read. func RunNotificationsRead(ctx *cli.Context) error { var statuses = []gitea.NotifyStatus{gitea.NotifyStatusRead} return task.ListNotifications(ctx, statuses) diff --git a/cmd/notifications/unread.go b/cmd/notifications/unread.go index 4a41756..587a9ad 100644 --- a/cmd/notifications/unread.go +++ b/cmd/notifications/unread.go @@ -34,7 +34,7 @@ var CmdNotificationsUnread = cli.Command{ }, flags.AllDefaultFlags...), } -// RunNotificationsList list notifications +// RunNotificationsUnread will show notifications with status unread. func RunNotificationsUnread(ctx *cli.Context) error { var statuses = []gitea.NotifyStatus{gitea.NotifyStatusUnread} return task.ListNotifications(ctx, statuses) -- 2.40.1 From 91b5db3e420034e53e925e4d8b86692aab08f842 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Tue, 8 Dec 2020 21:30:09 +0100 Subject: [PATCH 4/7] Integrated review comments. Signed-off-by: Karl Heinz Marbaise --- cmd/flags/flags.go | 11 +++++++++++ cmd/notifications/list.go | 19 +++---------------- cmd/notifications/pinned.go | 17 ++--------------- cmd/notifications/read.go | 15 +-------------- cmd/notifications/unread.go | 15 +-------------- 5 files changed, 18 insertions(+), 59 deletions(-) diff --git a/cmd/flags/flags.go b/cmd/flags/flags.go index d9fe526..ac2b91a 100644 --- a/cmd/flags/flags.go +++ b/cmd/flags/flags.go @@ -91,3 +91,14 @@ var IssuePRFlags = append([]cli.Flag{ &PaginationPageFlag, &PaginationLimitFlag, }, AllDefaultFlags...) + +// NotificationFlags defines flags that should be available on notifications. +var NotificationFlags = append([]cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Show notifications across all your repositories instead of the current repository only", + }, + &PaginationPageFlag, + &PaginationLimitFlag, +}, AllDefaultFlags...) diff --git a/cmd/notifications/list.go b/cmd/notifications/list.go index caf5bb5..32f0fd9 100644 --- a/cmd/notifications/list.go +++ b/cmd/notifications/list.go @@ -15,23 +15,10 @@ import ( var CmdNotificationsList = cli.Command{ Name: "ls", Aliases: []string{"list"}, - Usage: "List notifications....", - Description: `List notification....`, + Usage: "List notifications", + Description: `List notifications`, Action: RunNotificationsList, - Flags: append([]cli.Flag{ - &cli.BoolFlag{ - Name: "all", - Aliases: []string{"a"}, - Usage: "show all notifications of related gitea instance", - }, - &cli.StringFlag{ - Name: "state", - Usage: "Filter by milestone state (all|open|closed)", - DefaultText: "open", - }, - &flags.PaginationPageFlag, - &flags.PaginationLimitFlag, - }, flags.AllDefaultFlags...), + Flags: flags.NotificationFlags, } // RunNotificationsList list notifications diff --git a/cmd/notifications/pinned.go b/cmd/notifications/pinned.go index 85432ed..0c8cef6 100644 --- a/cmd/notifications/pinned.go +++ b/cmd/notifications/pinned.go @@ -14,24 +14,11 @@ import ( // CmdNotificationsPinned represents a sub command of notifications to list pinned notifications var CmdNotificationsPinned = cli.Command{ Name: "pinned", - Aliases: []string{"pin"}, + Aliases: []string{"pd"}, Usage: "show pinned notifications", Description: `show pinned notifications`, Action: RunNotificationsPinned, - Flags: append([]cli.Flag{ - &cli.BoolFlag{ - Name: "all", - Aliases: []string{"a"}, - Usage: "show all notifications of related gitea instance", - }, - &cli.StringFlag{ - Name: "state", - Usage: "Filter by milestone state (all|open|closed)", - DefaultText: "open", - }, - &flags.PaginationPageFlag, - &flags.PaginationLimitFlag, - }, flags.AllDefaultFlags...), + Flags: flags.NotificationFlags, } // RunNotificationsPinned will show notifications with status pinned. diff --git a/cmd/notifications/read.go b/cmd/notifications/read.go index 95112ca..0636259 100644 --- a/cmd/notifications/read.go +++ b/cmd/notifications/read.go @@ -18,20 +18,7 @@ var CmdNotificationsRead = cli.Command{ Usage: "show read notifications instead", Description: `show read notifications instead`, Action: RunNotificationsRead, - Flags: append([]cli.Flag{ - &cli.BoolFlag{ - Name: "all", - Aliases: []string{"a"}, - Usage: "show all notifications of related gitea instance", - }, - &cli.StringFlag{ - Name: "state", - Usage: "Filter by milestone state (all|open|closed)", - DefaultText: "open", - }, - &flags.PaginationPageFlag, - &flags.PaginationLimitFlag, - }, flags.AllDefaultFlags...), + Flags: flags.NotificationFlags, } // RunNotificationsRead will show notifications with status read. diff --git a/cmd/notifications/unread.go b/cmd/notifications/unread.go index 587a9ad..1c35118 100644 --- a/cmd/notifications/unread.go +++ b/cmd/notifications/unread.go @@ -18,20 +18,7 @@ var CmdNotificationsUnread = cli.Command{ Usage: "show unread notifications", Description: `show unread notifications`, Action: RunNotificationsUnread, - Flags: append([]cli.Flag{ - &cli.BoolFlag{ - Name: "all", - Aliases: []string{"a"}, - Usage: "show all notifications of related gitea instance", - }, - &cli.StringFlag{ - Name: "state", - Usage: "Filter by milestone state (all|open|closed)", - DefaultText: "open", - }, - &flags.PaginationPageFlag, - &flags.PaginationLimitFlag, - }, flags.AllDefaultFlags...), + Flags: flags.NotificationFlags, } // RunNotificationsUnread will show notifications with status unread. -- 2.40.1 From 481132ffdb5e97fce4d160ad0cec109f1861c59d Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Thu, 10 Dec 2020 08:01:05 +0100 Subject: [PATCH 5/7] Moved notifications_list from task into cmd/notifications Signed-off-by: Karl Heinz Marbaise --- cmd/notifications/list.go | 3 +-- {modules/task => cmd/notifications}/notifications_list.go | 8 ++++---- cmd/notifications/pinned.go | 3 +-- cmd/notifications/read.go | 3 +-- cmd/notifications/unread.go | 3 +-- 5 files changed, 8 insertions(+), 12 deletions(-) rename {modules/task => cmd/notifications}/notifications_list.go (86%) diff --git a/cmd/notifications/list.go b/cmd/notifications/list.go index 32f0fd9..f05961e 100644 --- a/cmd/notifications/list.go +++ b/cmd/notifications/list.go @@ -7,7 +7,6 @@ package notifications import ( "code.gitea.io/sdk/gitea" "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/task" "github.com/urfave/cli/v2" ) @@ -23,5 +22,5 @@ var CmdNotificationsList = cli.Command{ // RunNotificationsList list notifications func RunNotificationsList(ctx *cli.Context) error { - return task.ListNotifications(ctx, []gitea.NotifyStatus{}) + return listNotifications(ctx, []gitea.NotifyStatus{}) } diff --git a/modules/task/notifications_list.go b/cmd/notifications/notifications_list.go similarity index 86% rename from modules/task/notifications_list.go rename to cmd/notifications/notifications_list.go index 58d6151..b0120a8 100644 --- a/modules/task/notifications_list.go +++ b/cmd/notifications/notifications_list.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package task +package notifications import ( "log" @@ -15,10 +15,10 @@ import ( "github.com/urfave/cli/v2" ) -//ListNotifications will get the notifications based on status -func ListNotifications(ctx *cli.Context, status []gitea.NotifyStatus) error { +//listNotifications will get the notifications based on status +func listNotifications(ctx *cli.Context, status []gitea.NotifyStatus) error { - //TODO: What is the purpose of the following? + //This enforces pagination. listOpts := flags.GetListOptions(ctx) if listOpts.Page == 0 { listOpts.Page = 1 diff --git a/cmd/notifications/pinned.go b/cmd/notifications/pinned.go index 0c8cef6..9904c2f 100644 --- a/cmd/notifications/pinned.go +++ b/cmd/notifications/pinned.go @@ -7,7 +7,6 @@ package notifications import ( "code.gitea.io/sdk/gitea" "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/task" "github.com/urfave/cli/v2" ) @@ -24,5 +23,5 @@ var CmdNotificationsPinned = cli.Command{ // RunNotificationsPinned will show notifications with status pinned. func RunNotificationsPinned(ctx *cli.Context) error { var statuses = []gitea.NotifyStatus{gitea.NotifyStatusPinned} - return task.ListNotifications(ctx, statuses) + return listNotifications(ctx, statuses) } diff --git a/cmd/notifications/read.go b/cmd/notifications/read.go index 0636259..40cb428 100644 --- a/cmd/notifications/read.go +++ b/cmd/notifications/read.go @@ -7,7 +7,6 @@ package notifications import ( "code.gitea.io/sdk/gitea" "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/task" "github.com/urfave/cli/v2" ) @@ -24,5 +23,5 @@ var CmdNotificationsRead = cli.Command{ // RunNotificationsRead will show notifications with status read. func RunNotificationsRead(ctx *cli.Context) error { var statuses = []gitea.NotifyStatus{gitea.NotifyStatusRead} - return task.ListNotifications(ctx, statuses) + return listNotifications(ctx, statuses) } diff --git a/cmd/notifications/unread.go b/cmd/notifications/unread.go index 1c35118..262665e 100644 --- a/cmd/notifications/unread.go +++ b/cmd/notifications/unread.go @@ -7,7 +7,6 @@ package notifications import ( "code.gitea.io/sdk/gitea" "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/task" "github.com/urfave/cli/v2" ) @@ -24,5 +23,5 @@ var CmdNotificationsUnread = cli.Command{ // RunNotificationsUnread will show notifications with status unread. func RunNotificationsUnread(ctx *cli.Context) error { var statuses = []gitea.NotifyStatus{gitea.NotifyStatusUnread} - return task.ListNotifications(ctx, statuses) + return listNotifications(ctx, statuses) } -- 2.40.1 From 31bd1cc6b1d9c69751d4c4989346acb6b3e33d65 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Fri, 11 Dec 2020 20:50:46 +0100 Subject: [PATCH 6/7] WIP. Cleanuped / ... --- cmd/notifications.go | 7 ++++- cmd/notifications/list.go | 41 +++++++++++++++++++++++-- cmd/notifications/notifications_list.go | 8 +++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/cmd/notifications.go b/cmd/notifications.go index b72d605..73e3630 100644 --- a/cmd/notifications.go +++ b/cmd/notifications.go @@ -34,6 +34,11 @@ var CmdNotifications = cli.Command{ Aliases: []string{"a"}, Usage: "show all notifications of related gitea instance", }, + &cli.StringFlag{ + Name: "state", + Usage: "set milestone state (default is open)", + DefaultText: "open", + }, }), } @@ -78,6 +83,6 @@ func runNotifications(cmd *cli.Context) error { } func runNotificationsDetails(ctx *cli.Context) error { - log.Fatal("Not yet implemented.") + log.Fatal("Use tea notif --help to see all available commands.") return nil } diff --git a/cmd/notifications/list.go b/cmd/notifications/list.go index f05961e..3f18a1f 100644 --- a/cmd/notifications/list.go +++ b/cmd/notifications/list.go @@ -6,7 +6,7 @@ package notifications import ( "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" + "fmt" "github.com/urfave/cli/v2" ) @@ -17,10 +17,45 @@ var CmdNotificationsList = cli.Command{ Usage: "List notifications", Description: `List notifications`, Action: RunNotificationsList, - Flags: flags.NotificationFlags, + // Flags: flags.NotificationFlags, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "show all notifications of related gitea instance", + }, + &cli.StringFlag{ + Name: "state", + Usage: "set notification state (default is all), pinned,read,unread", + DefaultText: "xxx", + }, + }), } +// notif ls +// notif ls --state all +// notif ls --state pinned +// notif ls --state read +// notif ls --state unread + // RunNotificationsList list notifications func RunNotificationsList(ctx *cli.Context) error { - return listNotifications(ctx, []gitea.NotifyStatus{}) + // --states all + + states := []gitea.NotifyStatus{gitea.NotifyStatusRead, gitea.NotifyStatusPinned} + + switch ctx.String("state") { + case "all": + states = []gitea.NotifyStatus{gitea.NotifyStatusPinned, gitea.NotifyStatusRead, gitea.NotifyStatusUnread} + case "pinned": + states = []gitea.NotifyStatus{gitea.NotifyStatusPinned} + case "read": + states = []gitea.NotifyStatus{gitea.NotifyStatusRead} + case "unread": + states = []gitea.NotifyStatus{gitea.NotifyStatusUnread} + default: + return fmt.Errorf("invalid notification state type '%s'. valid: all, pinned,read,unread", ctx.String("state")) + } + + return listNotifications(ctx, states) } diff --git a/cmd/notifications/notifications_list.go b/cmd/notifications/notifications_list.go index b0120a8..d6cc060 100644 --- a/cmd/notifications/notifications_list.go +++ b/cmd/notifications/notifications_list.go @@ -5,6 +5,7 @@ package notifications import ( + "fmt" "log" "code.gitea.io/tea/cmd/flags" @@ -28,14 +29,17 @@ func listNotifications(ctx *cli.Context, status []gitea.NotifyStatus) error { var err error var allRelated = ctx.Bool("all") + fmt.Printf("allRelated: %t\n", allRelated) + + login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue) if allRelated { - login := config.InitCommandLoginOnly(flags.GlobalLoginValue) + fmt.Printf("login: %s owner: %s repo:%s\n", login.Name, owner, repo) news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{ ListOptions: listOpts, Status: status, }) } else { - login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue) + fmt.Printf("login: %s owner: %s repo:%s\n", login.Name, owner, repo) news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{ ListOptions: listOpts, Status: status, -- 2.40.1 From abd32a70747f421ff14dc86eedcf5408dbeb90c4 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Sat, 12 Dec 2020 18:08:07 +0100 Subject: [PATCH 7/7] WIP - Improved. --- cmd/notifications/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/notifications/list.go b/cmd/notifications/list.go index 3f18a1f..1ae8a76 100644 --- a/cmd/notifications/list.go +++ b/cmd/notifications/list.go @@ -42,7 +42,7 @@ var CmdNotificationsList = cli.Command{ func RunNotificationsList(ctx *cli.Context) error { // --states all - states := []gitea.NotifyStatus{gitea.NotifyStatusRead, gitea.NotifyStatusPinned} + states := []gitea.NotifyStatus{} switch ctx.String("state") { case "all": -- 2.40.1