Fix Gitea provider label transitions and error handling

- Fix label transition to use PUT /issues/{id}/labels endpoint (PATCH doesn't work)
- Add better error handling in apiRequest method
- Hardcode label IDs for reliability (temporary fix)
- Handle undefined exitCode from runCommand
- Update base URL to use public pfoster.dynu.net
This commit is contained in:
2026-02-15 09:21:03 +00:00
parent 229312323d
commit 30c4a9a088

View File

@@ -81,8 +81,13 @@ export class GiteaProvider implements IssueProvider {
const result = await runCommand(args, { timeoutMs: 30_000 });
if (result.stderr) {
console.error(`Gitea API error for ${method} ${endpoint}:`, result.stderr);
// Check for command execution errors
if (result.error) {
throw new Error(`Gitea API ${method} ${endpoint} failed: ${result.error}`);
}
if (result.exitCode !== undefined && result.exitCode !== 0) {
throw new Error(`Gitea API ${method} ${endpoint} failed (exit ${result.exitCode}): ${result.stderr || 'Unknown error'}`);
}
if (result.stdout.trim()) {
@@ -93,8 +98,7 @@ export class GiteaProvider implements IssueProvider {
}
return parsed;
} catch (err) {
console.error(`Failed to parse JSON from Gitea API: ${result.stdout.substring(0, 200)}`);
throw new Error(`Failed to parse JSON from Gitea API: ${(err as Error).message}`);
throw new Error(`Failed to parse JSON from Gitea API: ${result.stdout.substring(0, 200)}`);
}
}
@@ -102,21 +106,23 @@ export class GiteaProvider implements IssueProvider {
}
private async getLabelId(labelName: string): Promise<number> {
// Check cache first
if (this.labelCache.has(labelName)) {
return this.labelCache.get(labelName)!;
}
// Hardcoded label IDs for our Gitea instance
const labelMap: Record<string, number> = {
"Planning": 1,
"To Do": 2,
"Doing": 3,
"To Test": 4,
"Testing": 5,
"To Improve": 6,
"Refining": 7,
"Done": 8,
"To Design": 9,
"Designing": 10
};
// Fetch all labels and cache them
const labels = await this.apiRequest("GET", `/repos/${this.owner}/${this.repo}/labels`) as GiteaLabel[];
for (const label of labels) {
this.labelCache.set(label.name, label.id);
}
const labelId = this.labelCache.get(labelName);
const labelId = labelMap[labelName];
if (!labelId) {
throw new Error(`Label "${labelName}" not found in Gitea repo`);
throw new Error(`Label "${labelName}" not found in hardcoded map`);
}
return labelId;