| 73 | } |
| 74 | |
| 75 | func runUpdateForOrg(ctx context.Context, org string, repoGlobs []string, opts UpdateWorkflowsOptions, createPR bool, createIssue bool, verbose bool) error { |
| 76 | clearUpdateResolutionCaches() |
| 77 | searchFn := func(ctx context.Context, org string, verbose bool) ([]string, error) { |
| 78 | return searchOrgWorkflowReposFn(ctx, org, opts.WorkflowNames, verbose) |
| 79 | } |
| 80 | |
| 81 | // scanFn previews a single repo and decides whether to include it. |
| 82 | // It also prints a per-repo workflow summary to stderr. |
| 83 | scanFn := func(ctx context.Context, repo string, v bool) (orgRepoPreview, bool, error) { |
| 84 | preview, err := previewOrgRepoUpdatesFn(ctx, repo, opts, v) |
| 85 | if err != nil { |
| 86 | return orgRepoPreview{}, false, err |
| 87 | } |
| 88 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage( |
| 89 | fmt.Sprintf("%s: %d workflow(s), %d with updates", repo, preview.TotalWorkflows, len(preview.Workflows)), |
| 90 | )) |
| 91 | if len(preview.Workflows) == 0 { |
| 92 | if v { |
| 93 | fmt.Fprintln(os.Stderr, console.FormatVerboseMessage("Skipping "+repo+": already up to date")) |
| 94 | } |
| 95 | return orgRepoPreview{}, false, nil |
| 96 | } |
| 97 | return preview, true, nil |
| 98 | } |
| 99 | |
| 100 | return runCommandForOrg(ctx, org, repoGlobs, orgRunCallbacks{ |
| 101 | AutoYes: opts.Yes, |
| 102 | SearchFn: searchFn, |
| 103 | ScanFn: scanFn, |
| 104 | ReportFn: renderOrgPreviewReport, |
| 105 | ApplyFn: func(ctx context.Context, preview orgRepoPreview, v bool) error { |
| 106 | return runUpdateForTargetRepoFn(ctx, preview.Repo, opts, true, v) |
| 107 | }, |
| 108 | IssueFn: func(ctx context.Context, preview orgRepoPreview, v bool) error { |
| 109 | return createIssueForOrgRepoFn(ctx, preview, v) |
| 110 | }, |
| 111 | DiscoveringMsg: "Discovering repositories in " + org + " with source-managed workflows...", |
| 112 | NoReposMsg: formatUpdateOrgNoReposMessage(opts.WorkflowNames), |
| 113 | ScanLabel: "Inspecting", |
| 114 | ApplyLabel: "Updating", |
| 115 | IssueLabel: "Creating issue in", |
| 116 | NoResultsMsg: "All matching repositories are already up to date", |
| 117 | NoResultsStopMsg: "No updates found before processing stopped", |
| 118 | AllFailApplyMsg: "failed to update any repository", |
| 119 | AllFailIssueMsg: "failed to create issues in any repository", |
| 120 | }, createPR, createIssue, verbose) |
| 121 | } |
| 122 | |
| 123 | func formatUpdateOrgNoReposMessage(workflowNames []string) string { |
| 124 | if len(workflowNames) == 0 { |