1
0
Fork 0

support comment operations

This commit is contained in:
Cyborus 2023-11-13 18:35:44 -05:00
parent 9da230e5ee
commit ffbbfaf898
No known key found for this signature in database

View file

@ -17,9 +17,35 @@ impl Forgejo {
self.delete(&format!("/repos/{owner}/{repo}/issues/{id}")).await
}
pub async fn edit_issue(&self, owner: &str, repo: &str, id: u64, opts: EditIssueOption) -> Result<(), ForgejoError> {
pub async fn edit_issue(&self, owner: &str, repo: &str, id: u64, opts: EditIssueOption) -> Result<Issue, ForgejoError> {
self.patch(&format!("/repos/{owner}/{repo}/issues/{id}"), &opts).await
}
pub async fn get_repo_comments(&self, owner: &str, repo: &str, query: RepoCommentQuery) -> Result<Vec<Comment>, 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<Vec<Comment>, 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<Comment, ForgejoError> {
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<Option<Comment>, 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<Comment, ForgejoError> {
self.patch(&format!("/repos/{owner}/{repo}/issues/comments/{id}"), &opts).await
}
}
#[derive(serde::Deserialize, Debug, PartialEq)]
@ -93,6 +119,23 @@ impl State {
}
}
#[derive(serde::Deserialize, Debug, PartialEq)]
pub struct Comment {
pub assets: Vec<Attachment>,
pub body: String,
#[serde(with = "time::serde::rfc3339")]
pub created_at: time::OffsetDateTime,
pub html_url: Url,
pub id: u64,
pub issue_url: Url,
pub original_author: String,
pub original_author_id: u64,
pub pull_request_url: Url,
#[serde(with = "time::serde::rfc3339")]
pub updated_at: time::OffsetDateTime,
pub user: User,
}
#[derive(Default, Debug)]
pub struct IssueQuery {
pub state: Option<State>,
@ -143,6 +186,40 @@ impl IssueQueryType {
}
}
#[derive(Default, Debug)]
pub struct IssueCommentQuery {
pub since: Option<time::OffsetDateTime>,
pub before: Option<time::OffsetDateTime>,
}
impl IssueCommentQuery {
fn to_string(&self, owner: &str, repo: &str, issue_id: u64) -> String {
format!("/repos/{owner}/{repo}/issues/{issue_id}/comments?since={}&before={}",
self.since.map(|t| t.format(&time::format_description::well_known::Rfc3339).unwrap()).unwrap_or_default(),
self.before.map(|t| t.format(&time::format_description::well_known::Rfc3339).unwrap()).unwrap_or_default(),
)
}
}
#[derive(Default, Debug)]
pub struct RepoCommentQuery {
pub since: Option<time::OffsetDateTime>,
pub before: Option<time::OffsetDateTime>,
pub page: Option<u32>,
pub limit: Option<u32>,
}
impl RepoCommentQuery {
fn to_string(&self, owner: &str, repo: &str) -> String {
format!("/repos/{owner}/{repo}/issues/comments?since={}&before={}&page={}&limit={}",
self.since.map(|t| t.format(&time::format_description::well_known::Rfc3339).unwrap()).unwrap_or_default(),
self.before.map(|t| t.format(&time::format_description::well_known::Rfc3339).unwrap()).unwrap_or_default(),
self.page.map(|page| page.to_string()).unwrap_or_default(),
self.limit.map(|page| page.to_string()).unwrap_or_default(),
)
}
}
#[derive(serde::Serialize, Debug, PartialEq, Default)]
pub struct CreateIssueOption {
pub assignees: Vec<String>,
@ -169,3 +246,13 @@ pub struct EditIssueOption {
pub title: Option<String>,
pub unset_due_date: Option<bool>,
}
#[derive(serde::Serialize, Debug, PartialEq, Default)]
pub struct CreateIssueCommentOption {
body: String,
}
#[derive(serde::Serialize, Debug, PartialEq, Default)]
pub struct EditIssueCommentOption {
body: String,
}