gitbucket-cli 0.8.0

A command-line tool for GitBucket, inspired by GitHub CLI
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 {
    /// List issues for a repository
    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
    }

    /// Get a single issue
    pub async fn get_issue(&self, owner: &str, repo: &str, number: u64) -> Result<Issue> {
        self.get(&format!("/repos/{}/{}/issues/{}", owner, repo, number))
            .await
    }

    /// Create an issue
    pub async fn create_issue(&self, owner: &str, repo: &str, body: &CreateIssue) -> Result<Issue> {
        self.post(&format!("/repos/{}/{}/issues", owner, repo), body)
            .await
    }

    /// Update an issue (close, reopen, edit)
    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
    }

    /// List comments on an issue
    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
    }

    /// Add a comment to an issue
    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
    }

    /// Update an issue comment
    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
    }
}