This commit is contained in:
@@ -9,8 +9,8 @@ use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::model::{
|
||||
CreateIssuePayload, EditIssuePayload, Issue, MoveProjectIssuePayload, Project, ProjectBoard,
|
||||
ProjectColumn,
|
||||
Comment, CommentPayload, CreateIssuePayload, EditIssuePayload, Issue, MoveProjectIssuePayload,
|
||||
Project, ProjectBoard, ProjectColumn,
|
||||
};
|
||||
|
||||
pub trait GiteaApi {
|
||||
@@ -30,6 +30,10 @@ pub trait GiteaApi {
|
||||
fn create_issue(&self, payload: &CreateIssuePayload) -> Result<Issue, ApiError>;
|
||||
fn edit_issue(&self, issue_number: u64, payload: &EditIssuePayload) -> Result<Issue, ApiError>;
|
||||
fn delete_issue(&self, issue_number: u64) -> Result<(), ApiError>;
|
||||
fn list_issue_comments(&self, issue_number: u64) -> Result<Vec<Comment>, ApiError>;
|
||||
fn create_issue_comment(&self, issue_number: u64, body: String) -> Result<Comment, ApiError>;
|
||||
fn edit_issue_comment(&self, comment_id: u64, body: String) -> Result<Comment, ApiError>;
|
||||
fn delete_issue_comment(&self, comment_id: u64) -> Result<(), ApiError>;
|
||||
}
|
||||
|
||||
pub struct GiteaClient {
|
||||
@@ -279,6 +283,62 @@ impl GiteaApi for GiteaClient {
|
||||
check_response(response, &format!("deleting issue #{issue_number}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_issue_comments(&self, issue_number: u64) -> Result<Vec<Comment>, ApiError> {
|
||||
self.get_all(
|
||||
&format!("issues/{issue_number}/comments"),
|
||||
&format!("listing comments for issue #{issue_number}"),
|
||||
&[],
|
||||
)
|
||||
}
|
||||
|
||||
fn create_issue_comment(&self, issue_number: u64, body: String) -> Result<Comment, ApiError> {
|
||||
let response = self
|
||||
.client
|
||||
.post(self.endpoint(&format!("issues/{issue_number}/comments"))?)
|
||||
.header("Authorization", format!("token {}", self.token))
|
||||
.json(&CommentPayload { body })
|
||||
.send()
|
||||
.map_err(|error| {
|
||||
ApiError(format!(
|
||||
"cannot reach Gitea while creating comment on issue #{issue_number}: {error}"
|
||||
))
|
||||
})?;
|
||||
self.decode(
|
||||
response,
|
||||
&format!("creating comment on issue #{issue_number}"),
|
||||
)
|
||||
}
|
||||
|
||||
fn edit_issue_comment(&self, comment_id: u64, body: String) -> Result<Comment, ApiError> {
|
||||
let response = self
|
||||
.client
|
||||
.patch(self.endpoint(&format!("issues/comments/{comment_id}"))?)
|
||||
.header("Authorization", format!("token {}", self.token))
|
||||
.json(&CommentPayload { body })
|
||||
.send()
|
||||
.map_err(|error| {
|
||||
ApiError(format!(
|
||||
"cannot reach Gitea while editing comment #{comment_id}: {error}"
|
||||
))
|
||||
})?;
|
||||
self.decode(response, &format!("editing comment #{comment_id}"))
|
||||
}
|
||||
|
||||
fn delete_issue_comment(&self, comment_id: u64) -> Result<(), ApiError> {
|
||||
let response = self
|
||||
.client
|
||||
.delete(self.endpoint(&format!("issues/comments/{comment_id}"))?)
|
||||
.header("Authorization", format!("token {}", self.token))
|
||||
.send()
|
||||
.map_err(|error| {
|
||||
ApiError(format!(
|
||||
"cannot reach Gitea while deleting comment #{comment_id}: {error}"
|
||||
))
|
||||
})?;
|
||||
check_response(response, &format!("deleting comment #{comment_id}"))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn check_response(response: Response, operation: &str) -> Result<Response, ApiError> {
|
||||
|
||||
Reference in New Issue
Block a user