MCPcopy
hub / github.com/openai/codex-plugin-cc / resolveReviewTarget

Function resolveReviewTarget

plugins/codex/scripts/lib/git.mjs:134–190  ·  view source on GitHub ↗
(cwd, options = {})

Source from the content-addressed store, hash-verified

132}
133
134export function resolveReviewTarget(cwd, options = {}) {
135 ensureGitRepository(cwd);
136
137 const requestedScope = options.scope ?? "auto";
138 const baseRef = options.base ?? null;
139 const state = getWorkingTreeState(cwd);
140 const supportedScopes = new Set(["auto", "working-tree", "branch"]);
141
142 if (baseRef) {
143 return {
144 mode: "branch",
145 label: `branch diff against ${baseRef}`,
146 baseRef,
147 explicit: true
148 };
149 }
150
151 if (requestedScope === "working-tree") {
152 return {
153 mode: "working-tree",
154 label: "working tree diff",
155 explicit: true
156 };
157 }
158
159 if (!supportedScopes.has(requestedScope)) {
160 throw new Error(
161 `Unsupported review scope "${requestedScope}". Use one of: auto, working-tree, branch, or pass --base <ref>.`
162 );
163 }
164
165 if (requestedScope === "branch") {
166 const detectedBase = detectDefaultBranch(cwd);
167 return {
168 mode: "branch",
169 label: `branch diff against ${detectedBase}`,
170 baseRef: detectedBase,
171 explicit: true
172 };
173 }
174
175 if (state.isDirty) {
176 return {
177 mode: "working-tree",
178 label: "working tree diff",
179 explicit: false
180 };
181 }
182
183 const detectedBase = detectDefaultBranch(cwd);
184 return {
185 mode: "branch",
186 label: `branch diff against ${detectedBase}`,
187 baseRef: detectedBase,
188 explicit: false
189 };
190}
191

Callers 3

git.test.mjsFile · 0.90
executeReviewRunFunction · 0.90
handleReviewCommandFunction · 0.90

Calls 3

ensureGitRepositoryFunction · 0.85
getWorkingTreeStateFunction · 0.85
detectDefaultBranchFunction · 0.85

Tested by

no test coverage detected