AddResolvedWorkflows adds workflows using pre-resolved workflow data. This allows callers to resolve workflows early (e.g., to show descriptions) and then add them later. The opts.Quiet parameter suppresses detailed output (useful for interactive mode where output is already shown).
(ctx context.Context, workflowStrings []string, resolved *ResolvedWorkflows, opts AddOptions)
| 220 | // This allows callers to resolve workflows early (e.g., to show descriptions) and then add them later. |
| 221 | // The opts.Quiet parameter suppresses detailed output (useful for interactive mode where output is already shown). |
| 222 | func AddResolvedWorkflows(ctx context.Context, workflowStrings []string, resolved *ResolvedWorkflows, opts AddOptions) (*AddWorkflowsResult, error) { |
| 223 | addLog.Printf("Adding workflows: count=%d, engineOverride=%s, createPR=%v, noGitattributes=%v, opts.WorkflowDir=%s, noStopAfter=%v, stopAfter=%s", len(workflowStrings), opts.EngineOverride, opts.CreatePR, opts.NoGitattributes, opts.WorkflowDir, opts.NoStopAfter, opts.StopAfter) |
| 224 | |
| 225 | result := &AddWorkflowsResult{} |
| 226 | |
| 227 | for _, warning := range resolved.Warnings { |
| 228 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(warning)) |
| 229 | } |
| 230 | |
| 231 | // If creating a PR, check prerequisites |
| 232 | if opts.CreatePR { |
| 233 | // Check if GitHub CLI is available |
| 234 | if !isGHCLIAvailable() { |
| 235 | return nil, errors.New("GitHub CLI (gh) is required for PR creation but not available") |
| 236 | } |
| 237 | |
| 238 | // Check if we're in a git repository |
| 239 | if !isGitRepo() { |
| 240 | return nil, errors.New("not in a git repository - PR creation requires a git repository") |
| 241 | } |
| 242 | |
| 243 | // Check no other changes are present |
| 244 | if err := checkCleanWorkingDirectory(opts.Verbose); err != nil { |
| 245 | return nil, fmt.Errorf("working directory is not clean: %w", err) |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // Set workflow_dispatch result |
| 250 | result.HasWorkflowDispatch = resolved.HasWorkflowDispatch |
| 251 | |
| 252 | // Set FromWildcard flag based on resolved workflows |
| 253 | opts.FromWildcard = resolved.HasWildcard |
| 254 | |
| 255 | // Handle PR creation workflow |
| 256 | if opts.CreatePR { |
| 257 | addLog.Print("Creating workflow with PR") |
| 258 | prNumber, prURL, err := addWorkflowsWithPR(ctx, resolved.Workflows, opts) |
| 259 | if err != nil { |
| 260 | return nil, err |
| 261 | } |
| 262 | result.PRNumber = prNumber |
| 263 | result.PRURL = prURL |
| 264 | return result, nil |
| 265 | } |
| 266 | |
| 267 | // Handle normal workflow addition - pass resolved workflows with content |
| 268 | addLog.Print("Adding workflows normally without PR") |
| 269 | return result, addWorkflows(ctx, resolved.Workflows, opts) |
| 270 | } |
| 271 | |
| 272 | // addWorkflows handles workflow addition using pre-fetched content |
| 273 | func addWorkflows(ctx context.Context, workflows []*ResolvedWorkflow, opts AddOptions) error { |