mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 07:26:33 -04:00
Add a 'tea collaborators' command for managing repository collaborators,
mirroring the conventions of the recently-added 'tea deploy-keys' command:
- list: List all collaborators of a repository
- create: Add a collaborator with specified permission (read/write/admin)
- delete: Remove a collaborator from a repository
- permission: Check a collaborator's current permission level
Running 'tea collaborators <username>' without a subcommand is a shortcut
for 'tea collaborators permission <username>'.
Subcommand naming follows the codebase's create/delete convention; aliases
('add' for create, 'rm'/'remove' for delete) preserve the existing muscle
memory.
The deploy-keys functionality previously bundled here is intentionally
omitted: it is covered by the already-open upstream PR #1067 and would
conflict.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package collaborators
|
|
|
|
import (
|
|
stdctx "context"
|
|
|
|
gitea "gitea.dev/sdk"
|
|
|
|
"gitea.dev/tea/cmd/flags"
|
|
"gitea.dev/tea/modules/context"
|
|
"gitea.dev/tea/modules/print"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdCollaboratorsList represents a sub command of collaborators to list collaborators
|
|
var CmdCollaboratorsList = cli.Command{
|
|
Name: "list",
|
|
Aliases: []string{"ls"},
|
|
Usage: "List collaborators",
|
|
Description: "List collaborators of a repository",
|
|
Action: RunCollaboratorsList,
|
|
Flags: append([]cli.Flag{
|
|
&flags.PaginationPageFlag,
|
|
&flags.PaginationLimitFlag,
|
|
}, flags.AllDefaultFlags...),
|
|
}
|
|
|
|
// RunCollaboratorsList lists collaborators
|
|
func RunCollaboratorsList(ctx stdctx.Context, cmd *cli.Command) error {
|
|
c, err := context.InitCommand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := c.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
|
return err
|
|
}
|
|
client := c.Login.Client()
|
|
|
|
collaborators, _, err := client.ListCollaborators(ctx, c.Owner, c.Repo, gitea.ListCollaboratorsOptions{
|
|
ListOptions: flags.GetListOptions(cmd),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
print.CollaboratorsList(collaborators, c.Output)
|
|
return nil
|
|
}
|