gitea.tea/cmd/deploytokens/list.go
Ross Golder 803aeab5db
feat: Add 'tea deploy-tokens' command for repository deploy token management
- Add deploy-tokens subcommand with list, create, delete
- Create deploy token print helpers with token display (shown once only)
- Add unit tests for all commands
- Update SDK dependency to use fork with deploy token support

Relates to gitea/go-sdk#846
2026-09-08 11:05:40 +07:00

58 lines
1.2 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package deploytokens
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"
)
var CmdDeployTokensList = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List deploy tokens",
Description: "List deploy tokens of a repository",
Action: RunDeployTokensList,
Flags: append([]cli.Flag{
&flags.PaginationPageFlag,
&flags.PaginationLimitFlag,
}, flags.AllDefaultFlags...),
}
func RunDeployTokensList(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()
opts := gitea.ListDeployKeysOptions{
ListOptions: flags.GetListOptions(cmd),
}
keys, _, err := client.ListDeployKeys(ctx, c.Owner, c.Repo, opts)
if err != nil {
return err
}
var tokens []*gitea.DeployKey
for _, key := range keys {
if key.KeyType == "token" {
tokens = append(tokens, key)
}
}
print.DeployTokensList(tokens, c.Output)
return nil
}