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

Function executeScan

cmd/opencodereview/scan_cmd.go:111–247  ·  view source on GitHub ↗
(opts scanOptions)

Source from the content-addressed store, hash-verified

109}
110
111func executeScan(opts scanOptions) (retErr error) {
112 out, closeOut, err := resolveOutputWriter(opts.outputPath, opts.outputFormat)
113 if err != nil {
114 return err
115 }
116 defer func() {
117 if cerr := closeOut(); cerr != nil {
118 retErr = errors.Join(retErr, fmt.Errorf("close output file: %w", cerr))
119 }
120 }()
121
122 cc, err := loadCommonContext(opts.repoDir, opts.rulePath, "", opts.maxTools, opts.maxGitProcs, false)
123 if err != nil {
124 return err
125 }
126 applyCLIExcludes(cc, splitPaths(opts.excludes))
127
128 // scan owns its own template (scan_template.json) independent from the
129 // diff-review template loaded by loadCommonContext above. Apply --max-tools
130 // as an "only raise" override to the scan template's per-file budget.
131 scanTpl, err := template.LoadScanDefault()
132 if err != nil {
133 return fmt.Errorf("load scan template: %w", err)
134 }
135 if err := scanTpl.Validate(); err != nil {
136 return fmt.Errorf("invalid scan template: %w", err)
137 }
138 if opts.maxTools > scanTpl.MaxToolRequestTimes {
139 scanTpl.MaxToolRequestTimes = opts.maxTools
140 }
141 if opts.batch != "" {
142 // CLI override of BATCH_STRATEGY; validated downstream by parseBatchStrategy
143 // (unknown values silently fall back to "none").
144 scanTpl.BatchStrategy = opts.batch
145 }
146 // Token budget: --max-tokens-budget overrides the template value when set.
147 budget := scanTpl.MaxTokensBudget
148 if opts.maxTokensBudget > 0 {
149 budget = int64(opts.maxTokensBudget)
150 }
151
152 scanPaths := splitPaths(opts.paths)
153
154 if opts.preview {
155 return runScanPreview(cc, scanTpl, scanPaths, opts.outputFormat, out)
156 }
157
158 resumeState, err := loadScanResumeState(cc.RepoDir, opts, scanPaths)
159 if err != nil {
160 return err
161 }
162
163 rt, err := loadLLMRuntime(cc.Template, opts.toolConfigPath, llm.ResolveOptions{
164 Provider: opts.provider,
165 Model: opts.model,
166 })
167 if err != nil {
168 return err

Callers 1

scan_cmd.goFile · 0.85

Calls 15

RunMethod · 0.95
SessionIDMethod · 0.95
LoadScanDefaultFunction · 0.92
NewAgentFunction · 0.92
NewCommentWorkerPoolFunction · 0.92
StartSpanFunction · 0.92
IsEnabledFunction · 0.92
TraceIDFromContextFunction · 0.92
resolveOutputWriterFunction · 0.85
loadCommonContextFunction · 0.85
applyCLIExcludesFunction · 0.85

Tested by

no test coverage detected