Watch
0
0
Fork
You've already forked hyperhive
0

an agent gets one todo when its pr starts conflicting with the target branch

This commit is contained in:
atlas 2026-11-11 04:36:28 +01:00 • committed by mara
commit 11eb7dac9c

View file

@ -10,6 +10,9 @@
//! `pull_request_sync`, …), not `X-Forgejo-Event`, which folds those into
//! `issues` and `pull_request`. It reaches the subject only once it is one
//! plain token.
//!
//! [`publish_event`] keeps an event this daemon makes, such as the
//! `pull_request_mergeability` event of `crate::pr_conflicts`, the same way.
use axum::http::HeaderMap;
use std::time::Duration;
@ -51,15 +54,42 @@ pub(crate) async fn publish(
body: axum::body::Bytes,
) -> Result<(), NotKept> {
let subject = subject(headers)?;
let mut message = async_nats::jetstream::message::PublishMessage::build().payload(body);
if let Some(id) = headers.get(DELIVERY_HEADER).and_then(|v| v.to_str().ok()) {
message = message.message_id(id);
}
keep(state, subject, message).await
}
/// Keep an event this daemon makes itself, of `event_type`, in the stream, and
/// wait for the stream's ack. The router reads it like a delivery.
pub(crate) async fn publish_event(
state: &crate::routes::AppState,
event_type: &str,
body: Vec<u8>,
) -> Result<(), NotKept> {
if !swarm_wire::forge_events::is_subject_token(event_type) {
return Err(NotKept::BadEventType);
}
let message = async_nats::jetstream::message::PublishMessage::build().payload(body.into());
keep(
state,
swarm_wire::forge_events::subject(event_type),
message,
)
.await
}
async fn keep(
state: &crate::routes::AppState,
subject: String,
message: async_nats::jetstream::message::PublishMessage,
) -> Result<(), NotKept> {
let Some(status) = state.status.as_ref() else {
return Err(NotKept::Queue("no swarm queue is configured".to_owned()));
};
let client = status.queue_client();
swarm_queue_client::ensure_connected(&client).map_err(|e| NotKept::Queue(e.to_string()))?;
let mut message = async_nats::jetstream::message::PublishMessage::build().payload(body);
if let Some(id) = headers.get(DELIVERY_HEADER).and_then(|v| v.to_str().ok()) {
message = message.message_id(id);
}
let kept = async {
swarm_queue_client::forge_events::open_or_create(&client)
.await