(engine, repo string, nonInteractive bool)
| 42 | } |
| 43 | |
| 44 | func runTokensBootstrap(engine, repo string, nonInteractive bool) error { |
| 45 | tokensBootstrapLog.Printf("Running tokens bootstrap: engine=%s, repo=%s, nonInteractive=%v", engine, repo, nonInteractive) |
| 46 | var repoSlug string |
| 47 | var err error |
| 48 | |
| 49 | // Determine target repository |
| 50 | if repo != "" { |
| 51 | repoSlug = repo |
| 52 | } else { |
| 53 | repoSlug, err = GetCurrentRepoSlug() |
| 54 | if err != nil { |
| 55 | return fmt.Errorf("failed to detect current repository: %w", err) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Analyzing workflows in %s...", repoSlug))) |
| 60 | |
| 61 | // Discover workflows in the repository |
| 62 | requirements, err := getSecretRequirements(engine) |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("failed to analyze workflows: %w", err) |
| 65 | } |
| 66 | |
| 67 | tokensBootstrapLog.Printf("Collected %d required secrets from workflows", len(requirements)) |
| 68 | |
| 69 | // Check existing secrets in repository |
| 70 | existingSecrets, err := getExistingSecretsInRepo(repoSlug) |
| 71 | if err != nil { |
| 72 | // If we can't check existing secrets (e.g., no gh auth), continue with empty map |
| 73 | tokensBootstrapLog.Printf("Could not check existing secrets: %v", err) |
| 74 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Unable to check existing repository secrets. Will assume all secrets need to be configured.")) |
| 75 | existingSecrets = make(map[string]struct { |
| 76 | }) |
| 77 | } |
| 78 | |
| 79 | // Filter to only required secrets that are missing |
| 80 | missing := getMissingRequiredSecrets(requirements, existingSecrets) |
| 81 | |
| 82 | // Always display summary table of all required secrets with their status |
| 83 | displaySecretsSummaryTable(requirements, existingSecrets) |
| 84 | |
| 85 | if len(missing) == 0 { |
| 86 | tokensBootstrapLog.Print("All required secrets present") |
| 87 | fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("All required secrets are configured.")) |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | tokensBootstrapLog.Printf("Found %d missing required secrets", len(missing)) |
| 92 | |
| 93 | // In non-interactive mode, just display what's missing |
| 94 | if nonInteractive { |
| 95 | displayMissingSecrets(missing, repoSlug, existingSecrets) |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | // Interactive mode: prompt for missing secrets |
| 100 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Found %d missing required secret(s). You will be prompted to provide them.", len(missing)))) |
| 101 | fmt.Fprintln(os.Stderr, "") |
no test coverage detected