MCPcopy Create free account
hub / github.com/github/gh-aw / newSecretsSetSubcommand

Function newSecretsSetSubcommand

pkg/cli/secret_set_command.go:39–123  ·  view source on GitHub ↗

NaCl box public key size

()

Source from the content-addressed store, hash-verified

37const publicKeySize = 32 // NaCl box public key size
38
39func newSecretsSetSubcommand() *cobra.Command {
40 var (
41 flagValue string
42 flagValueEnv string
43 flagAPIBase string
44 )
45
46 cmd := &cobra.Command{
47 Use: "set <secret-name>",
48 Short: "Create or update a repository secret",
49 Long: `Create or update a GitHub Actions secret for a repository.
50
51The secret value can be provided in three ways:
52 1. Via the --value flag
53 2. Via the --value-from-env flag (reads from environment variable)
54 3. From stdin (if neither flag is provided)`,
55 Example: ` # From stdin (uses current repository)
56 gh aw secrets set MY_SECRET
57
58 # Specify target repository
59 gh aw secrets set MY_SECRET --repo myorg/myrepo
60
61 # From flag
62 gh aw secrets set MY_SECRET --value "secret123" --repo myorg/myrepo
63
64 # From environment variable
65 export MY_TOKEN="secret123"
66 gh aw secrets set MY_SECRET --value-from-env MY_TOKEN --repo myorg/myrepo`,
67 Args: cobra.ExactArgs(1),
68 RunE: func(cmd *cobra.Command, args []string) error {
69 secretName := args[0]
70 secretSetLog.Printf("Setting repository secret: name=%s", secretName)
71
72 // Determine target repository: explicit --repo or current repo by default
73 flagRepo, _ := cmd.Flags().GetString("repo")
74 var repoSlug string
75 if flagRepo != "" {
76 repoSlug = flagRepo
77 secretSetLog.Printf("Using explicit repository: %s", repoSlug)
78 } else {
79 var err error
80 repoSlug, err = GetCurrentRepoSlug()
81 if err != nil {
82 secretSetLog.Printf("Failed to detect current repository: %v", err)
83 return fmt.Errorf("failed to detect current repository: %w", err)
84 }
85 secretSetLog.Printf("Using current repository: %s", repoSlug)
86 }
87
88 owner, repo, splitErr := repoutil.SplitRepoSlug(repoSlug)
89 if splitErr != nil {
90 return fmt.Errorf("invalid repository slug %q: %w", repoSlug, splitErr)
91 }
92
93 // Create GitHub REST client using go-gh
94 client, err := api.NewRESTClient(secretSetClientOptions(flagAPIBase))
95 if err != nil {
96 return fmt.Errorf("cannot create GitHub client: %w", err)

Callers 1

NewSecretsCommandFunction · 0.85

Calls 11

SplitRepoSlugFunction · 0.92
FormatSuccessMessageFunction · 0.92
GetCurrentRepoSlugFunction · 0.85
secretSetClientOptionsFunction · 0.85
resolveSecretValueForSetFunction · 0.85
setRepoSecretFunction · 0.85
addRepoFlagFunction · 0.85
PrintMethod · 0.80
GetStringMethod · 0.65
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected