checking if a pr exists does not return a body
This commit is contained in:
parent
e732034aea
commit
5da7e69f82
23
src/lib.rs
23
src/lib.rs
|
@ -88,6 +88,12 @@ impl Forgejo {
|
|||
self.execute_str(request).await
|
||||
}
|
||||
|
||||
async fn get_exists(&self, path: &str) -> Result<bool, ForgejoError> {
|
||||
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
|
||||
let request = self.client.get(url).build()?;
|
||||
self.execute_exists(request).await
|
||||
}
|
||||
|
||||
async fn post<T: Serialize, U: DeserializeOwned>(
|
||||
&self,
|
||||
path: &str,
|
||||
|
@ -222,6 +228,23 @@ impl Forgejo {
|
|||
status => Err(ForgejoError::UnexpectedStatusCode(status)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Like `execute`, but returns `false` on 404.
|
||||
async fn execute_exists(
|
||||
&self,
|
||||
request: Request,
|
||||
) -> Result<bool, ForgejoError> {
|
||||
let response = self.client.execute(request).await?;
|
||||
match response.status() {
|
||||
status if status.is_success() => Ok(true),
|
||||
StatusCode::NOT_FOUND => Ok(false),
|
||||
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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
|
|
|
@ -32,9 +32,7 @@ impl Forgejo {
|
|||
}
|
||||
|
||||
pub async fn is_merged(&self, owner: &str, repo: &str, pr: u64) -> Result<bool, ForgejoError> {
|
||||
self.get_opt::<()>(&format!("repos/{owner}/{repo}/pulls/{pr}/merge"))
|
||||
.await
|
||||
.map(|o| o.is_some())
|
||||
self.get_exists(&format!("repos/{owner}/{repo}/pulls/{pr}/merge")).await
|
||||
}
|
||||
|
||||
pub async fn merge_pr(
|
||||
|
|
Loading…
Reference in a new issue