git-gemini-forge 0.6.6

A simple Gemini server that serves a read-only view of public repositories from a Git forge.
use super::ForgejoApi;
use crate::handlers::templates::PercentEncoded;
use crate::network::ForgeApi;
use crate::network::net::{ApiEndpoint, Net};
use crate::network::{error, responses::Branch};
use url::Url;

struct BranchesEndpoint<'a> {
	api: &'a ForgejoApi,
	base_url: Url,
	username: &'a PercentEncoded,
	repo_name: &'a PercentEncoded,
}

impl ApiEndpoint<ForgejoApi, Vec<Branch>> for BranchesEndpoint<'_> {
	fn api(&self) -> &ForgejoApi {
		self.api
	}

	fn url(&self) -> Url {
		self.base_url
			.join(&format!(
				"repos/{}/{}/branches",
				self.username.uri_component(),
				self.repo_name.uri_component()
			))
			.expect("Valid URL path")
	}
}

/// Retrieves branches for the given repository from the given API.
pub async fn get_branches(
	api: &ForgejoApi,
	net: &Net,
	username: &PercentEncoded,
	repo_name: &PercentEncoded,
) -> Result<Vec<Branch>, error::Error> {
	let base_url = api.base_url().clone();
	let endpoint = BranchesEndpoint {
		api,
		base_url,
		username,
		repo_name,
	};

	net.call(&endpoint).await
}