Files

55 lines
1.2 KiB
Go
Raw Permalink Normal View History

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package cmd
import (
2025-06-10 14:35:12 +02:00
"context"
"fmt"
"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/setting"
2025-06-10 14:35:12 +02:00
"github.com/urfave/cli/v3"
)
func newActionsCommand() *cli.Command {
return &cli.Command{
2023-12-15 23:49:01 +08:00
Name: "actions",
Usage: "Manage Gitea Actions",
2025-06-10 14:35:12 +02:00
Commands: []*cli.Command{
newActionsGenerateRunnerTokenCommand(),
},
}
}
func newActionsGenerateRunnerTokenCommand() *cli.Command {
return &cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
Action: runGenerateActionsRunnerToken,
Aliases: []string{"grt"},
Flags: []cli.Flag{
2023-07-21 17:28:19 +08:00
&cli.StringFlag{
Name: "scope",
Aliases: []string{"s"},
Value: "",
Usage: "{owner}[/{repo}] - leave empty for a global runner",
},
},
}
}
2025-06-10 14:35:12 +02:00
func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
2023-06-21 13:50:26 +08:00
setting.MustInstalled()
scope := c.String("scope")
respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
if extra.HasError() {
return handleCliResponseExtra(extra)
}
_, _ = fmt.Printf("%s\n", respText.Text)
return nil
}