@@ -9,6 +9,7 @@ use crate::{bot::ReviewResult, errors::AppError};
|
||||
#[derive(Clone)]
|
||||
pub struct GiteaAPI {
|
||||
base_url: String,
|
||||
token: String,
|
||||
client: reqwest::Client,
|
||||
}
|
||||
|
||||
@@ -22,6 +23,7 @@ impl GiteaAPI {
|
||||
|
||||
Ok(Self {
|
||||
base_url: String::from(base_url),
|
||||
token: String::from(token),
|
||||
client: reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(timeout))
|
||||
.default_headers(default_headers)
|
||||
@@ -29,6 +31,20 @@ impl GiteaAPI {
|
||||
})
|
||||
}
|
||||
|
||||
/// API token used to authenticate against Gitea.
|
||||
pub fn token(&self) -> &str {
|
||||
&self.token
|
||||
}
|
||||
|
||||
/// HTTPS clone URL for a repository, suitable for `git clone`.
|
||||
pub fn repo_clone_url(&self, full_name: &str) -> String {
|
||||
format!(
|
||||
"{}/{}.git",
|
||||
self.base_url.trim_end_matches('/'),
|
||||
full_name.trim_start_matches('/')
|
||||
)
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
pub async fn get_authorized_user(&self) -> anyhow::Result<User> {
|
||||
let url = format!("{}/api/v1/user", self.base_url);
|
||||
|
||||
Reference in New Issue
Block a user