Skip to content

Commit 05dac0e

Browse files
committed
More progress
1 parent 2f50f22 commit 05dac0e

File tree

5 files changed

+39
-41
lines changed

5 files changed

+39
-41
lines changed

apps/cloud-agents/scripts/enqueue-test-job.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ if [ -z "$ISSUE_NUMBER" ]; then
99
echo "Usage: $0 <issue_number> [repo]"
1010
echo ""
1111
echo "Examples:"
12-
echo " $0 4567 # Fetch issue #4567 from RooCodeInc/Roo-Code"
13-
echo " $0 123 owner/repo # Fetch issue #123 from owner/repo"
12+
echo " $0 4567 # Fetch issue #4567 from RooCodeInc/Roo-Code"
13+
echo " $0 123 owner/repo # Fetch issue #123 from owner/repo"
1414
echo ""
1515
echo "This script fetches real GitHub issue data and enqueues it as a job."
1616
exit 1
@@ -54,11 +54,6 @@ LABELS=$(echo "$ISSUE_DATA" | jq -r '[.labels[].name] | @json')
5454
TITLE_ESCAPED=$(printf '%s' "$TITLE" | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
5555
BODY_ESCAPED=$(printf '%s' "$BODY" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' | sed 's/\\n$//')
5656

57-
echo "Issue Title: $TITLE"
58-
echo "Issue Labels: $LABELS"
59-
echo ""
60-
echo "Enqueueing job..."
61-
6257
JSON_PAYLOAD=$(cat <<EOF
6358
{
6459
"type": "github.issue.fix",
@@ -73,7 +68,4 @@ JSON_PAYLOAD=$(cat <<EOF
7368
EOF
7469
)
7570

76-
curl -X POST "$JOBS_ENDPOINT" \
77-
-H "Content-Type: application/json" \
78-
-d "$JSON_PAYLOAD" \
79-
-w "\nStatus: %{http_code}\n\n"
71+
curl -X POST "$JOBS_ENDPOINT" -H "Content-Type: application/json" -d "$JSON_PAYLOAD" -w "\nStatus: %{http_code}\n\n"

apps/cloud-agents/src/app/api/jobs/route.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,34 @@ export async function POST(request: NextRequest) {
99
try {
1010
const body = await request.json()
1111
const values = createJobSchema.parse(body)
12+
1213
const [job] = await db
1314
.insert(cloudJobs)
1415
.values({ ...values, status: "pending" })
1516
.returning()
1617

1718
if (!job) {
18-
throw new Error("Failed to create job")
19+
throw new Error("Failed to create `cloudJobs` record.")
1920
}
2021

22+
let enqueuedJob
23+
2124
switch (values.type) {
2225
case "github.issue.fix":
23-
await enqueue({ jobId: job.id, type: "github.issue.fix", payload: values.payload })
26+
enqueuedJob = await enqueue({ jobId: job.id, ...values })
2427
break
2528
default:
2629
throw new Error(`Unknown job type: ${values.type}`)
2730
}
2831

29-
return NextResponse.json(job)
32+
return NextResponse.json({ message: "job_enqueued", jobId: job.id, enqueuedJobId: enqueuedJob.id })
3033
} catch (error) {
31-
console.error("Error creating job:", error)
34+
console.error("Create Job Error:", error)
3235

3336
if (error instanceof z.ZodError) {
34-
return NextResponse.json({ error: "Invalid request body", details: error.errors }, { status: 400 })
37+
return NextResponse.json({ error: "bad_request", details: error.errors }, { status: 400 })
3538
}
3639

37-
return NextResponse.json({ error: "Internal server error" }, { status: 500 })
40+
return NextResponse.json({ error: "internal_server_error" }, { status: 500 })
3841
}
3942
}

apps/cloud-agents/src/app/api/webhooks/github/route.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server"
22
import { createHmac } from "crypto"
33
import { z } from "zod"
44

5-
import { type JobType, type JobStatus, type JobPayload, githubWebhookSchema } from "@/types"
5+
import { type JobType, type JobPayload, githubWebhookSchema } from "@/types"
66
import { db, cloudJobs } from "@/db"
77
import { enqueue } from "@/lib"
88

@@ -15,59 +15,58 @@ function verifySignature(body: string, signature: string, secret: string): boole
1515
export async function POST(request: NextRequest) {
1616
try {
1717
const signature = request.headers.get("x-hub-signature-256")
18-
const event = request.headers.get("x-github-event")
1918

2019
if (!signature) {
21-
return NextResponse.json({ error: "Missing signature" }, { status: 400 })
20+
return NextResponse.json({ error: "missing_signature" }, { status: 400 })
2221
}
2322

2423
const body = await request.text()
2524

2625
if (!verifySignature(body, signature, process.env.GITHUB_WEBHOOK_SECRET!)) {
27-
return NextResponse.json({ error: "Invalid signature" }, { status: 401 })
26+
return NextResponse.json({ error: "invalid_signature" }, { status: 401 })
2827
}
2928

30-
console.log("✅ Signature verified")
31-
console.log("📋 Event ->", event)
29+
const event = request.headers.get("x-github-event")
3230

3331
if (event !== "issues") {
3432
return NextResponse.json({ message: "event_ignored" })
3533
}
3634

3735
const data = githubWebhookSchema.parse(JSON.parse(body))
36+
console.log("🗄️ Webhook ->", data)
37+
const { action, repository, issue } = data
3838

39-
console.log("🗄️ Data ->", data)
40-
41-
if (data.action !== "opened") {
39+
if (action !== "opened") {
4240
return NextResponse.json({ message: "action_ignored" })
4341
}
4442

4543
const type: JobType = "github.issue.fix"
46-
const status: JobStatus = "pending"
4744

4845
const payload: JobPayload<typeof type> = {
49-
repo: data.repository.full_name,
50-
issue: data.issue.number,
51-
title: data.issue.title,
52-
body: data.issue.body || "",
53-
labels: data.issue.labels.map((label) => label.name),
46+
repo: repository.full_name,
47+
issue: issue.number,
48+
title: issue.title,
49+
body: issue.body || "",
50+
labels: issue.labels.map(({ name }) => name),
5451
}
5552

56-
const [job] = await db.insert(cloudJobs).values({ type, status, payload }).returning()
53+
const [job] = await db.insert(cloudJobs).values({ type, payload, status: "pending" }).returning()
5754

5855
if (!job) {
59-
throw new Error("Failed to create job")
56+
throw new Error("Failed to create `cloudJobs` record.")
6057
}
6158

62-
await enqueue({ jobId: job.id, type, payload })
63-
return NextResponse.json({ message: "Job created successfully", jobId: job.id })
59+
const enqueuedJob = await enqueue({ jobId: job.id, type, payload })
60+
console.log("🔗 Enqueued job ->", enqueuedJob)
61+
62+
return NextResponse.json({ message: "job_enqueued", jobId: job.id, enqueuedJobId: enqueuedJob.id })
6463
} catch (error) {
65-
console.error("GitHub webhook error:", error)
64+
console.error("GitHub Webhook Error:", error)
6665

6766
if (error instanceof z.ZodError) {
68-
return NextResponse.json({ error: "Invalid webhook payload", details: error.errors }, { status: 400 })
67+
return NextResponse.json({ error: "bad_request", details: error.errors }, { status: 400 })
6968
}
7069

71-
return NextResponse.json({ error: "Internal server error" }, { status: 500 })
70+
return NextResponse.json({ error: "internal_server_error" }, { status: 500 })
7271
}
7372
}

apps/cloud-agents/src/lib/jobs/fixGitHubIssue.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ ${payload.body}
2626
${payload.labels && payload.labels.length > 0 ? `Labels: ${payload.labels.join(", ")}` : ""}
2727
2828
Please analyze the issue, understand what needs to be fixed, and implement a solution.
29+
If you're reasonably satisfied with the solution then create and submit a pull request using the "gh" command line tool.
30+
You'll first need to create a new branch for the pull request.
31+
32+
Make sure to reference the issue in the pull request description.
2933
`.trim()
3034

3135
const result = await runTask({

apps/cloud-agents/src/lib/runTask.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { type TaskEvent, TaskCommandName, RooCodeEventName, IpcMessageType, EVAL
99
import { IpcClient } from "@roo-code/ipc"
1010

1111
import { Logger } from "./logger"
12-
import { isDockerContainer, findGitRoot } from "./utils"
12+
import { isDockerContainer } from "./utils"
1313

1414
const TIMEOUT = 30 * 60 * 1_000
1515

@@ -27,7 +27,7 @@ type RunTaskOptions = {
2727
}
2828

2929
export const runTask = async ({ prompt, publish, logger }: RunTaskOptions) => {
30-
const workspacePath = findGitRoot(process.cwd())
30+
const workspacePath = "/Users/cte/Documents/Roomote-Control" // findGitRoot(process.cwd())
3131
const ipcSocketPath = path.resolve(os.tmpdir(), `${crypto.randomUUID().slice(0, 8)}.sock`)
3232
const env = { ROO_CODE_IPC_SOCKET_PATH: ipcSocketPath }
3333
const controller = new AbortController()

0 commit comments

Comments
 (0)