gitea.tea/cmd/collaborators/delete.go
Ross Golder d1e0849df7
feat(collaborators): add repository collaborator management commands
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.
2026-09-05 09:52:43 +07:00

66 lines
1.6 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package collaborators
import (
stdctx "context"
"errors"
"fmt"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"github.com/urfave/cli/v3"
)
// CmdCollaboratorsDelete represents a sub command of collaborators to delete a collaborator
var CmdCollaboratorsDelete = cli.Command{
Name: "delete",
Aliases: []string{"rm", "remove"},
Usage: "Delete a collaborator",
Description: "Remove a collaborator from a repository",
ArgsUsage: "<username>",
Action: runCollaboratorsDelete,
Flags: append([]cli.Flag{
&cli.BoolFlag{
Name: "confirm",
Aliases: []string{"y"},
Usage: "confirm deletion without prompting",
},
}, flags.AllDefaultFlags...),
}
func runCollaboratorsDelete(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()
if !cmd.Bool("confirm") {
fmt.Printf("Are you sure you want to remove %s as collaborator? [y/N] ", username)
var response string
fmt.Scanln(&response)
if response != "y" && response != "Y" && response != "yes" {
fmt.Println("Deletion canceled.")
return nil
}
}
if _, err = client.DeleteCollaborator(ctx, c.Owner, c.Repo, username); err != nil {
return err
}
fmt.Printf("Collaborator %s removed successfully\n", username)
return nil
}