1
0
Fork 0

merging a pr does not return a body

This commit is contained in:
Cyborus 2023-12-11 00:17:54 -05:00
parent bc9dbc6348
commit e732034aea
No known key found for this signature in database
2 changed files with 24 additions and 1 deletions

View file

@ -118,6 +118,16 @@ impl Forgejo {
self.execute_str(request).await
}
async fn post_unit<T: Serialize>(
&self,
path: &str,
body: &T,
) -> Result<(), ForgejoError> {
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
let request = self.client.post(url).json(body).build()?;
self.execute_unit(request).await
}
async fn post_raw(
&self,
path: &str,
@ -179,6 +189,19 @@ impl Forgejo {
}
}
/// Like `execute`, but returns unit.
async fn execute_unit(&self, request: Request) -> Result<(), ForgejoError> {
let response = self.client.execute(request).await?;
match response.status() {
status if status.is_success() => Ok(()),
status if status.is_client_error() => Err(ForgejoError::ApiError(
status,
response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")),
)),
status => Err(ForgejoError::UnexpectedStatusCode(status)),
}
}
/// Like `execute`, but returns `Ok(None)` on 404.
async fn execute_opt<T: DeserializeOwned>(
&self,

View file

@ -44,7 +44,7 @@ impl Forgejo {
pr: u64,
opts: MergePullRequestOption,
) -> Result<(), ForgejoError> {
self.post(&format!("repos/{owner}/{repo}/pulls/{pr}/merge"), &opts)
self.post_unit(&format!("repos/{owner}/{repo}/pulls/{pr}/merge"), &opts)
.await
}