@self-review/core 1.43.0 → 1.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -349,12 +349,22 @@ interface MaterializeResult {
|
|
|
349
349
|
*/
|
|
350
350
|
cleanup: () => void;
|
|
351
351
|
}
|
|
352
|
+
/** A local clone whose fetch remote matches the requested forge repository. */
|
|
353
|
+
interface ExistingClone {
|
|
354
|
+
repoPath: string;
|
|
355
|
+
remoteName: string;
|
|
356
|
+
}
|
|
352
357
|
/**
|
|
353
358
|
* Default runner: spawns real git. Resolves with the exit code on any
|
|
354
359
|
* completed run (including non-zero); rejects only when git cannot be
|
|
355
360
|
* spawned at all (e.g. ENOENT).
|
|
356
361
|
*/
|
|
357
362
|
declare const defaultGitRunner: ForgeCommandRunner;
|
|
363
|
+
/**
|
|
364
|
+
* Detect an existing clone: when `cwd` is inside a git repository with a
|
|
365
|
+
* remote matching the forge URL, return `{ repoPath, remoteName }`.
|
|
366
|
+
*/
|
|
367
|
+
declare function detectExistingClone(url: ForgeUrl, cwd: string, runner?: ForgeCommandRunner): Promise<ExistingClone | null>;
|
|
358
368
|
/**
|
|
359
369
|
* Materialize a forge PR/MR into a local git context.
|
|
360
370
|
*
|
|
@@ -363,17 +373,21 @@ declare const defaultGitRunner: ForgeCommandRunner;
|
|
|
363
373
|
* branch and PR/MR head refs are fetched into that clone under
|
|
364
374
|
* `refs/self-review/*` — read-only for the working tree. Otherwise a
|
|
365
375
|
* blobless clone is created in a unique directory under the OS temp root
|
|
366
|
-
* and `cleanup()` removes exactly that directory.
|
|
376
|
+
* and `cleanup()` removes exactly that directory. Callers that already
|
|
377
|
+
* detected a clone may pass it to avoid repeating the git probes.
|
|
367
378
|
*
|
|
368
379
|
* The returned `headSha` is the live remote head, so callers can compare it
|
|
369
380
|
* against a recorded `remote-head-sha` for drift detection.
|
|
370
381
|
*/
|
|
371
|
-
declare function materialize(url: ForgeUrl, baseBranch: string, cwd: string, runner?: ForgeCommandRunner): Promise<MaterializeResult>;
|
|
382
|
+
declare function materialize(url: ForgeUrl, baseBranch: string, cwd: string, runner?: ForgeCommandRunner, existingClone?: ExistingClone | null): Promise<MaterializeResult>;
|
|
372
383
|
/**
|
|
373
384
|
* Git-only fallback for the base branch when no forge CLI is available:
|
|
374
385
|
* resolves the remote's default branch from its HEAD symref via
|
|
375
|
-
* `git ls-remote --symref <
|
|
386
|
+
* `git ls-remote --symref <remote> HEAD`. When an existing matching clone
|
|
387
|
+
* is supplied, the configured remote is used so its SSH/HTTPS transport
|
|
388
|
+
* and credentials are preserved. Otherwise the forge HTTPS URL is used.
|
|
389
|
+
* No forge API involved.
|
|
376
390
|
*/
|
|
377
|
-
declare function resolveRemoteDefaultBranch(url: ForgeUrl, runner?: ForgeCommandRunner): Promise<string>;
|
|
391
|
+
declare function resolveRemoteDefaultBranch(url: ForgeUrl, runner?: ForgeCommandRunner, existing?: ExistingClone | null): Promise<string>;
|
|
378
392
|
|
|
379
|
-
export { type FetchThreadsOptions, type ForgeAnchorSide, ForgeCliUnavailableError, type ForgeCommandResult, type ForgeCommandRunner, type ForgeName, type ForgeProvider, type ForgeThread, type ForgeThreadAnchor, type ForgeThreadTurn, type ForgeUrl, GUIDE_XSD_SCHEMA, type GuideParseResult, IMPLICIT_GUIDE_GROUP_NAME, type MaterializeMode, type MaterializeResult, REVIEW_LEVEL_FILE_PATH, type RenderedTextMode, checkWritability, computePayloadStats, countTotalLines, createGitHubProvider, createGitLabProvider, createIgnoreFilter, defaultGitRunner, generateSyntheticDiffs, generateUntrackedDiffs, getGitDiffStats, getLanguageFromPath, getRenderedTextMode, getRepoRoot, getRepoRootAsync, getUntrackedFilesAsync, isHtmlFile, isMarkdownFile, isPreviewableImage, isPreviewableRenderedText, isPreviewableSvg, loadConfig, mapThreadsToReviewComments, materialize, parseDiff, parseForgeUrl, parseGuideXml, parseReviewXml, parseReviewXmlString, reconcileGuide, resolveRemoteDefaultBranch, runGitDiff, runGitDiffAsync, scanDirectory, scanFile, serializeReview, validateGitAvailable };
|
|
393
|
+
export { type ExistingClone, type FetchThreadsOptions, type ForgeAnchorSide, ForgeCliUnavailableError, type ForgeCommandResult, type ForgeCommandRunner, type ForgeName, type ForgeProvider, type ForgeThread, type ForgeThreadAnchor, type ForgeThreadTurn, type ForgeUrl, GUIDE_XSD_SCHEMA, type GuideParseResult, IMPLICIT_GUIDE_GROUP_NAME, type MaterializeMode, type MaterializeResult, REVIEW_LEVEL_FILE_PATH, type RenderedTextMode, checkWritability, computePayloadStats, countTotalLines, createGitHubProvider, createGitLabProvider, createIgnoreFilter, defaultGitRunner, detectExistingClone, generateSyntheticDiffs, generateUntrackedDiffs, getGitDiffStats, getLanguageFromPath, getRenderedTextMode, getRepoRoot, getRepoRootAsync, getUntrackedFilesAsync, isHtmlFile, isMarkdownFile, isPreviewableImage, isPreviewableRenderedText, isPreviewableSvg, loadConfig, mapThreadsToReviewComments, materialize, parseDiff, parseForgeUrl, parseGuideXml, parseReviewXml, parseReviewXmlString, reconcileGuide, resolveRemoteDefaultBranch, runGitDiff, runGitDiffAsync, scanDirectory, scanFile, serializeReview, validateGitAvailable };
|
package/dist/index.d.ts
CHANGED
|
@@ -349,12 +349,22 @@ interface MaterializeResult {
|
|
|
349
349
|
*/
|
|
350
350
|
cleanup: () => void;
|
|
351
351
|
}
|
|
352
|
+
/** A local clone whose fetch remote matches the requested forge repository. */
|
|
353
|
+
interface ExistingClone {
|
|
354
|
+
repoPath: string;
|
|
355
|
+
remoteName: string;
|
|
356
|
+
}
|
|
352
357
|
/**
|
|
353
358
|
* Default runner: spawns real git. Resolves with the exit code on any
|
|
354
359
|
* completed run (including non-zero); rejects only when git cannot be
|
|
355
360
|
* spawned at all (e.g. ENOENT).
|
|
356
361
|
*/
|
|
357
362
|
declare const defaultGitRunner: ForgeCommandRunner;
|
|
363
|
+
/**
|
|
364
|
+
* Detect an existing clone: when `cwd` is inside a git repository with a
|
|
365
|
+
* remote matching the forge URL, return `{ repoPath, remoteName }`.
|
|
366
|
+
*/
|
|
367
|
+
declare function detectExistingClone(url: ForgeUrl, cwd: string, runner?: ForgeCommandRunner): Promise<ExistingClone | null>;
|
|
358
368
|
/**
|
|
359
369
|
* Materialize a forge PR/MR into a local git context.
|
|
360
370
|
*
|
|
@@ -363,17 +373,21 @@ declare const defaultGitRunner: ForgeCommandRunner;
|
|
|
363
373
|
* branch and PR/MR head refs are fetched into that clone under
|
|
364
374
|
* `refs/self-review/*` — read-only for the working tree. Otherwise a
|
|
365
375
|
* blobless clone is created in a unique directory under the OS temp root
|
|
366
|
-
* and `cleanup()` removes exactly that directory.
|
|
376
|
+
* and `cleanup()` removes exactly that directory. Callers that already
|
|
377
|
+
* detected a clone may pass it to avoid repeating the git probes.
|
|
367
378
|
*
|
|
368
379
|
* The returned `headSha` is the live remote head, so callers can compare it
|
|
369
380
|
* against a recorded `remote-head-sha` for drift detection.
|
|
370
381
|
*/
|
|
371
|
-
declare function materialize(url: ForgeUrl, baseBranch: string, cwd: string, runner?: ForgeCommandRunner): Promise<MaterializeResult>;
|
|
382
|
+
declare function materialize(url: ForgeUrl, baseBranch: string, cwd: string, runner?: ForgeCommandRunner, existingClone?: ExistingClone | null): Promise<MaterializeResult>;
|
|
372
383
|
/**
|
|
373
384
|
* Git-only fallback for the base branch when no forge CLI is available:
|
|
374
385
|
* resolves the remote's default branch from its HEAD symref via
|
|
375
|
-
* `git ls-remote --symref <
|
|
386
|
+
* `git ls-remote --symref <remote> HEAD`. When an existing matching clone
|
|
387
|
+
* is supplied, the configured remote is used so its SSH/HTTPS transport
|
|
388
|
+
* and credentials are preserved. Otherwise the forge HTTPS URL is used.
|
|
389
|
+
* No forge API involved.
|
|
376
390
|
*/
|
|
377
|
-
declare function resolveRemoteDefaultBranch(url: ForgeUrl, runner?: ForgeCommandRunner): Promise<string>;
|
|
391
|
+
declare function resolveRemoteDefaultBranch(url: ForgeUrl, runner?: ForgeCommandRunner, existing?: ExistingClone | null): Promise<string>;
|
|
378
392
|
|
|
379
|
-
export { type FetchThreadsOptions, type ForgeAnchorSide, ForgeCliUnavailableError, type ForgeCommandResult, type ForgeCommandRunner, type ForgeName, type ForgeProvider, type ForgeThread, type ForgeThreadAnchor, type ForgeThreadTurn, type ForgeUrl, GUIDE_XSD_SCHEMA, type GuideParseResult, IMPLICIT_GUIDE_GROUP_NAME, type MaterializeMode, type MaterializeResult, REVIEW_LEVEL_FILE_PATH, type RenderedTextMode, checkWritability, computePayloadStats, countTotalLines, createGitHubProvider, createGitLabProvider, createIgnoreFilter, defaultGitRunner, generateSyntheticDiffs, generateUntrackedDiffs, getGitDiffStats, getLanguageFromPath, getRenderedTextMode, getRepoRoot, getRepoRootAsync, getUntrackedFilesAsync, isHtmlFile, isMarkdownFile, isPreviewableImage, isPreviewableRenderedText, isPreviewableSvg, loadConfig, mapThreadsToReviewComments, materialize, parseDiff, parseForgeUrl, parseGuideXml, parseReviewXml, parseReviewXmlString, reconcileGuide, resolveRemoteDefaultBranch, runGitDiff, runGitDiffAsync, scanDirectory, scanFile, serializeReview, validateGitAvailable };
|
|
393
|
+
export { type ExistingClone, type FetchThreadsOptions, type ForgeAnchorSide, ForgeCliUnavailableError, type ForgeCommandResult, type ForgeCommandRunner, type ForgeName, type ForgeProvider, type ForgeThread, type ForgeThreadAnchor, type ForgeThreadTurn, type ForgeUrl, GUIDE_XSD_SCHEMA, type GuideParseResult, IMPLICIT_GUIDE_GROUP_NAME, type MaterializeMode, type MaterializeResult, REVIEW_LEVEL_FILE_PATH, type RenderedTextMode, checkWritability, computePayloadStats, countTotalLines, createGitHubProvider, createGitLabProvider, createIgnoreFilter, defaultGitRunner, detectExistingClone, generateSyntheticDiffs, generateUntrackedDiffs, getGitDiffStats, getLanguageFromPath, getRenderedTextMode, getRepoRoot, getRepoRootAsync, getUntrackedFilesAsync, isHtmlFile, isMarkdownFile, isPreviewableImage, isPreviewableRenderedText, isPreviewableSvg, loadConfig, mapThreadsToReviewComments, materialize, parseDiff, parseForgeUrl, parseGuideXml, parseReviewXml, parseReviewXmlString, reconcileGuide, resolveRemoteDefaultBranch, runGitDiff, runGitDiffAsync, scanDirectory, scanFile, serializeReview, validateGitAvailable };
|
package/dist/index.js
CHANGED
|
@@ -2523,7 +2523,7 @@ async function revParse(runner, repoPath, ref) {
|
|
|
2523
2523
|
}
|
|
2524
2524
|
return result.stdout.trim();
|
|
2525
2525
|
}
|
|
2526
|
-
async function detectExistingClone(
|
|
2526
|
+
async function detectExistingClone(url, cwd, runner = defaultGitRunner) {
|
|
2527
2527
|
const toplevel = await runner("git", ["-C", cwd, "rev-parse", "--show-toplevel"]);
|
|
2528
2528
|
if (toplevel.exitCode !== 0) {
|
|
2529
2529
|
return null;
|
|
@@ -2604,8 +2604,8 @@ async function materializeIntoTempClone(runner, url, baseBranch) {
|
|
|
2604
2604
|
throw error;
|
|
2605
2605
|
}
|
|
2606
2606
|
}
|
|
2607
|
-
async function materialize(url, baseBranch, cwd, runner = defaultGitRunner) {
|
|
2608
|
-
const existing = await detectExistingClone(
|
|
2607
|
+
async function materialize(url, baseBranch, cwd, runner = defaultGitRunner, existingClone) {
|
|
2608
|
+
const existing = existingClone === void 0 ? await detectExistingClone(url, cwd, runner) : existingClone;
|
|
2609
2609
|
if (existing) {
|
|
2610
2610
|
return materializeIntoExistingClone(
|
|
2611
2611
|
runner,
|
|
@@ -2617,16 +2617,19 @@ async function materialize(url, baseBranch, cwd, runner = defaultGitRunner) {
|
|
|
2617
2617
|
}
|
|
2618
2618
|
return materializeIntoTempClone(runner, url, baseBranch);
|
|
2619
2619
|
}
|
|
2620
|
-
async function resolveRemoteDefaultBranch(url, runner = defaultGitRunner) {
|
|
2620
|
+
async function resolveRemoteDefaultBranch(url, runner = defaultGitRunner, existing = null) {
|
|
2621
2621
|
const cloneUrl = cloneUrlFor(url);
|
|
2622
|
-
const
|
|
2622
|
+
const remote = existing?.remoteName ?? cloneUrl;
|
|
2623
|
+
const label = existing ? `${remote} (${cloneUrl})` : cloneUrl;
|
|
2624
|
+
const args = existing ? ["-C", existing.repoPath, "ls-remote", "--symref", remote, "HEAD"] : ["ls-remote", "--symref", remote, "HEAD"];
|
|
2625
|
+
const result = await runner("git", args);
|
|
2623
2626
|
if (result.exitCode !== 0) {
|
|
2624
|
-
throw gitFailure(`ls-remote of ${
|
|
2627
|
+
throw gitFailure(`ls-remote of ${label}`, result, true);
|
|
2625
2628
|
}
|
|
2626
2629
|
const match = /^ref:\s+refs\/heads\/(\S+)\s+HEAD$/m.exec(result.stdout);
|
|
2627
2630
|
if (!match) {
|
|
2628
2631
|
throw new Error(
|
|
2629
|
-
`Failed to resolve the default branch of ${
|
|
2632
|
+
`Failed to resolve the default branch of ${label}: git ls-remote returned no HEAD symref.`
|
|
2630
2633
|
);
|
|
2631
2634
|
}
|
|
2632
2635
|
return match[1];
|
|
@@ -2643,6 +2646,7 @@ export {
|
|
|
2643
2646
|
createGitLabProvider,
|
|
2644
2647
|
createIgnoreFilter,
|
|
2645
2648
|
defaultGitRunner,
|
|
2649
|
+
detectExistingClone,
|
|
2646
2650
|
generateSyntheticDiffs,
|
|
2647
2651
|
generateUntrackedDiffs,
|
|
2648
2652
|
getGitDiffStats,
|