Files
devclaw-gitea/lib/providers/index.ts
Lauren ten Hoor d7178bb8e5 refactor: reorganize task management imports and update task handling tools
- Updated import paths for task management providers in task-comment, task-create, and task-update tools.
- Removed deprecated task-complete and task-pickup tools, replacing them with work-finish and work-start tools for improved task handling.
- Enhanced work-finish and work-start tools to streamline task completion and pickup processes, including context-aware detection and auto-scheduling features.
- Updated package.json to include build scripts and main entry point.
- Modified tsconfig.json to enable output directory, declaration files, and source maps for better TypeScript support.
2026-02-10 21:39:41 +08:00

37 lines
1.2 KiB
TypeScript

/**
* Provider factory — auto-detects GitHub vs GitLab from git remote.
*/
import { execFileSync } from "node:child_process";
import type { IssueProvider } from "./provider.js";
import { GitLabProvider } from "./gitlab.js";
import { GitHubProvider } from "./github.js";
import { resolveRepoPath } from "../projects.js";
export type ProviderOptions = {
provider?: "gitlab" | "github";
repo?: string;
repoPath?: string;
};
export type ProviderWithType = {
provider: IssueProvider;
type: "github" | "gitlab";
};
function detectProvider(repoPath: string): "gitlab" | "github" {
try {
const url = execFileSync("git", ["remote", "get-url", "origin"], { cwd: repoPath, timeout: 5_000 }).toString().trim();
return url.includes("github.com") ? "github" : "gitlab";
} catch {
return "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");
const type = opts.provider ?? detectProvider(repoPath);
const provider = type === "github" ? new GitHubProvider({ repoPath }) : new GitLabProvider({ repoPath });
return { provider, type };
}