code.gitea.io/gitea@v1.21.7/cmd/actions.go (about)

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