Problem: Provider type (github/gitlab) was auto-detected on every createProvider() call but never persisted, causing loss of configuration after session restart. Solution: - Add 'provider' field to Project type - Store detected provider type during project registration - Pass stored provider type to createProvider() calls Changes: - lib/projects.ts: Add provider field to Project type - lib/tools/project-register.ts: Save providerType to projects.json - lib/tool-helpers.ts: Pass project.provider to createProvider - lib/services/*.ts: Pass project.provider to createProvider Impact: Issue tracker source now persists across restarts. Existing projects will auto-detect on next use and should be re-registered or manually edited to add provider field. Fixes #193
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
/**
|
|
* tool-helpers.ts — Shared resolution helpers for tool execute() functions.
|
|
*
|
|
* Eliminates repeated boilerplate across tools: workspace validation,
|
|
* project resolution, provider creation.
|
|
*/
|
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
import type { ToolContext } from "./types.js";
|
|
import { readProjects, getProject, type Project, type ProjectsData } from "./projects.js";
|
|
import { createProvider, type ProviderWithType } from "./providers/index.js";
|
|
|
|
/**
|
|
* Require workspaceDir from context or throw a clear error.
|
|
*/
|
|
export function requireWorkspaceDir(ctx: ToolContext): string {
|
|
if (!ctx.workspaceDir) {
|
|
throw new Error("No workspace directory available in tool context");
|
|
}
|
|
return ctx.workspaceDir;
|
|
}
|
|
|
|
/**
|
|
* Resolve project by groupId, throw if not found.
|
|
*/
|
|
export async function resolveProject(
|
|
workspaceDir: string,
|
|
groupId: string,
|
|
): Promise<{ data: ProjectsData; project: Project }> {
|
|
const data = await readProjects(workspaceDir);
|
|
const project = getProject(data, groupId);
|
|
if (!project) {
|
|
throw new Error(`Project not found for groupId ${groupId}. Run project_register first.`);
|
|
}
|
|
return { data, project };
|
|
}
|
|
|
|
/**
|
|
* Create an issue provider for a project.
|
|
* Uses stored provider type from project config if available, otherwise auto-detects.
|
|
*/
|
|
export async function resolveProvider(project: Project): Promise<ProviderWithType> {
|
|
return createProvider({ repo: project.repo, provider: project.provider });
|
|
}
|
|
|
|
/**
|
|
* Get plugin config as a typed record (or undefined).
|
|
*/
|
|
export function getPluginConfig(api: OpenClawPluginApi): Record<string, unknown> | undefined {
|
|
return api.pluginConfig as Record<string, unknown> | undefined;
|
|
}
|