diff --git a/crates/config/src/webhook/message.rs b/crates/config/src/webhook/message.rs index da4d7cc3..26006461 100644 --- a/crates/config/src/webhook/message.rs +++ b/crates/config/src/webhook/message.rs @@ -23,10 +23,6 @@ impl WebhookMessage { pub const fn body(&self) -> &Body { &self.body } - #[deprecated] - pub const fn authorisation(&self) -> &config::WebhookAuth { - todo!() - } pub fn header(&self, header: &str) -> Option { self.headers.get(header).map(|value| value.to_string()) } diff --git a/crates/forge-forgejo/src/lib.rs b/crates/forge-forgejo/src/lib.rs index c59f57c6..9fa6a3e7 100644 --- a/crates/forge-forgejo/src/lib.rs +++ b/crates/forge-forgejo/src/lib.rs @@ -70,21 +70,20 @@ impl git::ForgeLike for ForgeJo { ); let result = self.net.get::(request).await; match result { - Ok(response) => { - match response.response_body() { - Some(status) => match status.state { - ForgejoState::Success => Status::Pass, - ForgejoState::Pending => Status::Pending, - ForgejoState::Failure => Status::Fail, - ForgejoState::Error => Status::Fail, - ForgejoState::Blank => Status::Pending, - }, - None => { - warn!("No status found for commit"); - Status::Pending // assume issue is transient and allow retry - } + Ok(response) => match response.response_body() { + Some(status) => match status.state { + ForgejoState::Success => Status::Pass, + ForgejoState::Pending => Status::Pending, + ForgejoState::Failure => Status::Fail, + ForgejoState::Error => Status::Fail, + ForgejoState::Blank => Status::Pending, + }, + None => { + #[cfg(not(tarpaulin_include))] + unreachable!(); // response.response_body() is always Some when + // request responseType::Json } - } + }, Err(e) => { warn!(?e, "Failed to get commit status"); Status::Pending // assume issue is transient and allow retry diff --git a/crates/forge-forgejo/src/tests.rs b/crates/forge-forgejo/src/tests.rs index 014a0c90..881e0bf6 100644 --- a/crates/forge-forgejo/src/tests.rs +++ b/crates/forge-forgejo/src/tests.rs @@ -276,6 +276,33 @@ mod forgejo { let_assert!(Ok(_) = forge.unregister_webhook(&webhook_id).await); } + + #[tokio::test] + async fn should_return_error_on_network_error() { + let repo_details = given::repo_details(); + let hostname = repo_details.forge.hostname(); + let repo_path = &repo_details.repo_path; + use secrecy::ExposeSecret; + let token = repo_details.forge.token().expose_secret(); + let webhook_id = given::a_webhook_id(); + let mut net = given::a_network(); + + net.add_delete_error( + format!( + "https://{hostname}/api/v1/repos/{repo_path}/hooks/{webhook_id}?token={token}" + ) + .as_str(), + "error", + ); + + let forge = given::a_forgejo_forge(&repo_details, net); + + let_assert!(Err(err) = forge.unregister_webhook(&webhook_id).await); + assert!( + matches!(err, git::forge::webhook::Error::FailedToUnregister(_)), + "{err:?}" + ); + } } mod register_webhook { diff --git a/crates/forge-forgejo/src/webhook/unregister.rs b/crates/forge-forgejo/src/webhook/unregister.rs index ea92bec9..d174c31c 100644 --- a/crates/forge-forgejo/src/webhook/unregister.rs +++ b/crates/forge-forgejo/src/webhook/unregister.rs @@ -28,7 +28,9 @@ pub async fn unregister( let result = net.delete(request).await; if let Err(e) = result { tracing::warn!("Failed to unregister webhook"); - return Err(git::forge::webhook::Error::FailedToRegister(e.to_string())); + return Err(git::forge::webhook::Error::FailedToUnregister( + e.to_string(), + )); } Ok(()) } diff --git a/crates/git/src/forge/webhook.rs b/crates/git/src/forge/webhook.rs index 5ea15219..26d3472a 100644 --- a/crates/git/src/forge/webhook.rs +++ b/crates/git/src/forge/webhook.rs @@ -9,6 +9,9 @@ pub enum Error { #[error("failed to register: {0}")] FailedToRegister(String), + #[error("failed to unregister: {0}")] + FailedToUnregister(String), + #[error("network response was empty")] NetworkResponseEmpty,