mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
feat!: rebuild tea on Cobra with explicit noun/verb commands (#1126)
- **switch tea to the Cobra command tree:** `internal/app` wires the packages from parts 1–4 into explicit noun/verb commands with `--repo`, `--json` / `--jq`, `--sudo` and `--debug`; `main.go` points at it. Build, release and docs tooling (`tools/cli-docs`, Makefile, goreleaser, snap, CI) and README / CONTRIBUTING are updated. - **remove the urfave/cli command tree:** deletes `cmd/`, `modules/`, the old integration tests, contrib completion scripts and the generated `docs/CLI.md`, and drops their dependencies. This commit only deletes. ## Breaking changes This is a breaking release. It requires Gitea 28 or newer; configuration moves to separate `config.yml` and `hosts.yml` files and requires fresh authentication, and command names, aliases, flags and output formats change. `docs/migration-1.0.md` maps every old command, flag and environment variable to its replacement. ## Issues fixes #1118 fixes #1116 fixes #1115 fixes #1094 fixes #1091 fixes #1073 fixes #1052 fixes #1032 fixes #1023 fixes #966 fixes #908 fixes #833 fixes #831 fixes #817 fixes #804 fixes #779 fixes #770 fixes #737 fixes #697 fixes #726 fixes #677 fixes #672 fixes #633 fixes #632 fixes #560 fixes #556 fixes #523 fixes #516 fixes #510 fixes #504 fixes #500 fixes #482 fixes #406 fixes #403 fixes #373 fixes #351 fixes #344 fixes #326 fixes #325 fixes #323 fixes #246 fixes #240 fixes #232 fixes #197 fixes #172 fixes #141 fixes #69 fixes #1110 fixes #569 fixes #480 fixes #666 fixes #670 fixes #457 fixes #643 fixes #498 fixes #490 fixes #1069 fixes #834 fixes #602 fixes #328 fixes #417 fixes #571 fixes #1029 fixes #489 fixes #1050 fixes #162 fixes #430 fixes #1087 fixes #683 Reviewed-on: https://gitea.com/gitea/tea/pulls/1126 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
This commit is contained in:
1 parent
12e415a7a7
commit
f02245449b
456 files changed
+18892
-34015
No files matched your search
@@ -1,187 +0,0 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package repos
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitea.dev/sdk"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
"gitea.dev/tea/modules/context"
|
||||
"gitea.dev/tea/modules/print"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var repoFieldsFlag = flags.FieldsFlag(print.RepoFields, []string{
|
||||
"owner", "name", "type", "ssh",
|
||||
})
|
||||
|
||||
// CmdReposListFlags contains all flags needed for repo listing
|
||||
var CmdReposListFlags = append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "watched",
|
||||
Aliases: []string{"w"},
|
||||
Required: false,
|
||||
Usage: "List your watched repos instead",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "starred",
|
||||
Aliases: []string{"s"},
|
||||
Required: false,
|
||||
Usage: "List your starred repos instead",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "owner",
|
||||
Aliases: []string{"O"},
|
||||
Required: false,
|
||||
Usage: "List repos of a specific owner (org or user)",
|
||||
},
|
||||
repoFieldsFlag,
|
||||
&typeFilterFlag,
|
||||
&flags.PaginationPageFlag,
|
||||
&flags.PaginationLimitFlag,
|
||||
}, flags.LoginOutputFlags...)
|
||||
|
||||
// CmdReposList represents a sub command of repos to list them
|
||||
var CmdReposList = cli.Command{
|
||||
Name: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Usage: "List repositories you have access to",
|
||||
Description: "List repositories you have access to",
|
||||
Action: RunReposList,
|
||||
Flags: CmdReposListFlags,
|
||||
}
|
||||
|
||||
// RunReposList list repositories
|
||||
func RunReposList(requestCtx stdctx.Context, cmd *cli.Command) error {
|
||||
teaCmd, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client := teaCmd.Login.Client()
|
||||
|
||||
typeFilter, err := getTypeFilter(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var rps []*gitea.Repository
|
||||
if owner := teaCmd.String("owner"); owner != "" {
|
||||
var err error
|
||||
_, resp, orgErr := client.Organizations.GetOrg(requestCtx, owner)
|
||||
if orgErr != nil {
|
||||
if resp == nil || resp.StatusCode != http.StatusNotFound {
|
||||
return fmt.Errorf("could not find owner: %w", orgErr)
|
||||
}
|
||||
// not an org, treat as user
|
||||
rps, _, err = client.Repositories.ListUserRepos(requestCtx, owner, gitea.ListReposOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
})
|
||||
} else {
|
||||
rps, _, err = client.Repositories.ListOrgRepos(requestCtx, owner, gitea.ListOrgReposOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if teaCmd.Bool("starred") {
|
||||
user, _, err := client.Users.GetMyUserInfo(requestCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rps, _, err = client.Repositories.SearchRepos(requestCtx, gitea.SearchRepoOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
StarredByUserID: user.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if teaCmd.Bool("watched") {
|
||||
// GetMyWatchedRepos doesn't expose server-side pagination,
|
||||
// so we implement client-side pagination as a workaround
|
||||
allRepos, _, err := client.Repositories.GetMyWatchedRepos(requestCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rps = paginateRepos(allRepos, flags.GetListOptions(cmd))
|
||||
} else {
|
||||
var err error
|
||||
rps, _, err = client.Repositories.ListMyRepos(requestCtx, gitea.ListReposOptions{
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
reposFiltered := rps
|
||||
if typeFilter != gitea.RepoTypeNone {
|
||||
reposFiltered = filterReposByType(rps, typeFilter)
|
||||
}
|
||||
|
||||
fields, err := repoFieldsFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return print.ReposList(reposFiltered, teaCmd.Output, fields)
|
||||
}
|
||||
|
||||
func filterReposByType(repos []*gitea.Repository, t gitea.RepoType) []*gitea.Repository {
|
||||
var filtered []*gitea.Repository
|
||||
for _, r := range repos {
|
||||
switch t {
|
||||
case gitea.RepoTypeFork:
|
||||
if !r.Fork {
|
||||
continue
|
||||
}
|
||||
case gitea.RepoTypeMirror:
|
||||
if !r.Mirror {
|
||||
continue
|
||||
}
|
||||
case gitea.RepoTypeSource:
|
||||
if r.Fork || r.Mirror {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
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]
|
||||
}
|
||||
Reference in new issue
Block a user