Files
devclaw-gitea/lib/providers/index.ts
Lauren ten Hoor 8a79755e4c feat: Implement GitLabProvider for issue management using glab CLI
- Add GitLabProvider class for handling issue operations, label management, and MR checks.
- Implement methods for ensuring labels, creating issues, listing issues by label, and transitioning labels.
- Introduce a provider factory to auto-detect GitLab or GitHub based on the repository URL.
- Create project registration tool to validate repositories, create state labels, and log project entries.
- Enhance queue status and session health tools to support new session management features.
- Update task completion and task creation tools to support auto-chaining and improved session handling.
- Refactor task pickup tool to streamline model selection and session management.
2026-02-09 12:54:50 +08:00

55 lines
1.4 KiB
TypeScript

/**
* 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";
export type ProviderOptions = {
provider?: "gitlab" | "github";
glabPath?: string;
ghPath?: 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 type = opts.provider ?? detectProvider(opts.repoPath);
if (type === "github") {
return {
provider: new GitHubProvider({ ghPath: opts.ghPath, repoPath: opts.repoPath }),
type: "github",
};
}
return {
provider: new GitLabProvider({ glabPath: opts.glabPath, repoPath: opts.repoPath }),
type: "gitlab",
};
}