@@ -35,7 +35,6 @@ import { |
35 | 35 | ModelSelection, |
36 | 36 | type ProjectId, |
37 | 37 | SourceControlProviderError, |
38 | | - type SourceControlProviderKind, |
39 | 38 | type SourceControlWritingStyleSettings, |
40 | 39 | type ThreadId, |
41 | 40 | type ThreadPullRequestKey, |
@@ -81,6 +80,7 @@ import { detachStackFrame } from "./detachStackFrame.ts"; |
81 | 80 | import * as ServerSettings from "../serverSettings.ts"; |
82 | 81 | import type { GitManagerServiceError } from "@t3tools/contracts"; |
83 | 82 | import * as GitVcsDriver from "../vcs/GitVcsDriver.ts"; |
| 83 | +import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider"; |
84 | 84 | import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts"; |
85 | 85 | import { detectPrTemplate } from "../sourceControl/PrTemplateDetection.ts"; |
86 | 86 | import type { ChangeRequest } from "@t3tools/contracts"; |
@@ -314,27 +314,20 @@ function resolvePullRequestWorktreeLocalBranchName( |
314 | 314 | return `t3code/pr-${pullRequest.number}/${suffix}`; |
315 | 315 | } |
316 | 316 |
|
| 317 | +/** The repository's `owner/name` from a remote URL, as `provider` reads its remote paths. */ |
317 | 318 | export function parseRepositoryNameWithOwnerFromRemoteUrl( |
318 | 319 | url: string | null, |
319 | | - providerKind?: ChangeRequest["provider"], |
| 320 | + provider?: Pick< |
| 321 | + SourceControlProvider.SourceControlProvider["Service"], |
| 322 | + "repositoryNameFromRemoteUrl" |
| 323 | + >, |
320 | 324 | ): string | null { |
321 | 325 | const trimmed = url?.trim() ?? ""; |
322 | | - if (trimmed.length === 0) { |
323 | | - return null; |
324 | | - } |
325 | | - |
326 | | - const match = |
327 | | - /^(?:[^@/\s]+@[^:/\s]+:|(?:ssh|https?|git):\/\/[^/]+\/)((?:[^/\s]+\/)+[^/\s]+?)(?:\.git)?\/?$/iu.exec( |
328 | | - trimmed, |
329 | | - ); |
330 | | - const repositoryNameWithOwner = match?.[1]?.trim() ?? ""; |
331 | | - // Forgejo HTTP paths can include an installation mount; its API always names owner/repo. |
332 | | - if (providerKind === "forgejo" && /^https?:\/\//iu.test(trimmed)) { |
333 | | - return repositoryNameWithOwner.length > 0 |
334 | | - ? repositoryNameWithOwner.split("/").slice(-2).join("/") |
335 | | - : null; |
336 | | - } |
337 | | - return repositoryNameWithOwner.length > 0 ? repositoryNameWithOwner : null; |
| 326 | + if (trimmed.length === 0) return null; |
| 327 | + return ( |
| 328 | + provider?.repositoryNameFromRemoteUrl?.(trimmed) ?? |
| 329 | + SourceControlProvider.repositoryPathFromRemoteUrl(trimmed) |
| 330 | + ); |
338 | 331 | } |
339 | 332 |
|
340 | 333 | function parseRepositoryOwnerLogin(nameWithOwner: string | null): string | null { |
@@ -625,22 +618,14 @@ function parseCustomCommitMessage(raw: string): { subject: string; body: string |
625 | 618 | }; |
626 | 619 | } |
627 | 620 |
|
628 | | -// Without the owner selector, a bare branch name also lists same-named |
629 | | -// branches on other forks (`main`, `patch-1`), so GitHub probes ask for a full |
630 | | -// page and let matchesBranchHeadContext pick the right head. gh fetches up to |
631 | | -// 100 in one request, and GitHub prices a first:100 connection like first:1. |
632 | | -const GITHUB_HEAD_BRANCH_PROBE_LIMIT = 100; |
633 | | - |
634 | | -// `gh pr list --head` filters on the head ref name alone and accepts anything, so an |
635 | | -// `owner:branch` or `remote:branch` selector silently lists zero pull requests |
636 | | -// while spending a GraphQL call. Git branch names cannot contain ":", and the |
637 | | -// bare head branch is always among the selectors, so GitHub probes skip them and |
638 | | -// leave the owner check to matchesBranchHeadContext. |
| 621 | +// Git branch names cannot contain ":", and the bare head branch is always among the |
| 622 | +// selectors, so a host that cannot search `owner:branch` loses nothing by skipping them: |
| 623 | +// matchesBranchHeadContext does the owner check on the results. |
639 | 624 | function probeableHeadSelectors( |
640 | | - providerKind: SourceControlProviderKind, |
| 625 | + provider: SourceControlProvider.SourceControlProvider["Service"], |
641 | 626 | headSelectors: ReadonlyArray<string>, |
642 | 627 | ): ReadonlyArray<string> { |
643 | | - return providerKind === "github" |
| 628 | + return provider.searchesOwnerHeadSelectors === false |
644 | 629 | ? headSelectors.filter((selector) => !selector.includes(":")) |
645 | 630 | : headSelectors; |
646 | 631 | } |
@@ -1430,15 +1415,14 @@ export const make = Effect.gen(function* () { |
1430 | 1415 | /^https?:\/\//iu.test(remoteUrl) && |
1431 | 1416 | (repositoryNameWithOwner?.split("/").length ?? 0) > 2 |
1432 | 1417 | ) { |
1433 | | - const detected = detectSourceControlProviderFromGitRemoteUrl(remoteUrl); |
1434 | | - const kind = |
1435 | | - detected?.kind === "unknown" |
1436 | | - ? yield* sourceControlProvider(cwd).pipe( |
1437 | | - Effect.map((provider) => provider.kind), |
1438 | | - Effect.orElseSucceed(() => undefined), |
1439 | | - ) |
1440 | | - : detected?.kind; |
1441 | | - repositoryNameWithOwner = parseRepositoryNameWithOwnerFromRemoteUrl(remoteUrl, kind); |
| 1418 | + const kind = detectSourceControlProviderFromGitRemoteUrl(remoteUrl)?.kind; |
| 1419 | + const provider = |
| 1420 | + kind === undefined |
| 1421 | + ? undefined |
| 1422 | + : yield* ( |
| 1423 | + kind === "unknown" ? sourceControlProvider(cwd) : sourceControlProviders.get(kind) |
| 1424 | + ).pipe(Effect.orElseSucceed(() => undefined)); |
| 1425 | + repositoryNameWithOwner = parseRepositoryNameWithOwnerFromRemoteUrl(remoteUrl, provider); |
1442 | 1426 | } |
1443 | 1427 | return { |
1444 | 1428 | remoteUrlKey: remoteUrl ? normalizeGitRemoteUrl(remoteUrl) : null, |
@@ -1701,13 +1685,13 @@ export const make = Effect.gen(function* () { |
1701 | 1685 | >, |
1702 | 1686 | ) { |
1703 | 1687 | const provider = yield* sourceControlProvider(cwd); |
1704 | | - const headSelectors = probeableHeadSelectors(provider.kind, headContext.headSelectors); |
| 1688 | + const headSelectors = probeableHeadSelectors(provider, headContext.headSelectors); |
1705 | 1689 | for (const headSelector of headSelectors) { |
1706 | 1690 | const pullRequests = yield* provider.listChangeRequests({ |
1707 | 1691 | cwd, |
1708 | 1692 | headSelector, |
1709 | 1693 | state: "open", |
1710 | | - limit: provider.kind === "github" ? GITHUB_HEAD_BRANCH_PROBE_LIMIT : 1, |
| 1694 | + limit: provider.headBranchProbeLimit ?? 1, |
1711 | 1695 | }); |
1712 | 1696 | const normalizedPullRequests = pullRequests.map(toPullRequestInfo); |
1713 | 1697 |
|
@@ -1733,12 +1717,12 @@ export const make = Effect.gen(function* () { |
1733 | 1717 | const parsedByNumber = new Map<number, PullRequestInfo>(); |
1734 | 1718 |
|
1735 | 1719 | const provider = yield* sourceControlProvider(cwd); |
1736 | | - for (const headSelector of probeableHeadSelectors(provider.kind, headContext.headSelectors)) { |
| 1720 | + for (const headSelector of probeableHeadSelectors(provider, headContext.headSelectors)) { |
1737 | 1721 | const pullRequests = yield* provider.listChangeRequests({ |
1738 | 1722 | cwd, |
1739 | 1723 | headSelector, |
1740 | 1724 | state: "all", |
1741 | | - limit: provider.kind === "github" ? GITHUB_HEAD_BRANCH_PROBE_LIMIT : 20, |
| 1725 | + limit: provider.headBranchProbeLimit ?? 20, |
1742 | 1726 | }); |
1743 | 1727 |
|
1744 | 1728 | for (const pr of pullRequests.map(toPullRequestInfo)) { |
@@ -2129,7 +2113,7 @@ export const make = Effect.gen(function* () { |
2129 | 2113 | const rangeContext = yield* gitCore.readRangeContext(cwd, baseRangeRef); |
2130 | 2114 | const policy = yield* resolveStylePolicy(cwd, settings); |
2131 | 2115 | const changeRequestTemplate = |
2132 | | - settings.style.followChangeRequestTemplates && provider.kind === "github" |
| 2116 | + settings.style.followChangeRequestTemplates && provider.followsChangeRequestTemplates === true |
2133 | 2117 | ? Option.getOrUndefined(yield* detectPrTemplate(cwd, baseRangeRef, gitCore.execute)) |
2134 | 2118 | : undefined; |
2135 | 2119 |
|
|