1
0
Fork 0

support getting, deleting, and patching issues

This commit is contained in:
Cyborus 2023-11-13 17:20:29 -05:00
parent 8e45141822
commit 5d76734498
No known key found for this signature in database
2 changed files with 43 additions and 1 deletions

View file

@ -8,6 +8,18 @@ impl Forgejo {
pub async fn create_issue(&mut self, owner: &str, repo: &str, opts: CreateIssueOption) -> Result<Issue, ForgejoError> { pub async fn create_issue(&mut self, owner: &str, repo: &str, opts: CreateIssueOption) -> Result<Issue, ForgejoError> {
self.post(&format!("/repos/{owner}/{repo}/issues"), &opts).await self.post(&format!("/repos/{owner}/{repo}/issues"), &opts).await
} }
pub async fn get_issue(&mut self, owner: &str, repo: &str, id: u64) -> Result<Option<Issue>, ForgejoError> {
self.get_opt(&format!("/repos/{owner}/{repo}/issues/{id}")).await
}
pub async fn delete_issue(&mut self, owner: &str, repo: &str, id: u64) -> Result<(), ForgejoError> {
self.delete(&format!("/repos/{owner}/{repo}/issues/{id}")).await
}
pub async fn edit_issue(&mut self, owner: &str, repo: &str, id: u64, opts: EditIssueOption) -> Result<(), ForgejoError> {
self.patch(&format!("/repos/{owner}/{repo}/issues/{id}"), &opts).await
}
} }
#[derive(serde::Deserialize, Debug, PartialEq)] #[derive(serde::Deserialize, Debug, PartialEq)]
@ -66,7 +78,7 @@ pub struct Attachment {
pub uuid: String, pub uuid: String,
} }
#[derive(serde::Deserialize, Debug, PartialEq, Clone, Copy)] #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Copy)]
pub enum State { pub enum State {
Open, Open,
Closed, Closed,
@ -143,3 +155,17 @@ pub struct CreateIssueOption {
pub _ref: Option<String>, pub _ref: Option<String>,
pub title: String, pub title: String,
} }
#[derive(serde::Serialize, Debug, PartialEq, Default)]
pub struct EditIssueOption {
pub assignees: Vec<String>,
pub body: Option<String>,
#[serde(with = "time::serde::rfc3339::option")]
pub due_date: Option<time::OffsetDateTime>,
pub labels: Vec<u64>,
pub milestone: Option<u64>,
pub _ref: Option<String>,
pub state: Option<State>,
pub title: Option<String>,
pub unset_due_date: Option<bool>,
}

View file

@ -95,6 +95,22 @@ impl Forgejo {
self.execute(request).await self.execute(request).await
} }
async fn delete(&self, path: &str) -> Result<(), ForgejoError> {
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
let request = self.client.delete(url).build()?;
self.execute(request).await
}
async fn patch<T: Serialize, U: DeserializeOwned>(
&self,
path: &str,
body: &T,
) -> Result<U, ForgejoError> {
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
let request = self.client.patch(url).json(body).build()?;
self.execute(request).await
}
async fn execute<T: DeserializeOwned>(&self, request: Request) -> Result<T, ForgejoError> { async fn execute<T: DeserializeOwned>(&self, request: Request) -> Result<T, ForgejoError> {
let response = self.client.execute(dbg!(request)).await?; let response = self.client.execute(dbg!(request)).await?;
match response.status() { match response.status() {