refactor: migrate issue provider logic to task manager interface and implement GitHub/GitLab providers

This commit is contained in:
Lauren ten Hoor
2026-02-09 22:38:43 +08:00
parent 3a2e739a62
commit 4e10b171c1
10 changed files with 30 additions and 24 deletions

View File

@@ -1,59 +0,0 @@
/**
* Provider factory — creates the appropriate IssueProvider for a repository.
*
* Auto-detects provider from git remote URL:
* - github.com → GitHubProvider (gh CLI)
* - Everything else → GitLabProvider (glab CLI)
*
* Can be overridden with explicit `provider` option.
*/
import { execFileSync } from "node:child_process";
import type { IssueProvider } from "../issue-provider.js";
import { GitLabProvider } from "./gitlab.js";
import { GitHubProvider } from "./github.js";
import { resolveRepoPath } from "../utils.js";
export type ProviderOptions = {
provider?: "gitlab" | "github";
repo?: string;
repoPath?: string;
};
function detectProvider(repoPath: string): "gitlab" | "github" {
try {
const url = execFileSync("git", ["remote", "get-url", "origin"], {
cwd: repoPath,
timeout: 5_000,
}).toString().trim();
if (url.includes("github.com")) return "github";
return "gitlab";
} catch {
return "gitlab";
}
}
export type ProviderWithType = {
provider: IssueProvider;
type: "github" | "gitlab";
};
export function createProvider(opts: ProviderOptions): ProviderWithType {
const repoPath = opts.repoPath ?? (opts.repo ? resolveRepoPath(opts.repo) : null);
if (!repoPath) {
throw new Error("Either repoPath or repo must be provided to createProvider");
}
const type = opts.provider ?? detectProvider(repoPath);
if (type === "github") {
return {
provider: new GitHubProvider({ repoPath }),
type: "github",
};
}
return {
provider: new GitLabProvider({ repoPath }),
type: "gitlab",
};
}