Initial commit: DevClaw with Gitea support
This commit is contained in:
@@ -1,27 +1,36 @@
|
||||
/**
|
||||
* Provider factory — auto-detects GitHub vs GitLab from git remote.
|
||||
* Provider factory — auto-detects GitHub vs GitLab vs Gitea from git remote.
|
||||
*/
|
||||
import type { IssueProvider } from "./provider.js";
|
||||
import { GitLabProvider } from "./gitlab.js";
|
||||
import { GitHubProvider } from "./github.js";
|
||||
import { GiteaProvider } from "./gitea.js";
|
||||
import { resolveRepoPath } from "../projects.js";
|
||||
import { runCommand } from "../run-command.js";
|
||||
|
||||
export type ProviderOptions = {
|
||||
provider?: "gitlab" | "github";
|
||||
provider?: "gitlab" | "github" | "gitea";
|
||||
repo?: string;
|
||||
repoPath?: string;
|
||||
};
|
||||
|
||||
export type ProviderWithType = {
|
||||
provider: IssueProvider;
|
||||
type: "github" | "gitlab";
|
||||
type: "github" | "gitlab" | "gitea";
|
||||
};
|
||||
|
||||
async function detectProvider(repoPath: string): Promise<"gitlab" | "github"> {
|
||||
async function detectProvider(repoPath: string): Promise<"gitlab" | "github" | "gitea"> {
|
||||
try {
|
||||
const result = await runCommand(["git", "remote", "get-url", "origin"], { timeoutMs: 5_000, cwd: repoPath });
|
||||
return result.stdout.trim().includes("github.com") ? "github" : "gitlab";
|
||||
const remote = result.stdout.trim();
|
||||
|
||||
if (remote.includes("github.com")) {
|
||||
return "github";
|
||||
} else if (remote.includes("192.168.1.150:3000")) {
|
||||
return "gitea";
|
||||
} else {
|
||||
return "gitlab";
|
||||
}
|
||||
} catch {
|
||||
return "gitlab";
|
||||
}
|
||||
@@ -31,6 +40,20 @@ export async function createProvider(opts: ProviderOptions): Promise<ProviderWit
|
||||
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 ?? await detectProvider(repoPath);
|
||||
const provider = type === "github" ? new GitHubProvider({ repoPath }) : new GitLabProvider({ repoPath });
|
||||
|
||||
let provider: IssueProvider;
|
||||
switch (type) {
|
||||
case "github":
|
||||
provider = new GitHubProvider({ repoPath });
|
||||
break;
|
||||
case "gitea":
|
||||
provider = new GiteaProvider({ repoPath });
|
||||
break;
|
||||
case "gitlab":
|
||||
default:
|
||||
provider = new GitLabProvider({ repoPath });
|
||||
break;
|
||||
}
|
||||
|
||||
return { provider, type };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user