git-gemini-forge 0.5.2

A simple Gemini server that serves a read-only view of public repositories from a Git forge.
use super::GitLabApi;
use crate::network::get::{call, ApiEndpoint};
use crate::network::ForgeApi;
use crate::network::{error, responses::Branch};
use url::Url;

/// See https://docs.gitlab.com/ee/api/branches.html
struct BranchesEndpoint {
	base_url: Url,
	project_id: String,
}

impl ApiEndpoint<Vec<Branch>> for BranchesEndpoint {
	fn url(&self) -> Url {
		let project_id = &self.project_id;
		return self
			.base_url
			.join(&format!("projects/{project_id}/repository/branches"))
			.unwrap();
	}
}

/// Retrieves branches for the given repository from the given API.
pub fn get_branches(api: &GitLabApi, project_id: String) -> Result<Vec<Branch>, error::Error> {
	let base_url = api.base_url().clone();
	let endpoint: BranchesEndpoint = BranchesEndpoint {
		base_url,
		project_id,
	};

	let branches = call(&endpoint)?;
	return Ok(branches);
}