gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "context"
  6. "fmt"
  7. "code.gitea.io/gitea/modules/private"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/urfave/cli/v3"
  10. )
  11. var (
  12. // CmdActions represents the available actions sub-commands.
  13. CmdActions = &cli.Command{
  14. Name: "actions",
  15. Usage: "Manage Gitea Actions",
  16. Commands: []*cli.Command{
  17. subcmdActionsGenRunnerToken,
  18. },
  19. }
  20. subcmdActionsGenRunnerToken = &cli.Command{
  21. Name: "generate-runner-token",
  22. Usage: "Generate a new token for a runner to use to register with the server",
  23. Action: runGenerateActionsRunnerToken,
  24. Aliases: []string{"grt"},
  25. Flags: []cli.Flag{
  26. &cli.StringFlag{
  27. Name: "scope",
  28. Aliases: []string{"s"},
  29. Value: "",
  30. Usage: "{owner}[/{repo}] - leave empty for a global runner",
  31. },
  32. },
  33. }
  34. )
  35. func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
  36. setting.MustInstalled()
  37. scope := c.String("scope")
  38. respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
  39. if extra.HasError() {
  40. return handleCliResponseExtra(extra)
  41. }
  42. _, _ = fmt.Printf("%s\n", respText.Text)
  43. return nil
  44. }