Add default authorization header for gitea api (remove query string)

Add review cost
This commit is contained in:
2026-06-05 18:39:38 +00:00
parent cd5c5b9478
commit 01e13f0081
4 changed files with 53 additions and 38 deletions
+14 -7
View File
@@ -12,15 +12,22 @@ pub struct GiteaAPI {
}
impl GiteaAPI {
pub fn new(base_url: &str, token: &str, timeout: u64) -> Self {
Self {
pub fn new(base_url: &str, token: &str, timeout: u64) -> anyhow::Result<Self> {
let mut default_headers = reqwest::header::HeaderMap::new();
default_headers.insert(
reqwest::header::HeaderName::from_static("authorization"),
reqwest::header::HeaderValue::from_str(&format!("Bearer {}", token))?,
);
Ok(Self {
base_url: String::from(base_url),
client: reqwest::Client::builder()
.timeout(Duration::from_secs(timeout))
.default_headers(default_headers)
.build()
.unwrap(),
token: String::from(token),
}
})
}
pub async fn comment(
@@ -30,8 +37,8 @@ impl GiteaAPI {
index: u64,
) -> anyhow::Result<Comment> {
let url = format!(
"{}/api/v1/repos/{}/issues/{}/comments?access_token={}",
self.base_url, full_name, index, self.token
"{}/api/v1/repos/{}/issues/{}/comments",
self.base_url, full_name, index
);
let res = self
@@ -53,8 +60,8 @@ impl GiteaAPI {
comment_id: u64,
) -> anyhow::Result<()> {
let url = format!(
"{}/api/v1/repos/{}/issues/comments/{}?access_token={}",
self.base_url, full_name, comment_id, self.token
"{}/api/v1/repos/{}/issues/comments/{}",
self.base_url, full_name, comment_id
);
self.client