From f638dba99bee55cda1576557aed62833b6bca00a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 2 Feb 2026 22:58:25 +0000 Subject: [PATCH] More improvements (#870) - no duplicate logins - link to html page rather than api in output - client side pagination of watched repos Reviewed-on: https://gitea.com/gitea/tea/pulls/870 Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- cmd/notifications/mark_as.go | 8 ++++++-- cmd/repos/list.go | 37 ++++++++++++++++++++++++++++++++++-- modules/config/login.go | 7 +++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cmd/notifications/mark_as.go b/cmd/notifications/mark_as.go index a9d1525..fb25e00 100644 --- a/cmd/notifications/mark_as.go +++ b/cmd/notifications/mark_as.go @@ -130,8 +130,12 @@ func markNotificationAs(cmd *context.TeaContext, filterStates []string, targetSt if err != nil { return err } - // FIXME: this is an API URL, we want to display a web ui link.. - fmt.Println(n.Subject.URL) + // Use LatestCommentHTMLURL if available, otherwise fall back to HTMLURL + if n.Subject.LatestCommentHTMLURL != "" { + fmt.Println(n.Subject.LatestCommentHTMLURL) + } else { + fmt.Println(n.Subject.HTMLURL) + } return nil } diff --git a/cmd/repos/list.go b/cmd/repos/list.go index e09d4e5..5b9209f 100644 --- a/cmd/repos/list.go +++ b/cmd/repos/list.go @@ -72,11 +72,13 @@ func RunReposList(_ stdctx.Context, cmd *cli.Command) error { return err } } else if teaCmd.Bool("watched") { - var err error - rps, _, err = client.GetMyWatchedRepos() // TODO: this does not expose pagination.. + // GetMyWatchedRepos doesn't expose server-side pagination, + // so we implement client-side pagination as a workaround + allRepos, _, err := client.GetMyWatchedRepos() if err != nil { return err } + rps = paginateRepos(allRepos, flags.GetListOptions()) } else { var err error rps, _, err = client.ListMyRepos(gitea.ListReposOptions{ @@ -123,3 +125,34 @@ func filterReposByType(repos []*gitea.Repository, t gitea.RepoType) []*gitea.Rep } return filtered } + +// paginateRepos implements client-side pagination for repositories. +// This is a workaround for API endpoints that don't support server-side pagination. +func paginateRepos(repos []*gitea.Repository, opts gitea.ListOptions) []*gitea.Repository { + if len(repos) == 0 { + return repos + } + + pageSize := opts.PageSize + if pageSize <= 0 { + pageSize = flags.PaginationLimitFlag.Value + } + + page := opts.Page + if page < 1 { + page = 1 + } + + start := (page - 1) * pageSize + end := start + pageSize + + if start >= len(repos) { + return []*gitea.Repository{} + } + + if end > len(repos) { + end = len(repos) + } + + return repos[start:end] +} diff --git a/modules/config/login.go b/modules/config/login.go index fb71b9e..0e7f79f 100644 --- a/modules/config/login.go +++ b/modules/config/login.go @@ -170,6 +170,13 @@ func AddLogin(login *Login) error { return err } + // Check for duplicate login names + for _, existing := range config.Logins { + if strings.EqualFold(existing.Name, login.Name) { + return fmt.Errorf("login name '%s' already exists", login.Name) + } + } + // save login to global var config.Logins = append(config.Logins, *login)