From 5d76734498225c396ac7664f13b2c3039af1f037 Mon Sep 17 00:00:00 2001 From: Cyborus <87248184+Cyborus04@users.noreply.github.com> Date: Mon, 13 Nov 2023 17:20:29 -0500 Subject: [PATCH] support getting, deleting, and patching issues --- src/issue.rs | 28 +++++++++++++++++++++++++++- src/lib.rs | 16 ++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/issue.rs b/src/issue.rs index e284794..b930216 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -8,6 +8,18 @@ impl Forgejo { pub async fn create_issue(&mut self, owner: &str, repo: &str, opts: CreateIssueOption) -> Result { self.post(&format!("/repos/{owner}/{repo}/issues"), &opts).await } + + pub async fn get_issue(&mut self, owner: &str, repo: &str, id: u64) -> Result, 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)] @@ -66,7 +78,7 @@ pub struct Attachment { pub uuid: String, } -#[derive(serde::Deserialize, Debug, PartialEq, Clone, Copy)] +#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Copy)] pub enum State { Open, Closed, @@ -143,3 +155,17 @@ pub struct CreateIssueOption { pub _ref: Option, pub title: String, } + +#[derive(serde::Serialize, Debug, PartialEq, Default)] +pub struct EditIssueOption { + pub assignees: Vec, + pub body: Option, + #[serde(with = "time::serde::rfc3339::option")] + pub due_date: Option, + pub labels: Vec, + pub milestone: Option, + pub _ref: Option, + pub state: Option, + pub title: Option, + pub unset_due_date: Option, +} diff --git a/src/lib.rs b/src/lib.rs index 5cce27e..de92123 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,6 +95,22 @@ impl Forgejo { 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( + &self, + path: &str, + body: &T, + ) -> Result { + 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(&self, request: Request) -> Result { let response = self.client.execute(dbg!(request)).await?; match response.status() {