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

Function uploadSecretToRepo

pkg/cli/engine_secrets.go:460–484  ·  view source on GitHub ↗

uploadSecretToRepo uploads a secret to the repository if it doesn't already exist

(secretName, secretValue, repoSlug string, verbose bool)

Source from the content-addressed store, hash-verified

458
459// uploadSecretToRepo uploads a secret to the repository if it doesn't already exist
460func uploadSecretToRepo(secretName, secretValue, repoSlug string, verbose bool) error {
461 engineSecretsLog.Printf("Uploading secret %s to %s", secretName, repoSlug)
462
463 // Check if secret already exists
464 output, err := workflow.RunGHCombined("Checking secrets...", "secret", "list", "--repo", repoSlug)
465 if err == nil && stringContainsSecretName(string(output), secretName) {
466 if verbose {
467 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Secret %s already exists, skipping upload", secretName)))
468 }
469 return nil
470 }
471
472 // Upload the secret
473 if verbose {
474 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Uploading %s secret to repository", secretName)))
475 }
476
477 output, err = workflow.RunGHCombined("Setting secret...", "secret", "set", secretName, "--repo", repoSlug, "--body", secretValue)
478 if err != nil {
479 return fmt.Errorf("failed to set %s secret: %w (output: %s)", secretName, err, string(output))
480 }
481
482 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Uploaded %s secret to repository", secretName)))
483 return nil
484}
485
486// stringContainsSecretName checks if the gh secret list output contains a secret name
487func stringContainsSecretName(output, secretName string) bool {

Callers 4

ensureSecretAvailableFunction · 0.85

Calls 6

RunGHCombinedFunction · 0.92
FormatInfoMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
stringContainsSecretNameFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected