use super::pagination::Collection;
use crate::api::client::ApiClient;
use crate::error::Result;
use crate::models::comment::{Comment, CreateComment};
use crate::models::issue::{CreateIssue, Issue, UpdateIssue};
impl ApiClient {
pub async fn list_issues(&self, owner: &str, repo: &str, state: &str) -> Result<Vec<Issue>> {
self.collection(
&format!("/repos/{owner}/{repo}/issues?state={state}"),
Collection::IssuesOrPulls,
)
.await
}
pub async fn get_issue(&self, owner: &str, repo: &str, number: u64) -> Result<Issue> {
self.get(&format!("/repos/{}/{}/issues/{}", owner, repo, number))
.await
}
pub async fn create_issue(&self, owner: &str, repo: &str, body: &CreateIssue) -> Result<Issue> {
self.post(&format!("/repos/{}/{}/issues", owner, repo), body)
.await
}
pub async fn update_issue(
&self,
owner: &str,
repo: &str,
number: u64,
body: &UpdateIssue,
) -> Result<Issue> {
self.patch(
&format!("/repos/{}/{}/issues/{}", owner, repo, number),
body,
)
.await
}
pub async fn list_issue_comments(
&self,
owner: &str,
repo: &str,
number: u64,
) -> Result<Vec<Comment>> {
self.collection(
&format!("/repos/{owner}/{repo}/issues/{number}/comments?per_page=100"),
Collection::Comments,
)
.await
}
pub async fn create_issue_comment(
&self,
owner: &str,
repo: &str,
number: u64,
body: &CreateComment,
) -> Result<Comment> {
self.post(
&format!("/repos/{}/{}/issues/{}/comments", owner, repo, number),
body,
)
.await
}
pub async fn update_issue_comment(
&self,
owner: &str,
repo: &str,
comment_id: u64,
body: &CreateComment,
) -> Result<Comment> {
self.patch(
&format!("/repos/{}/{}/issues/comments/{}", owner, repo, comment_id),
body,
)
.await
}
}