Compare commits

...
7 Commits
Author SHA1 Message Date
Daniel SamsonandClaude Opus 4.6 f693d56762 Handle Gitea review webhook type field alongside state
Publish Image / publish (push) Successful in 23s
Gitea webhook payloads use "type" (e.g. "pull_request_review_rejected")
instead of "state" (e.g. "REQUEST_CHANGES"). Map both formats so
the pr-rework handler works with all Gitea webhook variations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 18:13:51 +01:00
Daniel SamsonandClaude Opus 4.6 a72ea9ad1d Fix BullMQ job dedup — remove completed/failed jobs
Publish Image / publish (push) Successful in 21s
Completed jobs with the same jobId block new jobs from being added.
Add removeOnComplete and removeOnFail to all job options so the same
task can be re-triggered after completion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 16:37:52 +01:00
Daniel SamsonandClaude Opus 4.6 2cdf68ddff Fix pr-rework crash — guard against missing review.state
Publish Image / publish (push) Successful in 23s
Gitea sends review objects without a state field in some cases.
Use optional chaining and log the review payload for debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 16:26:58 +01:00
Daniel SamsonandClaude Opus 4.6 81aee2f7fc Route spec PR review feedback to rework-spec instead of rework-pr
Publish Image / publish (push) Successful in 23s
When a review requests changes on a docs/ branch (architect PR), trigger
the rework-spec task type instead of rework-pr. This re-runs the architect
persona to fix the design docs based on review feedback.

- Add rework-spec to Coder template task_type options and lightweight stages
- Detect architect PRs via docs/ branch prefix in pr-rework handler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 16:18:00 +01:00
Daniel SamsonandClaude Opus 4.6 f495ea391f Fix issue-label and pr-rework webhook handlers
Publish Image / publish (push) Successful in 22s
- issue-label: Accept action "created" from Gitea (in addition to
  "labeled" and "label_updated") — Gitea sends "created" for new labels
- pr-rework: Guard against missing review object to prevent TypeError
  crash when Gitea sends review webhook without review data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 16:12:04 +01:00
Daniel SamsonandClaude Opus 4.6 d19798dfea Add debug logging to issue-label handler
Publish Image / publish (push) Successful in 23s
Log the webhook action and labels to diagnose why label events are
being ignored.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 15:56:19 +01:00
Daniel SamsonandClaude Opus 4.6 0812a9be37 Fix workspace deletion — use build transition API
Publish Image / publish (push) Successful in 35s
The plain DELETE endpoint returns 405 for stopped workspaces. Use
POST /workspaces/:id/builds with {"transition":"delete"} instead,
which is the correct Coder API for workspace deletion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 15:51:24 +01:00
6 changed files with 48 additions and 7 deletions
+5 -1
View File
@@ -128,6 +128,10 @@ data "coder_parameter" "task_type" {
name = "Rework PR"
value = "rework-pr"
}
option {
name = "Rework Spec"
value = "rework-spec"
}
option {
name = "Release"
value = "release"
@@ -470,7 +474,7 @@ resource "coder_agent" "main" {
git fetch origin develop 2>/dev/null && git checkout develop 2>/dev/null || true
# Lightweight stages only need the code, not a full build
LIGHT_STAGES="analyse architect release maintenance"
LIGHT_STAGES="analyse architect rework-spec release maintenance"
if echo "$LIGHT_STAGES" | grep -qw "$TASK_TYPE"; then
echo "Lightweight stage ($TASK_TYPE) — skipping build"
else
+3 -1
View File
@@ -22,7 +22,9 @@ export function issueLabel(config: Config, queue: TaskQueue) {
return async (c: Context) => {
const event = await c.req.json<IssueEvent>();
if (event.action !== "label_updated" && event.action !== "labeled") {
console.log(`[issue-label] action="${event.action}" issue=#${event.issue.number} labels=[${event.issue.labels.map((l) => l.name).join(", ")}]`);
if (!["labeled", "label_updated", "created"].includes(event.action)) {
return c.text("ignored: not a label event", 200);
}
+28 -2
View File
@@ -16,15 +16,41 @@ export function prRework(config: Config, queue: TaskQueue) {
return c.text("ignored: not a reviewed event", 200);
}
if (!event.review) {
console.log(`[pr-rework] ignored: no review object`);
return c.text("ignored: no review data", 200);
}
const [org, repo] = event.repository.full_name.split("/");
const prNumber = event.pull_request.number;
const reviewState = event.review.state.toLowerCase();
// Gitea webhook payloads use "state" in the API but "type" in webhooks
// state: "REQUEST_CHANGES" | "APPROVED" | "COMMENT"
// type: "pull_request_review_rejected" | "pull_request_review_approved" | ...
let reviewState: string;
if (event.review.state) {
reviewState = event.review.state.toLowerCase();
} else if (event.review.type) {
const typeMap: Record<string, string> = {
pull_request_review_rejected: "request_changes",
pull_request_review_approved: "approved",
pull_request_review_comment: "comment",
};
reviewState = typeMap[event.review.type] || event.review.type;
} else {
console.log(`[pr-rework] ignored: no review state or type (review: ${JSON.stringify(event.review)})`);
return c.text("ignored: no review state", 200);
}
console.log(`[pr-rework] PR #${prNumber} review: ${reviewState}`);
let taskType: string | null = null;
let giteaToken: string;
const branch = event.pull_request.head.ref;
const isArchitectPR = branch.startsWith("docs/");
if (reviewState === "request_changes") {
taskType = "rework-pr";
taskType = isArchitectPR ? "rework-spec" : "rework-pr";
giteaToken = config.giteaDevToken;
} else if (reviewState === "approved") {
taskType = "test";
+6
View File
@@ -161,6 +161,8 @@ export class TaskQueue {
jobId: `create-${key}`,
attempts: 3,
backoff: { type: "exponential", delay: 5000 },
removeOnComplete: true,
removeOnFail: true,
},
);
} catch (err: unknown) {
@@ -201,6 +203,8 @@ export class TaskQueue {
jobId: `cleanup-${workspaceName}`,
attempts: 5,
backoff: { type: "exponential", delay: 10000 },
removeOnComplete: true,
removeOnFail: true,
},
);
@@ -311,6 +315,8 @@ export class TaskQueue {
jobId: `cleanup-stale-${ws.name}-${Date.now()}`,
attempts: 5,
backoff: { type: "exponential", delay: 10000 },
removeOnComplete: true,
removeOnFail: true,
},
);
} catch (err) {
+4 -2
View File
@@ -109,12 +109,14 @@ export class CoderClient {
async deleteWorkspace(workspaceId: string): Promise<void> {
const res = await fetch(
`${this.baseUrl}/api/v2/workspaces/${workspaceId}`,
`${this.baseUrl}/api/v2/workspaces/${workspaceId}/builds`,
{
method: "DELETE",
method: "POST",
headers: {
"Content-Type": "application/json",
"Coder-Session-Token": this.token,
},
body: JSON.stringify({ transition: "delete" }),
},
);
+2 -1
View File
@@ -46,7 +46,8 @@ export interface GiteaPullRequest {
export interface GiteaReview {
id: number;
body: string;
state: string; // "approved", "request_changes", "comment"
state?: string; // "approved", "request_changes", "comment" (API response)
type?: string; // "pull_request_review_rejected" | "pull_request_review_approved" (webhook payload)
user: GiteaUser;
}