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 <techknowlogick@gitea.com>
Co-committed-by: techknowlogick <techknowlogick@gitea.com>
This commit is contained in:
techknowlogick
2026-02-02 22:58:25 +00:00
committed by techknowlogick
parent 20da414145
commit f638dba99b
3 changed files with 48 additions and 4 deletions

View File

@@ -130,8 +130,12 @@ func markNotificationAs(cmd *context.TeaContext, filterStates []string, targetSt
if err != nil { if err != nil {
return err return err
} }
// FIXME: this is an API URL, we want to display a web ui link.. // Use LatestCommentHTMLURL if available, otherwise fall back to HTMLURL
fmt.Println(n.Subject.URL) if n.Subject.LatestCommentHTMLURL != "" {
fmt.Println(n.Subject.LatestCommentHTMLURL)
} else {
fmt.Println(n.Subject.HTMLURL)
}
return nil return nil
} }

View File

@@ -72,11 +72,13 @@ func RunReposList(_ stdctx.Context, cmd *cli.Command) error {
return err return err
} }
} else if teaCmd.Bool("watched") { } else if teaCmd.Bool("watched") {
var err error // GetMyWatchedRepos doesn't expose server-side pagination,
rps, _, err = client.GetMyWatchedRepos() // TODO: this does not expose pagination.. // so we implement client-side pagination as a workaround
allRepos, _, err := client.GetMyWatchedRepos()
if err != nil { if err != nil {
return err return err
} }
rps = paginateRepos(allRepos, flags.GetListOptions())
} else { } else {
var err error var err error
rps, _, err = client.ListMyRepos(gitea.ListReposOptions{ rps, _, err = client.ListMyRepos(gitea.ListReposOptions{
@@ -123,3 +125,34 @@ func filterReposByType(repos []*gitea.Repository, t gitea.RepoType) []*gitea.Rep
} }
return filtered 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]
}

View File

@@ -170,6 +170,13 @@ func AddLogin(login *Login) error {
return err 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 // save login to global var
config.Logins = append(config.Logins, *login) config.Logins = append(config.Logins, *login)