git-gemini-forge 0.6.2

A simple Gemini server that serves a read-only view of public repositories from a Git forge.
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;

/// See https://docs.gitlab.com/ee/api/branches.html
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")
	}
}

/// Retrieves branches for the given repository from the given API.
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);
}