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"
|
|
"errors"
|
|
|
|
"gitea.dev/tea/cmd/flags"
|
|
"gitea.dev/tea/modules/context"
|
|
"gitea.dev/tea/modules/print"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdCollaboratorsPermission represents a sub command of collaborators to check permission
|
|
var CmdCollaboratorsPermission = cli.Command{
|
|
Name: "permission",
|
|
Aliases: []string{"perm"},
|
|
Usage: "Check collaborator permission",
|
|
Description: "Check the permission level of a collaborator on a repository",
|
|
ArgsUsage: "<username>",
|
|
Action: runCollaboratorsPermission,
|
|
Flags: flags.AllDefaultFlags,
|
|
}
|
|
|
|
func runCollaboratorsPermission(ctx stdctx.Context, cmd *cli.Command) error {
|
|
if cmd.Args().Len() == 0 {
|
|
return errors.New("username is required")
|
|
}
|
|
|
|
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()
|
|
|
|
username := cmd.Args().First()
|
|
|
|
permission, _, err := client.CollaboratorPermission(ctx, c.Owner, c.Repo, username)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
print.CollaboratorPermission(username, permission)
|
|
return nil
|
|
}
|