You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "fmt"
  6. "code.gitea.io/gitea/modules/private"
  7. "code.gitea.io/gitea/modules/setting"
  8. "github.com/urfave/cli"
  9. )
  10. var (
  11. // CmdActions represents the available actions sub-commands.
  12. CmdActions = cli.Command{
  13. Name: "actions",
  14. Usage: "",
  15. Description: "Commands for managing Gitea Actions",
  16. Subcommands: []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, s",
  28. Value: "",
  29. Usage: "{owner}[/{repo}] - leave empty for a global runner",
  30. },
  31. },
  32. }
  33. )
  34. func runGenerateActionsRunnerToken(c *cli.Context) error {
  35. ctx, cancel := installSignals()
  36. defer cancel()
  37. setting.MustInstalled()
  38. scope := c.String("scope")
  39. respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
  40. if extra.HasError() {
  41. return handleCliResponseExtra(extra)
  42. }
  43. _, _ = fmt.Printf("%s\n", respText)
  44. return nil
  45. }