refactor: remove glabPath and ghPath options from providers and update related code

This commit is contained in:
Lauren ten Hoor
2026-02-09 22:33:46 +08:00
parent 7a29da4c83
commit 3a2e739a62
12 changed files with 40 additions and 75 deletions

View File

@@ -24,7 +24,6 @@ import {
const execFileAsync = promisify(execFile);
export type GitHubProviderOptions = {
ghPath?: string;
repoPath: string;
};
@@ -50,16 +49,14 @@ function toIssue(gh: GhIssue): Issue {
}
export class GitHubProvider implements IssueProvider {
private ghPath: string;
private repoPath: string;
constructor(opts: GitHubProviderOptions) {
this.ghPath = opts.ghPath ?? "gh";
this.repoPath = opts.repoPath;
}
private async gh(args: string[]): Promise<string> {
const { stdout } = await execFileAsync(this.ghPath, args, {
const { stdout } = await execFileAsync("gh", args, {
cwd: this.repoPath,
timeout: 30_000,
});

View File

@@ -20,21 +20,18 @@ import {
const execFileAsync = promisify(execFile);
export type GitLabProviderOptions = {
glabPath?: string;
repoPath: string;
};
export class GitLabProvider implements IssueProvider {
private glabPath: string;
private repoPath: string;
constructor(opts: GitLabProviderOptions) {
this.glabPath = opts.glabPath ?? "glab";
this.repoPath = opts.repoPath;
}
private async glab(args: string[]): Promise<string> {
const { stdout } = await execFileAsync(this.glabPath, args, {
const { stdout } = await execFileAsync("glab", args, {
cwd: this.repoPath,
timeout: 30_000,
});
@@ -76,7 +73,7 @@ export class GitLabProvider implements IssueProvider {
const { promisify } = await import("node:util");
const execAsync = promisify(exec);
let cmd = `${this.glabPath} issue create --title "${title.replace(/"/g, '\\"')}" --description "$(cat ${tempFile})" --label "${label}" --output json`;
let cmd = `glab issue create --title "${title.replace(/"/g, '\\"')}" --description "$(cat ${tempFile})" --label "${label}" --output json`;
if (assignees && assignees.length > 0) {
cmd += ` --assignee "${assignees.join(",")}"`;
}

View File

@@ -11,12 +11,12 @@ 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";
glabPath?: string;
ghPath?: string;
repoPath: string;
repo?: string;
repoPath?: string;
};
function detectProvider(repoPath: string): "gitlab" | "github" {
@@ -39,16 +39,21 @@ export type ProviderWithType = {
};
export function createProvider(opts: ProviderOptions): ProviderWithType {
const type = opts.provider ?? detectProvider(opts.repoPath);
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({ ghPath: opts.ghPath, repoPath: opts.repoPath }),
provider: new GitHubProvider({ repoPath }),
type: "github",
};
}
return {
provider: new GitLabProvider({ glabPath: opts.glabPath, repoPath: opts.repoPath }),
provider: new GitLabProvider({ repoPath }),
type: "gitlab",
};
}