mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-03 04:27:21 -05:00
7e191eb18b
split modules/config login_tasks.go should probably be modules/task/login.go, but i didn't do that, as it still depends on the global `Config` variable from the config module, see https://gitea.com/gitea/tea/issues/158 rework InitCommand() - make it error tolerant if $PWD is not a git repo (#200) - don't force default login when repo flag is set (#191) remove InitCommandLoginOnly() Merge branch 'master' into issue-200-initcommand improve docs Merge branch 'master' into issue-200-initcommand move config func and config task func to right place Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/285 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
// 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 cmd
|
|
|
|
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"
|
|
)
|
|
|
|
// CmdNotifications is the main command to operate with notifications
|
|
var CmdNotifications = cli.Command{
|
|
Name: "notifications",
|
|
Aliases: []string{"notification", "notif"},
|
|
Usage: "Show notifications",
|
|
Description: "Show notifications, by default based of the current repo and unread one",
|
|
Action: runNotifications,
|
|
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(ctx *cli.Context) error {
|
|
var news []*gitea.NotificationThread
|
|
var err error
|
|
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
|
|
|
listOpts := flags.GetListOptions(ctx)
|
|
if listOpts.Page == 0 {
|
|
listOpts.Page = 1
|
|
}
|
|
|
|
var status []gitea.NotifyStatus
|
|
if ctx.Bool("read") {
|
|
status = []gitea.NotifyStatus{gitea.NotifyStatusRead}
|
|
}
|
|
if ctx.Bool("pinned") {
|
|
status = append(status, gitea.NotifyStatusPinned)
|
|
}
|
|
|
|
if ctx.Bool("all") {
|
|
news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{
|
|
ListOptions: listOpts,
|
|
Status: status,
|
|
})
|
|
} else {
|
|
news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{
|
|
ListOptions: listOpts,
|
|
Status: status,
|
|
})
|
|
}
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
print.NotificationsList(news, flags.GlobalOutputValue, ctx.Bool("all"))
|
|
return nil
|
|
}
|