git-gemini-forge 0.5.2

A simple Gemini server that serves a read-only view of public repositories from a Git forge.
pub mod error;
mod get;

pub mod responses;

use std::fmt::Debug;
use strum_macros::{Display, EnumIter, EnumString};
use url::Url;

// Export API structures:
pub mod forgejo;
pub mod gitlab;
// TODO: Implement other forge APIs...

// Describe the interfaces we expect:
#[derive(Clone, Copy, Debug, Display, EnumIter, EnumString, PartialEq)]
#[strum(ascii_case_insensitive)] // See https://docs.rs/strum/latest/strum/additional_attributes/index.html
pub enum ForgeApiKind {
	Forgejo,
	Gitea,
	GitLab,
}

/// Describes an interface by which we expect to get certain details
/// from a git forge. Implementations usually make REST calls via HTTP.
pub trait ForgeApi
where
	Self: Sync + Send,
{
	/// The kind of server software that serves this API.
	fn kind(&self) -> ForgeApiKind;

	/// The URL at which to communicate with the API. (e.g. "https://git.average.name/api/v1/")
	fn base_url(&self) -> &Url;

	/// Retrieves branches for the given repository.
	fn get_branches(
		&self,
		username: &str,
		repo_name: &str,
	) -> Result<Vec<responses::Branch>, error::Error>;

	/// Retrieves a list of files for the given repository.
	fn get_file_tree(
		&self,
		username: &str,
		repo_name: &str,
	) -> Result<Vec<responses::RepoContents>, error::Error>;

	/// Retrieves the 12 most recent repositories.
	fn get_recent_repos(&self) -> Result<Vec<responses::Repo>, error::Error>;

	/// Retrieves repository metadata.
	fn get_repo(&self, username: &str, repo_name: &str) -> Result<responses::Repo, error::Error>;

	/// Retrieves the user's repositories.
	fn get_user_repos(&self, username: &str) -> Result<Vec<responses::Repo>, error::Error>;

	/// Retrieves the users.
	fn get_users(&self) -> Result<Vec<responses::User>, error::Error>;

	/// Retrieves the forge version.
	fn get_version(&self) -> Result<responses::ServerVersion, error::Error>;
}