use super::GitLabApi;
use crate::handlers::templates::PercentEncoded;
use crate::network::net::{ApiEndpoint, Net};
use crate::network::ForgeApi;
use crate::network::{error, responses::Branch};
use url::Url;
struct BranchesEndpoint<'a> {
api: &'a GitLabApi,
base_url: Url,
project_id: &'a PercentEncoded,
}
impl ApiEndpoint<GitLabApi, Vec<Branch>> for BranchesEndpoint<'_> {
fn api(&self) -> &GitLabApi {
self.api
}
fn url(&self) -> Url {
self.base_url
.join(&format!(
"projects/{}/repository/branches",
self.project_id.uri_component()
))
.expect("Valid URL path")
}
}
pub fn get_branches(
api: &GitLabApi,
net: &Net,
project_id: &PercentEncoded,
) -> Result<Vec<Branch>, error::Error> {
let base_url = api.base_url().clone();
let endpoint: BranchesEndpoint = BranchesEndpoint {
api,
base_url,
project_id,
};
let branches = net.call(&endpoint)?;
return Ok(branches);
}