diff options
| author | soryu <soryu@soryu.co> | 2026-01-29 01:14:17 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-29 01:14:17 +0000 |
| commit | f6a40e2304585f140ed5766b25fe71a6958f4425 (patch) | |
| tree | ef468206f1c0ec1718e74a51115eb1005698c3e3 /makima/src/server/handlers | |
| parent | d7b0b576fb43902535f0ae8d4f257b50387ec01a (diff) | |
| download | soryu-f6a40e2304585f140ed5766b25fe71a6958f4425.tar.gz soryu-f6a40e2304585f140ed5766b25fe71a6958f4425.zip | |
Fix makima supervisor pr CLI command
Diffstat (limited to 'makima/src/server/handlers')
| -rw-r--r-- | makima/src/server/handlers/mesh_supervisor.rs | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs index 016367f..a0a3a96 100644 --- a/makima/src/server/handlers/mesh_supervisor.rs +++ b/makima/src/server/handlers/mesh_supervisor.rs @@ -1267,15 +1267,9 @@ pub struct MergeTaskResponse { #[derive(Debug, Deserialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct CreatePRRequest { - pub task_id: Uuid, + pub branch: String, pub title: String, pub body: Option<String>, - #[serde(default = "default_base_branch")] - pub base_branch: String, -} - -fn default_base_branch() -> String { - "main".to_string() } /// Response for PR creation. @@ -1513,48 +1507,53 @@ pub async fn create_pr( headers: HeaderMap, Json(request): Json<CreatePRRequest>, ) -> impl IntoResponse { - let (_supervisor_id, owner_id) = match verify_supervisor_auth(&state, &headers, None).await { + let (supervisor_id, _owner_id) = match verify_supervisor_auth(&state, &headers, None).await { Ok(ids) => ids, Err(e) => return e.into_response(), }; let pool = state.db_pool.as_ref().unwrap(); - // Get the target task - let task = match repository::get_task_for_owner(pool, request.task_id, owner_id).await { + // Get the supervisor's own task to find daemon and base_branch + let task = match repository::get_task(pool, supervisor_id).await { Ok(Some(t)) => t, Ok(None) => { return ( StatusCode::NOT_FOUND, - Json(ApiError::new("NOT_FOUND", "Task not found")), + Json(ApiError::new("NOT_FOUND", "Supervisor task not found")), ).into_response(); } Err(e) => { - tracing::error!(error = %e, "Failed to get task"); + tracing::error!(error = %e, "Failed to get supervisor task"); return ( StatusCode::INTERNAL_SERVER_ERROR, - Json(ApiError::new("DB_ERROR", "Failed to get task")), + Json(ApiError::new("DB_ERROR", "Failed to get supervisor task")), ).into_response(); } }; - // Get daemon running the task + // Get daemon running the supervisor let Some(daemon_id) = task.daemon_id else { return ( StatusCode::SERVICE_UNAVAILABLE, - Json(ApiError::new("NO_DAEMON", "Task has no assigned daemon")), + Json(ApiError::new("NO_DAEMON", "Supervisor has no assigned daemon")), ).into_response(); }; + // Use base_branch from the task's repository config, falling back to "main" + let base_branch = task.base_branch.unwrap_or_else(|| "main".to_string()); + // Subscribe to PR results BEFORE sending the command let mut rx = state.pr_results.subscribe(); - // Send CreatePR command to daemon + // Send CreatePR command to daemon using the supervisor's task ID + // (the branch is in the supervisor's worktree) let cmd = DaemonCommand::CreatePR { - task_id: request.task_id, + task_id: supervisor_id, title: request.title.clone(), body: request.body.clone(), - base_branch: request.base_branch.clone(), + base_branch, + branch: request.branch.clone(), }; if let Err(e) = state.send_daemon_command(daemon_id, cmd).await { @@ -1571,7 +1570,7 @@ pub async fn create_pr( loop { match rx.recv().await { Ok(notification) => { - if notification.task_id == request.task_id { + if notification.task_id == supervisor_id { return Some(notification); } // Not our task, keep waiting @@ -1594,7 +1593,7 @@ pub async fn create_pr( ( status, Json(CreatePRResponse { - task_id: request.task_id, + task_id: supervisor_id, success: notification.success, message: notification.message, pr_url: notification.pr_url, @@ -1607,7 +1606,7 @@ pub async fn create_pr( ( StatusCode::GATEWAY_TIMEOUT, Json(CreatePRResponse { - task_id: request.task_id, + task_id: supervisor_id, success: false, message: "PR creation timed out waiting for daemon response".to_string(), pr_url: None, |
