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

Function previewOrgRepoUpdates

pkg/cli/update_org.go:168–234  ·  view source on GitHub ↗
(ctx context.Context, repo string, opts UpdateWorkflowsOptions, verbose bool)

Source from the content-addressed store, hash-verified

166}
167
168func previewOrgRepoUpdates(ctx context.Context, repo string, opts UpdateWorkflowsOptions, verbose bool) (orgRepoPreview, error) {
169 gitRoot, err := gitutil.FindGitRoot()
170 if err != nil {
171 return orgRepoPreview{}, fmt.Errorf("--org requires running inside a git repository: %w", err)
172 }
173
174 updatesDir, err := ensureUpdateTargetRepoGitignore(gitRoot)
175 if err != nil {
176 return orgRepoPreview{}, err
177 }
178
179 checkoutDir := filepath.Join(updatesDir, sanitizeRepoPath(repo))
180 if err := shallowCloneTargetRepo(ctx, repo, checkoutDir); err != nil {
181 return orgRepoPreview{}, err
182 }
183
184 workflowsDir := filepath.Join(checkoutDir, constants.GetWorkflowDir())
185 workflows, err := findWorkflowsWithSource(workflowsDir, opts.WorkflowNames, verbose)
186 if err != nil {
187 return orgRepoPreview{}, fmt.Errorf("failed to scan workflows in shallow checkout: %w", err)
188 }
189
190 preview := orgRepoPreview{
191 Repo: repo,
192 TotalWorkflows: len(workflows),
193 Workflows: make([]orgWorkflowPreview, 0, len(workflows)),
194 }
195 for _, wf := range workflows {
196 sourceSpec, err := parseSourceSpec(wf.SourceSpec)
197 if err != nil {
198 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Skipping %s/%s: failed to parse source: %v", repo, wf.Name, err)))
199 orgUpdateLog.Printf("Failed to parse source for %s/%s: %v", repo, wf.Name, err)
200 continue
201 }
202 name := normalizeWorkflowID(wf.Name)
203 resolved, err := resolveRedirectedUpdateLocation(ctx, name, sourceSpec, opts.AllowMajor, verbose, opts.NoRedirect, opts.CoolDown)
204 if err != nil {
205 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Skipping %s/%s: %v", repo, wf.Name, err)))
206 orgUpdateLog.Printf("Failed to resolve update location for %s/%s: %v", repo, wf.Name, err)
207 continue
208 }
209 if resolved.currentRef == resolved.latestRef && len(resolved.redirectHistory) == 0 && !opts.Force {
210 continue
211 }
212
213 editedAt, err := getLatestWorkflowEditTimeFromCheckout(ctx, checkoutDir, wf.Path)
214 if err == nil {
215 if preview.OldestEdit.IsZero() || editedAt.Before(preview.OldestEdit) {
216 preview.OldestEdit = editedAt
217 }
218 }
219 // Resolve SHAs to version-tag labels so the preview shows human-readable
220 // identifiers (e.g. v1.2.3) instead of bare short SHAs when possible.
221 currentLabel := resolveVersionLabel(ctx, resolved.sourceSpec.Repo, resolved.currentRef)
222 latestLabel := resolveVersionLabel(ctx, resolved.sourceSpec.Repo, resolved.latestRef)
223 preview.Workflows = append(preview.Workflows, orgWorkflowPreview{
224 Name: name,
225 Path: wf.Path,

Callers

nothing calls this directly

Calls 14

FindGitRootFunction · 0.92
GetWorkflowDirFunction · 0.92
FormatWarningMessageFunction · 0.92
sanitizeRepoPathFunction · 0.85
shallowCloneTargetRepoFunction · 0.85
findWorkflowsWithSourceFunction · 0.85
parseSourceSpecFunction · 0.85
normalizeWorkflowIDFunction · 0.85
resolveVersionLabelFunction · 0.85

Tested by

no test coverage detected