refactor(source-control): GitManager reads provider resolvers, not host kinds (#17617)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5.5 authored and GitHub committed 2026-10-09 16:22:36 -07:00
1 parent c85dc64268
commit 49f849ecce
11 files changed
+190 -107

No files matched your search

@@ -1,5 +1,6 @@
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import type * as Option from "effect/Option";
import type {
ChangeRequest,
ChangeRequestState,
@@ -92,10 +93,48 @@ export function sourceControlRefFromInput(input: {
return input.source ?? parseSourceControlOwnerRef(input.headSelector);
}
/** The repository path a remote URL names (`owner/name`, or deeper for nested groups). */
export function repositoryPathFromRemoteUrl(url: string | null): string | null {
const trimmed = url?.trim() ?? "";
if (trimmed.length === 0) {
return null;
}
const match =
/^(?:[^@/\s]+@[^:/\s]+:|(?:ssh|https?|git):\/\/[^/]+\/)((?:[^/\s]+\/)+[^/\s]+?)(?:\.git)?\/?$/iu.exec(
trimmed,
);
const path = match?.[1]?.trim() ?? "";
return path.length > 0 ? path : null;
}
export class SourceControlProvider extends Context.Service<
SourceControlProvider,
{
readonly kind: SourceControlProviderKind;
/**
* How to look up a branch's change requests: which head selectors to ask about, and how many
* results to read per selector. The caller checks the owner against what comes back, so a
* host that cannot search `owner:branch` can drop those selectors without losing anything.
* Absent asks about every selector, reading 1 for the open lookup and 20 for any state.
*/
readonly headBranchProbe?: (input: {
readonly headSelectors: ReadonlyArray<string>;
readonly state: "open" | "all";
}) => { readonly headSelectors: ReadonlyArray<string>; readonly limit: number };
/**
* The repository's change request template at `treeish`, for change request content
* generation to follow. Absent means the host has no template convention.
*/
readonly readChangeRequestTemplate?: (input: {
readonly cwd: string;
readonly treeish: string;
}) => Effect.Effect<Option.Option<string>>;
/**
* The repository's `owner/name` from a remote URL, for a host whose remote paths can carry
* more than that (Forgejo's HTTP installation mount). Absent means the whole path.
*/
readonly repositoryNameFromRemoteUrl?: (url: string) => string | null;
/** Optional capability for issue and change-request subjects. */
readonly resolveLink?: ResolveSourceControlLink;
readonly listChangeRequests: (input: {