Merge pull request 'feat: 新建 notification 模块并注册' (#8) from dw into master

This commit is contained in:
lindiwen23 2026-06-03 09:19:02 +08:00
commit e9c4b5b0aa
2 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,68 @@
package notification
import (
"fmt"
"net/url"
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
)
func Shortcuts() []*common.Shortcut {
return []*common.Shortcut{
{
Name: "list",
Description: "列出通知",
Flags: []common.Flag{
{Name: "all", Usage: "显示所有通知(含已读)", Bool: true, Default: "false"},
{Name: "participating", Usage: "仅显示参与的通知", Bool: true, Default: "false"},
{Name: "page", Short: "p", Usage: "页码", Default: "1"},
{Name: "limit", Short: "l", Usage: "每页数量", Default: "20"},
},
Run: func(ctx *common.RuntimeContext) error {
q := url.Values{}
q.Set("page", ctx.Arg("page"))
q.Set("limit", ctx.Arg("limit"))
if ctx.Arg("all") == "true" {
q.Set("all", "true")
}
if ctx.Arg("participating") == "true" {
q.Set("participating", "true")
}
env, err := ctx.CallAPIWithQuery("GET", "/notifications", q)
if err != nil {
return err
}
return ctx.Output(env)
},
},
{
Name: "read",
Description: "标记单条通知为已读",
Flags: []common.Flag{
{Name: "id", Short: "i", Usage: "通知 ID", Required: true},
},
Run: func(ctx *common.RuntimeContext) error {
id, err := ctx.RequireArg("id")
if err != nil {
return err
}
env, err := ctx.CallAPI("PUT", fmt.Sprintf("/notifications/%s", id), nil)
if err != nil {
return err
}
return ctx.Output(env)
},
},
{
Name: "read-all",
Description: "标记所有通知为已读",
Run: func(ctx *common.RuntimeContext) error {
env, err := ctx.CallAPI("PUT", "/notifications", nil)
if err != nil {
return err
}
return ctx.Output(env)
},
},
}
}

View File

@ -12,6 +12,7 @@ import (
"github.com/gitlink-org/gitlink-cli/shortcuts/label"
"github.com/gitlink-org/gitlink-cli/shortcuts/member"
"github.com/gitlink-org/gitlink-cli/shortcuts/milestone"
"github.com/gitlink-org/gitlink-cli/shortcuts/notification"
"github.com/gitlink-org/gitlink-cli/shortcuts/org"
"github.com/gitlink-org/gitlink-cli/shortcuts/pipeline"
"github.com/gitlink-org/gitlink-cli/shortcuts/pr"
@ -35,6 +36,7 @@ func RegisterAll(root *cobra.Command, translators ...*i18n.Translator) {
"label": label.Shortcuts(),
"member": member.Shortcuts(),
"milestone": milestone.Shortcuts(),
"notification": notification.Shortcuts(),
"pipeline": pipeline.Shortcuts(),
"pr": pr.Shortcuts(tr),
"release": release.Shortcuts(tr),
@ -53,7 +55,8 @@ func RegisterAll(root *cobra.Command, translators ...*i18n.Translator) {
"issue": tr.T("cmd.issue.short"),
"label": "Issue label operations",
"member": "Repository member operations",
"milestone": "Milestone operations",
"milestone": "Milestone operations"
"notification": "Notification operations",
"pipeline": "Pipeline operations",
"pr": tr.T("cmd.pr.short"),
"release": tr.T("cmd.release.short"),