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

Function scanUpgradeRepo

pkg/cli/upgrade_org.go:67–112  ·  view source on GitHub ↗

scanUpgradeRepo shallow-clones repo, counts agentic workflow files, and extracts the current compiler version from the first lock file it finds. It returns (preview, true, nil) when the repo has workflows, or (orgRepoPreview{}, false, nil) when none are found.

(ctx context.Context, repo string, verbose bool)

Source from the content-addressed store, hash-verified

65// It returns (preview, true, nil) when the repo has workflows, or
66// (orgRepoPreview{}, false, nil) when none are found.
67func scanUpgradeRepo(ctx context.Context, repo string, verbose bool) (orgRepoPreview, bool, error) {
68 gitRoot, err := gitutil.FindGitRoot()
69 if err != nil {
70 return orgRepoPreview{}, false, fmt.Errorf("--org requires running inside a git repository: %w", err)
71 }
72
73 updatesDir, err := ensureUpdateTargetRepoGitignore(gitRoot)
74 if err != nil {
75 return orgRepoPreview{}, false, err
76 }
77
78 checkoutDir := filepath.Join(updatesDir, sanitizeRepoPath(repo))
79 if err := shallowCloneTargetRepo(ctx, repo, checkoutDir); err != nil {
80 return orgRepoPreview{}, false, err
81 }
82
83 workflowsDir := filepath.Join(checkoutDir, constants.GetWorkflowDir())
84
85 // Count .md workflow files (excluding lock files).
86 mdCount, err := countWorkflowMDFiles(workflowsDir)
87 if err != nil && !os.IsNotExist(err) {
88 return orgRepoPreview{}, false, fmt.Errorf("failed to scan workflows in %s: %w", repo, err)
89 }
90
91 if mdCount == 0 {
92 upgradeOrgLog.Printf("Skipping %s: no agentic workflow files found", repo)
93 if verbose {
94 fmt.Fprintln(os.Stderr, console.FormatVerboseMessage("Skipping "+repo+": no agentic workflow files found"))
95 }
96 return orgRepoPreview{}, false, nil
97 }
98
99 // Extract compiler version from lock file metadata.
100 currentVersion := extractCompilerVersionFromWorkflowsDir(workflowsDir)
101 upgradeOrgLog.Printf("Scanned %s: workflows=%d, currentVersion=%s", repo, mdCount, currentVersion)
102
103 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(
104 fmt.Sprintf("%s: %d workflow(s)%s", repo, mdCount, formatCurrentVersionSuffix(currentVersion)),
105 ))
106
107 return orgRepoPreview{
108 Repo: repo,
109 TotalWorkflows: mdCount,
110 CurrentVersion: currentVersion,
111 }, true, nil
112}
113
114// renderOrgUpgradeReport prints the discovered repositories with their workflow
115// counts and current compiler versions.

Callers

nothing calls this directly

Calls 12

FindGitRootFunction · 0.92
GetWorkflowDirFunction · 0.92
FormatVerboseMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
sanitizeRepoPathFunction · 0.85
shallowCloneTargetRepoFunction · 0.85
countWorkflowMDFilesFunction · 0.85
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected