summaryrefslogtreecommitdiff
path: root/makima/src/server/handlers/directives.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server/handlers/directives.rs')
-rw-r--r--makima/src/server/handlers/directives.rs54
1 files changed, 45 insertions, 9 deletions
diff --git a/makima/src/server/handlers/directives.rs b/makima/src/server/handlers/directives.rs
index 6d99179..35a46a0 100644
--- a/makima/src/server/handlers/directives.rs
+++ b/makima/src/server/handlers/directives.rs
@@ -232,15 +232,51 @@ pub async fn update_directive(
);
}
- // Transition the contract to 'inactive' now that its
- // iteration is "shipped" — editing the goal again starts
- // an amendment cycle, surfaced via the New draft action.
- if let Err(e) = repository::set_directive_inactive(pool, directive.id).await {
- tracing::warn!(
- directive_id = %directive.id,
- error = %e,
- "Failed to mark directive inactive after PR creation"
- );
+ // Auto-complete the active contract — flips its status
+ // to `shipped`, records pr_url/pr_branch, and (via the
+ // contract↔directive sync in repository) transitions
+ // the directive itself to `inactive`. This removes the
+ // need for a manual "Mark complete" click; the PR
+ // raise IS the completion signal.
+ match repository::get_active_contract_id_for_directive(pool, directive.id).await {
+ Ok(Some(contract_id)) => {
+ if let Err(e) = repository::complete_contract(
+ pool,
+ contract_id,
+ Some(new_pr_url.as_str()),
+ directive.pr_branch.as_deref(),
+ )
+ .await
+ {
+ tracing::warn!(
+ directive_id = %directive.id,
+ contract_id = %contract_id,
+ error = %e,
+ "Failed to auto-complete contract after PR creation — \
+ directive status not synced; user may need to manually ship"
+ );
+ }
+ }
+ Ok(None) => {
+ // No active contract — fall back to the old
+ // behaviour (mark directive inactive). This is
+ // the legacy path for directives without
+ // contracts attached yet.
+ if let Err(e) = repository::set_directive_inactive(pool, directive.id).await {
+ tracing::warn!(
+ directive_id = %directive.id,
+ error = %e,
+ "Failed to mark directive inactive after PR creation"
+ );
+ }
+ }
+ Err(e) => {
+ tracing::warn!(
+ directive_id = %directive.id,
+ error = %e,
+ "Failed to resolve active contract for auto-complete"
+ );
+ }
}
}
}