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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/v2"
  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",
  28. Aliases: []string{"s"},
  29. Value: "",
  30. Usage: "{owner}[/{repo}] - leave empty for a global runner",
  31. },
  32. },
  33. }
  34. )
  35. func runGenerateActionsRunnerToken(c *cli.Context) error {
  36. ctx, cancel := installSignals()
  37. defer cancel()
  38. setting.MustInstalled()
  39. scope := c.String("scope")
  40. respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
  41. if extra.HasError() {
  42. return handleCliResponseExtra(extra)
  43. }
  44. _, _ = fmt.Printf("%s\n", respText)
  45. return nil
  46. }