first comment ! :D
This commit is contained in:
+40
-5
@@ -1,24 +1,58 @@
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::errors::AppError;
|
||||
|
||||
pub struct GiteaAPI {
|
||||
base_url: String,
|
||||
token: String,
|
||||
}
|
||||
|
||||
impl GiteaAPI {
|
||||
pub fn new(base_url: &str) -> Self {
|
||||
pub fn new(base_url: &str, token: &str) -> Self {
|
||||
Self {
|
||||
base_url: String::from(base_url),
|
||||
token: String::from(token),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn comment(&self, full_name: &str, index: u64) -> anyhow::Result<u64> {
|
||||
Ok(1)
|
||||
pub async fn comment(&self, full_name: &str, index: u64) -> anyhow::Result<Comment> {
|
||||
let url = format!(
|
||||
"{}/api/v1/repos/{}/issues/{}/comments?access_token={}",
|
||||
self.base_url, full_name, index, self.token
|
||||
);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let res = client
|
||||
.post(url)
|
||||
.json(&json!({
|
||||
"body": "Hello world :)"
|
||||
}))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
println!("{}", res.status());
|
||||
|
||||
res.json::<Comment>().await.map_err(anyhow::Error::from)
|
||||
}
|
||||
|
||||
pub async fn edit_comment(&self, full_name: &str, id: u64) -> anyhow::Result<()> {
|
||||
pub async fn edit_comment(&self, full_name: &str, comment_id: u64) -> anyhow::Result<()> {
|
||||
let url = format!(
|
||||
"{}/api/v1/repos/{}/issues/comments/{}?access_token={}",
|
||||
self.base_url, full_name, comment_id, self.token
|
||||
);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let res = client
|
||||
.patch(url)
|
||||
.json(&json!({
|
||||
"body": "Updated Hello world :)"
|
||||
}))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
println!("{}", res.status());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -40,6 +74,7 @@ pub struct ReviewPayload {
|
||||
pub struct PullRequest {
|
||||
pub id: u64,
|
||||
pub diff_url: String,
|
||||
pub number: u64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user