Add PATCH support in Gitea client and update issue handling
Extend Gitea client with a `patch` method for executing PATCH requests. Introduce `IssueWriteSetBody` struct for serializing issue update payloads. Update Gitea action to append related issues and send PATCH requests to update issue descriptions.
This commit is contained in:
+34
-1
@@ -1,8 +1,9 @@
|
||||
use crate::config::{Config, GiteaConfig};
|
||||
use crate::error::GeneralError;
|
||||
use reqwest::header::{HeaderMap, ACCEPT, AUTHORIZATION};
|
||||
use reqwest::{ClientBuilder, StatusCode};
|
||||
use reqwest::{Body, ClientBuilder, StatusCode};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -79,6 +80,38 @@ impl Client {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn patch<T: DeserializeOwned, B: Serialize>(
|
||||
&self,
|
||||
url: Url,
|
||||
body: &B,
|
||||
) -> Result<T, GeneralError> {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.append(AUTHORIZATION, format!("token {}", self.token).parse()?);
|
||||
headers.append(ACCEPT, "application/json".parse()?);
|
||||
|
||||
let client = ClientBuilder::new()
|
||||
.default_headers(headers)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let response = client.patch(url.clone()).json(body).send().await?;
|
||||
|
||||
match response.status() {
|
||||
StatusCode::OK | StatusCode::CREATED => {
|
||||
let result: T = response.json().await?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
_ => Err(GeneralError {
|
||||
description: format!(
|
||||
"Could not call PATCH on {:?}, error code {}",
|
||||
url,
|
||||
response.status()
|
||||
),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user