2024-04-18 20:26:19 +01:00
|
|
|
pub mod load;
|
|
|
|
|
2024-04-07 18:58:08 +01:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
fmt::{Display, Formatter},
|
2024-04-14 15:46:21 +01:00
|
|
|
ops::Deref,
|
2024-04-19 18:15:27 +01:00
|
|
|
path::PathBuf,
|
2024-04-07 18:58:08 +01:00
|
|
|
};
|
2024-04-07 18:36:27 +01:00
|
|
|
|
2024-04-07 13:47:39 +01:00
|
|
|
use serde::Deserialize;
|
|
|
|
use terrors::OneOf;
|
|
|
|
|
|
|
|
use crate::filesystem::FileSystem;
|
2024-04-08 08:31:45 +01:00
|
|
|
|
2024-04-13 11:31:00 +01:00
|
|
|
/// Mapped from the `git-next-server.toml` file
|
2024-04-07 16:09:16 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq, Deserialize)]
|
2024-04-08 08:31:45 +01:00
|
|
|
pub struct ServerConfig {
|
2024-04-13 11:59:59 +01:00
|
|
|
webhook: Webhook,
|
2024-04-19 18:49:03 +01:00
|
|
|
storage: ServerStorage,
|
2024-04-19 18:15:27 +01:00
|
|
|
forge: HashMap<String, ForgeConfig>,
|
2024-04-07 18:58:08 +01:00
|
|
|
}
|
2024-04-08 08:31:45 +01:00
|
|
|
impl ServerConfig {
|
2024-04-08 08:05:13 +01:00
|
|
|
pub(crate) fn load(fs: &FileSystem) -> Result<Self, OneOf<(std::io::Error, toml::de::Error)>> {
|
|
|
|
let str = fs.read_file("git-next-server.toml").map_err(OneOf::new)?;
|
|
|
|
toml::from_str(&str).map_err(OneOf::new)
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:15:27 +01:00
|
|
|
pub(crate) fn forges(&self) -> impl Iterator<Item = (ForgeName, &ForgeConfig)> {
|
2024-04-08 08:05:13 +01:00
|
|
|
self.forge
|
|
|
|
.iter()
|
|
|
|
.map(|(name, forge)| (ForgeName(name.clone()), forge))
|
|
|
|
}
|
2024-04-14 06:48:26 +01:00
|
|
|
|
|
|
|
pub const fn webhook(&self) -> &Webhook {
|
|
|
|
&self.webhook
|
|
|
|
}
|
2024-04-08 08:05:13 +01:00
|
|
|
}
|
2024-04-07 18:58:08 +01:00
|
|
|
|
2024-04-13 11:59:59 +01:00
|
|
|
/// Defines the Webhook Forges should send updates to
|
2024-04-14 06:48:26 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-13 11:59:59 +01:00
|
|
|
pub struct Webhook {
|
|
|
|
url: String,
|
|
|
|
}
|
|
|
|
impl Webhook {
|
|
|
|
pub fn url(&self) -> WebhookUrl {
|
|
|
|
WebhookUrl(self.url.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The URL for the webhook where forges should send their updates
|
2024-04-15 22:44:56 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-13 11:59:59 +01:00
|
|
|
pub struct WebhookUrl(String);
|
|
|
|
impl AsRef<str> for WebhookUrl {
|
|
|
|
fn as_ref(&self) -> &str {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-19 18:49:03 +01:00
|
|
|
/// The directory to store server data, such as cloned repos
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
|
|
|
pub struct ServerStorage {
|
|
|
|
path: PathBuf,
|
|
|
|
}
|
|
|
|
|
2024-04-13 11:31:00 +01:00
|
|
|
/// Mapped from `.git-next.toml` file in target repo
|
|
|
|
/// Is also derived from the optional parameters in `git-next-server.toml` at
|
|
|
|
/// `forge.{forge}.repos.{repo}.(main|next|dev)`
|
2024-04-09 15:31:59 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-08 09:54:20 +01:00
|
|
|
pub struct RepoConfig {
|
|
|
|
branches: RepoBranches,
|
|
|
|
}
|
|
|
|
impl RepoConfig {
|
2024-04-16 22:21:55 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
pub const fn new(branches: RepoBranches) -> Self {
|
|
|
|
Self { branches }
|
|
|
|
}
|
|
|
|
// #[cfg(test)]
|
|
|
|
pub fn load(toml: &str) -> Result<Self, toml::de::Error> {
|
|
|
|
toml::from_str(toml)
|
2024-04-08 09:54:20 +01:00
|
|
|
}
|
2024-04-09 14:52:12 +01:00
|
|
|
|
2024-04-14 15:46:21 +01:00
|
|
|
pub const fn branches(&self) -> &RepoBranches {
|
2024-04-09 14:52:12 +01:00
|
|
|
&self.branches
|
|
|
|
}
|
2024-04-08 09:54:20 +01:00
|
|
|
}
|
2024-04-09 10:44:01 +01:00
|
|
|
impl Display for RepoConfig {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{:?}", self.branches)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// Mapped from `.git-next.toml` file at `branches`
|
2024-04-09 15:31:59 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-08 09:54:20 +01:00
|
|
|
pub struct RepoBranches {
|
|
|
|
main: String,
|
|
|
|
next: String,
|
|
|
|
dev: String,
|
|
|
|
}
|
2024-04-09 14:52:12 +01:00
|
|
|
impl RepoBranches {
|
2024-04-16 22:21:55 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
pub fn new(main: impl Into<String>, next: impl Into<String>, dev: impl Into<String>) -> Self {
|
|
|
|
Self {
|
|
|
|
main: main.into(),
|
|
|
|
next: next.into(),
|
|
|
|
dev: dev.into(),
|
|
|
|
}
|
|
|
|
}
|
2024-04-09 14:52:12 +01:00
|
|
|
pub fn main(&self) -> BranchName {
|
|
|
|
BranchName(self.main.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn next(&self) -> BranchName {
|
|
|
|
BranchName(self.next.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dev(&self) -> BranchName {
|
|
|
|
BranchName(self.dev.clone())
|
|
|
|
}
|
|
|
|
}
|
2024-04-09 10:44:01 +01:00
|
|
|
impl Display for RepoBranches {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
2024-04-08 09:54:20 +01:00
|
|
|
|
2024-04-13 11:31:00 +01:00
|
|
|
/// Defines a Forge to connect to
|
|
|
|
/// Maps from `git-next-server.toml` at `forge.{forge}`
|
2024-04-09 07:20:13 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-19 18:15:27 +01:00
|
|
|
pub struct ForgeConfig {
|
2024-04-07 16:11:23 +01:00
|
|
|
forge_type: ForgeType,
|
2024-04-07 16:14:05 +01:00
|
|
|
hostname: String,
|
2024-04-07 13:47:39 +01:00
|
|
|
user: String,
|
2024-04-08 12:08:42 +01:00
|
|
|
token: String,
|
2024-04-07 13:47:39 +01:00
|
|
|
// API Token
|
|
|
|
// Private SSH Key Path
|
2024-04-19 18:15:27 +01:00
|
|
|
repos: HashMap<String, ServerRepoConfig>,
|
2024-04-07 18:58:08 +01:00
|
|
|
}
|
2024-04-19 18:15:27 +01:00
|
|
|
impl ForgeConfig {
|
2024-04-09 07:20:13 +01:00
|
|
|
#[allow(dead_code)]
|
2024-04-07 18:58:08 +01:00
|
|
|
pub const fn forge_type(&self) -> &ForgeType {
|
|
|
|
&self.forge_type
|
|
|
|
}
|
|
|
|
|
2024-04-08 08:05:13 +01:00
|
|
|
pub fn hostname(&self) -> Hostname {
|
|
|
|
Hostname(self.hostname.clone())
|
2024-04-07 18:58:08 +01:00
|
|
|
}
|
|
|
|
|
2024-04-08 08:05:13 +01:00
|
|
|
pub fn user(&self) -> User {
|
|
|
|
User(self.user.clone())
|
2024-04-07 18:58:08 +01:00
|
|
|
}
|
|
|
|
|
2024-04-08 12:08:42 +01:00
|
|
|
pub fn token(&self) -> ApiToken {
|
2024-04-12 15:27:03 +01:00
|
|
|
ApiToken(self.token.clone().into())
|
2024-04-08 12:08:42 +01:00
|
|
|
}
|
|
|
|
|
2024-04-19 18:15:27 +01:00
|
|
|
pub fn repos(&self) -> impl Iterator<Item = (RepoAlias, &ServerRepoConfig)> {
|
2024-04-08 08:05:13 +01:00
|
|
|
self.repos
|
|
|
|
.iter()
|
2024-04-13 11:45:58 +01:00
|
|
|
.map(|(name, repo)| (RepoAlias(name.clone()), repo))
|
2024-04-07 18:58:08 +01:00
|
|
|
}
|
2024-04-07 13:47:39 +01:00
|
|
|
}
|
2024-04-19 18:15:27 +01:00
|
|
|
impl Display for ForgeConfig {
|
2024-04-09 07:20:13 +01:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{} - {}@{}", self.forge_type, self.user, self.hostname)
|
|
|
|
}
|
|
|
|
}
|
2024-04-07 13:47:39 +01:00
|
|
|
|
2024-04-19 18:15:27 +01:00
|
|
|
/// Defines a Repo within a ForgeConfig to be monitored by the server
|
2024-04-13 11:31:00 +01:00
|
|
|
/// Maps from `git-next-server.toml` at `forge.{forge}.repos.{name}`
|
2024-04-09 07:20:13 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-19 18:15:27 +01:00
|
|
|
pub struct ServerRepoConfig {
|
2024-04-08 08:05:13 +01:00
|
|
|
repo: String,
|
|
|
|
branch: String,
|
2024-04-21 18:54:36 +01:00
|
|
|
gitdir: Option<PathBuf>,
|
2024-04-13 11:44:40 +01:00
|
|
|
main: Option<String>,
|
|
|
|
next: Option<String>,
|
|
|
|
dev: Option<String>,
|
2024-04-08 08:05:13 +01:00
|
|
|
}
|
2024-04-19 18:15:27 +01:00
|
|
|
impl ServerRepoConfig {
|
2024-04-08 08:05:13 +01:00
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn repo(&self) -> RepoPath {
|
|
|
|
RepoPath(self.repo.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn branch(&self) -> BranchName {
|
|
|
|
BranchName(self.branch.clone())
|
|
|
|
}
|
2024-04-13 11:44:40 +01:00
|
|
|
/// Returns a RepoConfig from the server configuration if ALL THREE branches were provided
|
|
|
|
pub fn repo_config(&self) -> Option<RepoConfig> {
|
|
|
|
match (&self.main, &self.next, &self.dev) {
|
|
|
|
(Some(main), Some(next), Some(dev)) => Some(RepoConfig {
|
|
|
|
branches: RepoBranches {
|
|
|
|
main: main.to_string(),
|
|
|
|
next: next.to_string(),
|
|
|
|
dev: dev.to_string(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2024-04-21 18:54:36 +01:00
|
|
|
pub fn gitdir(&self) -> Option<GitDir> {
|
|
|
|
self.gitdir.clone().map(GitDir)
|
2024-04-21 18:48:49 +01:00
|
|
|
}
|
2024-04-08 08:05:13 +01:00
|
|
|
}
|
|
|
|
#[cfg(test)]
|
2024-04-19 18:15:27 +01:00
|
|
|
impl AsRef<Self> for ServerRepoConfig {
|
2024-04-08 09:54:20 +01:00
|
|
|
fn as_ref(&self) -> &Self {
|
2024-04-08 08:05:13 +01:00
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 18:15:27 +01:00
|
|
|
impl Display for ServerRepoConfig {
|
2024-04-08 08:05:13 +01:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{} - {}", self.repo, self.branch)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The name of a Forge to connect to
|
2024-04-08 08:22:23 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2024-04-07 19:41:56 +01:00
|
|
|
pub struct ForgeName(pub String);
|
|
|
|
impl Display for ForgeName {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The hostname of a forge
|
2024-04-08 08:22:23 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2024-04-07 19:41:56 +01:00
|
|
|
pub struct Hostname(pub String);
|
2024-04-08 08:05:13 +01:00
|
|
|
impl Display for Hostname {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The user within the forge to connect as
|
2024-04-08 08:22:23 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2024-04-07 19:41:56 +01:00
|
|
|
pub struct User(pub String);
|
2024-04-08 08:05:13 +01:00
|
|
|
impl Display for User {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The API Token for the [user]
|
|
|
|
/// ForgeJo: https://{hostname}/user/settings/applications
|
|
|
|
/// Github: https://github.com/settings/tokens
|
2024-04-12 15:27:03 +01:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct ApiToken(pub secrecy::Secret<String>);
|
|
|
|
impl From<String> for ApiToken {
|
|
|
|
fn from(value: String) -> Self {
|
|
|
|
Self(value.into())
|
2024-04-08 11:48:35 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
/// The API Token is in effect a password, so it must be explicitly exposed to access its value
|
2024-04-19 18:56:42 +01:00
|
|
|
impl secrecy::ExposeSecret<String> for ApiToken {
|
2024-04-12 15:27:03 +01:00
|
|
|
fn expose_secret(&self) -> &String {
|
|
|
|
self.0.expose_secret()
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The derived information about a Forge, used to create interactions with it
|
2024-04-12 15:27:03 +01:00
|
|
|
#[derive(Clone, Debug)]
|
2024-04-07 19:41:56 +01:00
|
|
|
pub struct ForgeDetails {
|
|
|
|
pub name: ForgeName,
|
|
|
|
pub forge_type: ForgeType,
|
|
|
|
pub hostname: Hostname,
|
|
|
|
pub user: User,
|
2024-04-08 12:08:42 +01:00
|
|
|
pub token: ApiToken,
|
2024-04-07 19:41:56 +01:00
|
|
|
// API Token
|
|
|
|
// Private SSH Key Path
|
|
|
|
}
|
2024-04-19 18:15:27 +01:00
|
|
|
impl From<(&ForgeName, &ForgeConfig)> for ForgeDetails {
|
|
|
|
fn from(forge: (&ForgeName, &ForgeConfig)) -> Self {
|
2024-04-07 19:41:56 +01:00
|
|
|
Self {
|
|
|
|
name: forge.0.clone(),
|
|
|
|
forge_type: forge.1.forge_type.clone(),
|
2024-04-08 11:49:56 +01:00
|
|
|
hostname: forge.1.hostname(),
|
|
|
|
user: forge.1.user(),
|
2024-04-08 12:08:42 +01:00
|
|
|
token: forge.1.token(),
|
2024-04-07 19:41:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
2024-04-13 11:45:58 +01:00
|
|
|
/// The alias of a repo
|
2024-04-13 11:31:00 +01:00
|
|
|
/// This is the alias for the repo within `git-next-server.toml`
|
2024-04-13 16:16:09 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
2024-04-13 11:45:58 +01:00
|
|
|
pub struct RepoAlias(pub String);
|
|
|
|
impl Display for RepoAlias {
|
2024-04-07 19:41:56 +01:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The path for the repo within the forge.
|
|
|
|
/// Typically this is composed of the user or organisation and the name of the repo
|
|
|
|
/// e.g. `{user}/{repo}`
|
2024-04-08 08:22:23 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2024-04-07 19:41:56 +01:00
|
|
|
pub struct RepoPath(pub String);
|
2024-04-08 08:05:13 +01:00
|
|
|
impl Display for RepoPath {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The name of a Branch
|
2024-04-12 18:45:32 +01:00
|
|
|
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
2024-04-08 08:05:13 +01:00
|
|
|
pub struct BranchName(pub String);
|
|
|
|
impl Display for BranchName {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2024-04-14 15:46:21 +01:00
|
|
|
impl Deref for BranchName {
|
|
|
|
type Target = String;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 11:31:00 +01:00
|
|
|
|
|
|
|
/// The derived information about a repo, used to interact with it
|
2024-04-12 15:27:03 +01:00
|
|
|
#[derive(Clone, Debug)]
|
2024-04-07 19:41:56 +01:00
|
|
|
pub struct RepoDetails {
|
2024-04-13 11:45:58 +01:00
|
|
|
pub name: RepoAlias,
|
2024-04-20 20:49:38 +01:00
|
|
|
pub repo_path: RepoPath,
|
2024-04-08 08:05:13 +01:00
|
|
|
pub branch: BranchName,
|
2024-04-07 19:41:56 +01:00
|
|
|
pub forge: ForgeDetails,
|
2024-04-21 19:33:18 +01:00
|
|
|
pub repo_config: Option<RepoConfig>,
|
2024-04-21 18:48:49 +01:00
|
|
|
pub gitdir: Option<GitDir>,
|
2024-04-07 19:41:56 +01:00
|
|
|
}
|
2024-04-08 08:05:13 +01:00
|
|
|
impl RepoDetails {
|
2024-04-19 18:15:27 +01:00
|
|
|
pub fn new(
|
|
|
|
name: &RepoAlias,
|
2024-04-20 20:50:50 +01:00
|
|
|
server_repo_config: &ServerRepoConfig,
|
2024-04-19 18:15:27 +01:00
|
|
|
forge_name: &ForgeName,
|
|
|
|
forge: &ForgeConfig,
|
|
|
|
) -> Self {
|
2024-04-08 08:05:13 +01:00
|
|
|
Self {
|
|
|
|
name: name.clone(),
|
2024-04-20 20:49:38 +01:00
|
|
|
repo_path: RepoPath(server_repo_config.repo.clone()),
|
2024-04-21 19:33:18 +01:00
|
|
|
repo_config: server_repo_config.repo_config(),
|
2024-04-20 20:50:50 +01:00
|
|
|
branch: BranchName(server_repo_config.branch.clone()),
|
2024-04-21 18:54:36 +01:00
|
|
|
gitdir: server_repo_config.gitdir(),
|
2024-04-08 08:05:13 +01:00
|
|
|
forge: ForgeDetails {
|
|
|
|
name: forge_name.clone(),
|
|
|
|
forge_type: forge.forge_type.clone(),
|
2024-04-08 11:49:56 +01:00
|
|
|
hostname: forge.hostname(),
|
|
|
|
user: forge.user(),
|
2024-04-08 12:08:42 +01:00
|
|
|
token: forge.token(),
|
2024-04-08 08:05:13 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 18:56:42 +01:00
|
|
|
pub fn origin(&self) -> secrecy::Secret<String> {
|
|
|
|
let repo_details = self;
|
|
|
|
let user = &repo_details.forge.user;
|
|
|
|
let hostname = &repo_details.forge.hostname;
|
2024-04-20 20:49:38 +01:00
|
|
|
let repo_path = &repo_details.repo_path;
|
2024-04-19 18:56:42 +01:00
|
|
|
use secrecy::ExposeSecret;
|
|
|
|
let expose_secret = &repo_details.forge.token;
|
|
|
|
let token = expose_secret.expose_secret();
|
2024-04-20 20:49:38 +01:00
|
|
|
let origin = format!("https://{user}:{token}@{hostname}/{repo_path}.git");
|
2024-04-19 18:56:42 +01:00
|
|
|
origin.into()
|
|
|
|
}
|
2024-04-08 08:05:13 +01:00
|
|
|
}
|
2024-04-08 08:12:31 +01:00
|
|
|
impl Display for RepoDetails {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"{}/{} ({}): {}:{}/{} @ {}",
|
|
|
|
self.forge.name,
|
|
|
|
self.name,
|
|
|
|
self.forge.forge_type,
|
|
|
|
self.forge.hostname,
|
|
|
|
self.forge.user,
|
2024-04-20 20:49:38 +01:00
|
|
|
self.repo_path,
|
2024-04-08 08:12:31 +01:00
|
|
|
self.branch,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2024-04-07 19:41:56 +01:00
|
|
|
|
2024-04-13 11:31:00 +01:00
|
|
|
/// Identifier for the type of Forge
|
2024-04-07 19:41:56 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
|
2024-04-07 16:09:16 +01:00
|
|
|
pub enum ForgeType {
|
2024-04-12 20:53:55 +01:00
|
|
|
#[cfg(feature = "forgejo")]
|
2024-04-07 13:47:39 +01:00
|
|
|
ForgeJo,
|
|
|
|
// Gitea,
|
|
|
|
// GitHub,
|
|
|
|
// GitLab,
|
|
|
|
// BitBucket,
|
2024-04-12 22:41:16 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
MockForge,
|
2024-04-07 13:47:39 +01:00
|
|
|
}
|
2024-04-07 18:36:27 +01:00
|
|
|
impl Display for ForgeType {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-21 18:38:47 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
|
|
pub struct GitDir(PathBuf);
|
|
|
|
impl GitDir {
|
|
|
|
#[allow(dead_code)] // TODO:
|
|
|
|
pub const fn pathbuf(&self) -> &PathBuf {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::fmt::Display for GitDir {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{self:?}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl From<&str> for GitDir {
|
|
|
|
fn from(value: &str) -> Self {
|
|
|
|
Self(value.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-07 13:47:39 +01:00
|
|
|
#[cfg(test)]
|
2024-04-21 18:23:57 +01:00
|
|
|
mod tests;
|