diff --git a/Cargo.lock b/Cargo.lock index 9b21a63..2c23273 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -794,6 +794,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", + "itoa", "powerfmt", "serde", "time-core", diff --git a/Cargo.toml b/Cargo.toml index 14f45dd..d64f32a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ thiserror = "1.0.43" tokio = { version = "1.29.1", features = ["net"] } url = { version = "2.4.0", features = ["serde"] } serde = { version = "1.0.168", features = ["derive"] } -time = { version = "0.3.22", features = ["parsing", "serde"] } +time = { version = "0.3.22", features = ["parsing", "serde", "formatting"] } diff --git a/src/issue.rs b/src/issue.rs new file mode 100644 index 0000000..673d0bb --- /dev/null +++ b/src/issue.rs @@ -0,0 +1,257 @@ +use super::*; + +impl Forgejo { + pub async fn get_repo_issues(&self, owner: &str, repo: &str, query: IssueQuery) -> Result, ForgejoError> { + self.get(&query.to_string(owner, repo)).await + } + + pub async fn create_issue(&self, owner: &str, repo: &str, opts: CreateIssueOption) -> Result { + self.post(&format!("repos/{owner}/{repo}/issues"), &opts).await + } + + pub async fn get_issue(&self, owner: &str, repo: &str, id: u64) -> Result, ForgejoError> { + self.get_opt(&format!("repos/{owner}/{repo}/issues/{id}")).await + } + + pub async fn delete_issue(&self, owner: &str, repo: &str, id: u64) -> Result<(), ForgejoError> { + self.delete(&format!("repos/{owner}/{repo}/issues/{id}")).await + } + + pub async fn edit_issue(&self, owner: &str, repo: &str, id: u64, opts: EditIssueOption) -> Result { + self.patch(&format!("repos/{owner}/{repo}/issues/{id}"), &opts).await + } + + + pub async fn get_repo_comments(&self, owner: &str, repo: &str, query: RepoCommentQuery) -> Result, ForgejoError> { + self.get(&query.to_string(owner, repo)).await + } + + pub async fn get_issue_comments(&self, owner: &str, repo: &str, issue_id: u64, query: IssueCommentQuery) -> Result, ForgejoError> { + self.get(&query.to_string(owner, repo, issue_id)).await + } + + pub async fn create_comment(&self, owner: &str, repo: &str, issue_id: u64, opts: CreateIssueCommentOption) -> Result { + self.post(&format!("repos/{owner}/{repo}/issues/{issue_id}/comments"), &opts).await + } + + pub async fn get_comment(&self, owner: &str, repo: &str, id: u64) -> Result, ForgejoError> { + self.get_opt(&format!("repos/{owner}/{repo}/issues/comments/{id}")).await + } + + pub async fn delete_comment(&self, owner: &str, repo: &str, id: u64) -> Result<(), ForgejoError> { + self.delete(&format!("repos/{owner}/{repo}/issues/comments/{id}")).await + } + + pub async fn edit_comment(&self, owner: &str, repo: &str, id: u64, opts: EditIssueCommentOption) -> Result { + self.patch(&format!("repos/{owner}/{repo}/issues/comments/{id}"), &opts).await + } +} + +#[derive(serde::Deserialize, Debug, PartialEq)] +pub struct Issue { + pub assets: Vec, + pub assignee: User, + pub assignees: Vec, + pub body: String, + #[serde(with = "time::serde::rfc3339")] + pub closed_at: time::OffsetDateTime, + pub comments: u64, + #[serde(with = "time::serde::rfc3339")] + pub created_at: time::OffsetDateTime, + #[serde(with = "time::serde::rfc3339")] + pub due_date: time::OffsetDateTime, + pub html_url: Url, + pub id: u64, + pub is_locked: bool, + pub labels: Vec