Watch
0
0
Fork
You've already forked hyperhive
0

add shared forge-client crate; hive-forge and hive-forge-notify use it

This commit is contained in:
atlas 2026-11-15 19:49:02 +01:00 • committed by mara
commit e59e41ec90

View file

@ -9,8 +9,9 @@
use std::time::Duration;
use forge_client::{StaticToken, TimeoutPolicy};
use forgejo_api::structs::{NotifyGetListQuery, NotifyReadThreadQuery};
use forgejo_api::{Auth, Forgejo, ForgejoError};
use forgejo_api::{Forgejo, ForgejoError};
use hive_forge_notify::notify::{HTTP_TIMEOUT_SECS, UNREAD_FETCH_LIMIT};
use hive_forge_notify::source::Source;
use tracing::{debug, warn};
@ -22,6 +23,7 @@ pub struct ForgejoSource {
/// out over plain `reqwest`.
pub base_url: String,
pub token: String,
timeouts: TimeoutPolicy,
}
impl ForgejoSource {
@ -36,11 +38,12 @@ impl ForgejoSource {
return None;
}
};
match Forgejo::new(Auth::Token(token), parsed) {
match forge_client::async_client(parsed, &StaticToken::new(token)) {
Ok(forge) => Some(Self {
forge: Box::new(forge),
base_url: base_url.to_owned(),
token: token.to_owned(),
timeouts: TimeoutPolicy::json_only(Duration::from_secs(HTTP_TIMEOUT_SECS)),
}),
Err(e) => {
warn!("forge_notify: failed to build forge client: {e}");
@ -93,9 +96,7 @@ impl Source for ForgejoSource {
.notify_get_list(query)
.page_size(u32::try_from(UNREAD_FETCH_LIMIT).unwrap_or(u32::MAX))
.response_type::<String>();
let raw = match tokio::time::timeout(Duration::from_secs(HTTP_TIMEOUT_SECS), request.send())
.await
{
let raw = match self.timeouts.bound_json(request.send()).await {
Ok(Ok(raw)) => raw,
Ok(Err(ForgejoError::UnexpectedStatusCode(status))) => {
debug!("forge_notify: poll status {status}");
@ -135,7 +136,7 @@ impl Source for ForgejoSource {
.forge
.notify_read_thread(thread_id, NotifyReadThreadQuery { to_status: None })
.response_type::<String>();
match tokio::time::timeout(Duration::from_secs(HTTP_TIMEOUT_SECS), request.send()).await {
match self.timeouts.bound_json(request.send()).await {
Err(_) => {
warn!(%id, "forge_notify: mark-read request failed — notification will resurface");
}