MCPcopy Create free account
hub / github.com/alibaba/open-code-review / loadCommonContext

Function loadCommonContext

cmd/opencodereview/shared.go:72–102  ·  view source on GitHub ↗

loadCommonContext validates the working directory, loads the embedded template, raises MaxToolRequestTimes when maxTools exceeds the default, resolves the absolute repo path, loads system review rules, and creates the global git subprocess limiter. Both review and scan callers go through this so the

(repoDirInput, rulePath string, maxTools, maxGitProcs int, requireGit bool)

Source from the content-addressed store, hash-verified

70// path: diff concept requires git). requireGit=false allows non-git
71// directories (scan path: provider falls back to filepath.Walk).
72func loadCommonContext(repoDirInput, rulePath string, maxTools, maxGitProcs int, requireGit bool) (*commonContext, error) {
73 tpl, err := template.LoadDefault()
74 if err != nil {
75 return nil, fmt.Errorf("load default template: %w", err)
76 }
77 if maxTools > tpl.MaxToolRequestTimes {
78 tpl.MaxToolRequestTimes = maxTools
79 }
80 if err := tpl.Validate(); err != nil {
81 return nil, fmt.Errorf("invalid config: %w", err)
82 }
83
84 repoDir, isGit, err := resolveWorkingDir(repoDirInput, requireGit)
85 if err != nil {
86 return nil, err
87 }
88
89 resolver, fileFilter, err := rules.NewResolver(repoDir, rulePath)
90 if err != nil {
91 return nil, fmt.Errorf("load rules: %w", err)
92 }
93
94 return &commonContext{
95 Template: tpl,
96 RepoDir: repoDir,
97 Resolver: resolver,
98 FileFilter: fileFilter,
99 GitRunner: gitcmd.New(maxGitProcs),
100 IsGitRepo: isGit,
101 }, nil
102}
103
104// resolveWorkingDir returns (absPath, isGitRepo, err). When requireGit is
105// true, returns an error if the directory is not a git repo. When false,

Callers 9

loadDelegateContextFunction · 0.85
TestRunScanPreviewFunction · 0.85
TestRunPreviewFunction · 0.85
TestRunPreviewJSONFormatFunction · 0.85
executeReviewFunction · 0.85
executeScanFunction · 0.85

Calls 5

LoadDefaultFunction · 0.92
NewResolverFunction · 0.92
NewFunction · 0.92
resolveWorkingDirFunction · 0.85
ValidateMethod · 0.45

Tested by 6

TestRunScanPreviewFunction · 0.68
TestRunPreviewFunction · 0.68
TestRunPreviewJSONFormatFunction · 0.68