refactor(config): more derive_more replacing boilerplate
All checks were successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-05-15 07:55:05 +01:00
parent c374076323
commit d70baa4350
23 changed files with 217 additions and 220 deletions

View file

@ -62,9 +62,10 @@ warp = "0.3"
# error handling
derive_more = { version = "1.0.0-beta.6", features = [
"from",
"constructor",
"display",
"deref",
"from",
] }
terrors = "0.3"

View file

@ -1,13 +1,8 @@
/// The API Token for the [user]
/// ForgeJo: https://{hostname}/user/settings/applications
/// Github: https://github.com/settings/tokens
#[derive(Clone, Debug)]
pub struct ApiToken(pub secrecy::Secret<String>);
impl From<String> for ApiToken {
fn from(value: String) -> Self {
Self(value.into())
}
}
#[derive(Clone, Debug, derive_more::Constructor)]
pub struct ApiToken(secrecy::Secret<String>);
/// The API Token is in effect a password, so it must be explicitly exposed to access its value
impl secrecy::ExposeSecret<String> for ApiToken {
fn expose_secret(&self) -> &String {

View file

@ -4,14 +4,16 @@ use crate::{ApiToken, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User};
/// Defines a Forge to connect to
/// Maps from `git-next-server.toml` at `forge.{forge}`
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Display)]
#[derive(
Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Constructor, derive_more::Display,
)]
#[display("{}:{}@{}", forge_type.to_string().to_lowercase(), user, hostname)]
pub struct ForgeConfig {
pub forge_type: ForgeType,
pub hostname: String,
pub user: String,
pub token: String,
pub repos: BTreeMap<String, ServerRepoConfig>,
forge_type: ForgeType,
hostname: String,
user: String,
token: String,
repos: BTreeMap<String, ServerRepoConfig>,
}
impl ForgeConfig {
pub const fn forge_type(&self) -> ForgeType {
@ -23,11 +25,11 @@ impl ForgeConfig {
}
pub fn user(&self) -> User {
User(self.user.clone())
User::new(self.user.clone())
}
pub fn token(&self) -> ApiToken {
ApiToken(self.token.clone().into())
ApiToken::new(self.token.clone().into())
}
pub fn repos(&self) -> impl Iterator<Item = (RepoAlias, &ServerRepoConfig)> {
@ -35,4 +37,8 @@ impl ForgeConfig {
.iter()
.map(|(name, repo)| (RepoAlias::new(name), repo))
}
pub fn get_repo(&self, arg: &str) -> Option<&ServerRepoConfig> {
self.repos.get(arg)
}
}

View file

@ -1,16 +1,38 @@
use crate::{ApiToken, ForgeConfig, ForgeName, ForgeType, Hostname, User};
/// The derived information about a Forge, used to create interactions with it
#[derive(Clone, Debug)]
#[derive(Clone, Debug, derive_more::Constructor)]
pub struct ForgeDetails {
pub forge_name: ForgeName,
pub forge_type: ForgeType,
pub hostname: Hostname,
pub user: User,
pub token: ApiToken,
forge_name: ForgeName,
forge_type: ForgeType,
hostname: Hostname,
user: User,
token: ApiToken,
// API Token
// Private SSH Key Path
}
impl ForgeDetails {
pub const fn forge_name(&self) -> &ForgeName {
&self.forge_name
}
pub const fn forge_type(&self) -> ForgeType {
self.forge_type
}
pub const fn hostname(&self) -> &Hostname {
&self.hostname
}
pub const fn user(&self) -> &User {
&self.user
}
pub const fn token(&self) -> &ApiToken {
&self.token
}
pub fn with_hostname(self, hostname: Hostname) -> Self {
let mut me = self;
me.hostname = hostname;
me
}
}
impl From<(&ForgeName, &ForgeConfig)> for ForgeDetails {
fn from(forge: (&ForgeName, &ForgeConfig)) -> Self {
Self {

View file

@ -1,8 +1,8 @@
use std::path::PathBuf;
/// The name of a Forge to connect to
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
pub struct ForgeName(pub String);
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
pub struct ForgeName(String);
impl From<&ForgeName> for PathBuf {
fn from(value: &ForgeName) -> Self {
Self::from(&value.0)

View file

@ -1,6 +1,8 @@
use std::{ops::Deref, path::PathBuf};
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, derive_more::From)]
#[derive(
Debug, Clone, PartialEq, Eq, serde::Deserialize, derive_more::Deref, derive_more::From,
)]
pub struct GitDir(PathBuf);
impl GitDir {
pub fn new(pathbuf: &std::path::Path) -> Self {
@ -11,13 +13,6 @@ impl GitDir {
&self.0
}
}
impl Deref for GitDir {
type Target = PathBuf;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::fmt::Display for GitDir {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0.display())

View file

@ -1,12 +1,14 @@
use crate::BranchName;
/// Mapped from `.git-next.toml` file at `branches`
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Display)]
#[derive(
Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Constructor, derive_more::Display,
)]
#[display("{},{},{}", main, next, dev)]
pub struct RepoBranches {
pub main: String,
pub next: String,
pub dev: String,
main: String,
next: String,
dev: String,
}
impl RepoBranches {
pub fn main(&self) -> BranchName {

View file

@ -4,11 +4,13 @@ use crate::RepoConfigSource;
/// 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)`
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Display)]
#[derive(
Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Constructor, derive_more::Display,
)]
#[display("{}", branches)]
pub struct RepoConfig {
pub branches: RepoBranches,
pub source: RepoConfigSource,
branches: RepoBranches,
source: RepoConfigSource,
}
impl RepoConfig {
pub fn load(toml: &str) -> Result<Self, toml::de::Error> {

View file

@ -1,5 +1,5 @@
/// 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}`
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
pub struct RepoPath(pub String);
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
pub struct RepoPath(String);

View file

@ -4,19 +4,21 @@ use crate::{BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource, Repo
/// Defines a Repo within a ForgeConfig to be monitored by the server
/// Maps from `git-next-server.toml` at `forge.{forge}.repos.{name}`
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Display)]
#[derive(
Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Constructor, derive_more::Display,
)]
#[display("{}@{}", repo, branch)]
pub struct ServerRepoConfig {
pub repo: String,
pub branch: String,
pub gitdir: Option<PathBuf>,
pub main: Option<String>,
pub next: Option<String>,
pub dev: Option<String>,
repo: String,
branch: String,
gitdir: Option<PathBuf>,
main: Option<String>,
next: Option<String>,
dev: Option<String>,
}
impl ServerRepoConfig {
pub fn repo(&self) -> RepoPath {
RepoPath(self.repo.clone())
RepoPath::new(self.repo.clone())
}
pub fn branch(&self) -> BranchName {
@ -30,14 +32,10 @@ impl ServerRepoConfig {
/// 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(),
},
source: RepoConfigSource::Server,
}),
(Some(main), Some(next), Some(dev)) => Some(RepoConfig::new(
RepoBranches::new(main.to_string(), next.to_string(), dev.to_string()),
RepoConfigSource::Server,
)),
_ => None,
}
}

View file

@ -9,40 +9,29 @@ mod server_repo_config {
#[test]
fn should_not_return_repo_config_when_no_branches() {
let src = ServerRepoConfig {
repo: "".to_string(),
branch: "".to_string(),
gitdir: None,
main: None,
next: None,
dev: None,
};
let src = ServerRepoConfig::new("".to_string(), "".to_string(), None, None, None, None);
let_assert!(None = src.repo_config());
}
#[test]
fn should_return_repo_config_when_branches() {
let src = ServerRepoConfig {
repo: "".to_string(),
branch: "".to_string(),
gitdir: None,
main: Some("main".to_string()),
next: Some("next".to_string()),
dev: Some("dev".to_string()),
};
let src = ServerRepoConfig::new(
"".to_string(),
"".to_string(),
None,
Some("main".to_string()),
Some("next".to_string()),
Some("dev".to_string()),
);
let_assert!(Some(rc) = src.repo_config());
assert_eq!(
rc,
RepoConfig {
branches: RepoBranches {
main: "main".to_string(),
next: "next".to_string(),
dev: "dev".to_string()
},
source: RepoConfigSource::Server
}
RepoConfig::new(
RepoBranches::new("main".to_string(), "next".to_string(), "dev".to_string()),
RepoConfigSource::Server
)
);
}
}
@ -65,14 +54,10 @@ mod repo_config {
assert_eq!(
rc,
RepoConfig {
branches: RepoBranches {
main: "main".to_string(),
next: "next".to_string(),
dev: "dev".to_string(),
},
source: RepoConfigSource::Repo // reading from repo is the default
}
RepoConfig::new(
RepoBranches::new("main".to_string(), "next".to_string(), "dev".to_string(),),
RepoConfigSource::Repo // reading from repo is the default
)
);
Ok(())
@ -90,32 +75,26 @@ mod forge_config {
let hostname = "localhost".to_string();
let user = "bob".to_string();
let token = "alpha".to_string();
let red = ServerRepoConfig {
repo: "red".to_string(),
branch: "main".to_string(),
main: None,
next: None,
dev: None,
gitdir: None,
};
let blue = ServerRepoConfig {
repo: "blue".to_string(),
branch: "main".to_string(),
main: None,
next: None,
dev: None,
gitdir: None,
};
let red = ServerRepoConfig::new(
"red".to_string(),
"main".to_string(),
None,
None,
None,
None,
);
let blue = ServerRepoConfig::new(
"blue".to_string(),
"main".to_string(),
None,
None,
None,
None,
);
let mut repos = BTreeMap::new();
repos.insert("red".to_string(), red.clone());
repos.insert("blue".to_string(), blue.clone());
let fc = ForgeConfig {
forge_type,
hostname,
user,
token,
repos,
};
let fc = ForgeConfig::new(forge_type, hostname, user, token, repos);
let returned_repos = fc.repos().collect::<Vec<_>>();

View file

@ -1,3 +1,3 @@
/// The user within the forge to connect as
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
pub struct User(pub String);
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
pub struct User(String);

View file

@ -7,8 +7,8 @@ use super::{Generation, GitRemote};
/// The derived information about a repo, used to interact with it
#[derive(Clone, Debug, derive_more::Display)]
#[display("gen-{}:{}:{}/{}:{}@{}/{}@{}", generation, forge.forge_type,
forge.forge_name, repo_alias, forge.user, forge.hostname, repo_path,
#[display("gen-{}:{}:{}/{}:{}@{}/{}@{}", generation, forge.forge_type(),
forge.forge_name(), repo_alias, forge.user(), forge.hostname(), repo_path,
branch)]
pub struct RepoDetails {
pub generation: Generation,
@ -31,32 +31,32 @@ impl RepoDetails {
Self {
generation,
repo_alias: repo_alias.clone(),
repo_path: RepoPath(server_repo_config.repo.clone()),
repo_path: server_repo_config.repo(),
repo_config: server_repo_config.repo_config(),
branch: BranchName::new(&server_repo_config.branch),
branch: server_repo_config.branch(),
gitdir,
forge: ForgeDetails {
forge_name: forge_name.clone(),
forge_type: forge_config.forge_type(),
hostname: forge_config.hostname(),
user: forge_config.user(),
token: forge_config.token(),
},
forge: ForgeDetails::new(
forge_name.clone(),
forge_config.forge_type(),
forge_config.hostname(),
forge_config.user(),
forge_config.token(),
),
}
}
pub fn origin(&self) -> secrecy::Secret<String> {
let repo_details = self;
let user = &repo_details.forge.user;
let hostname = &repo_details.forge.hostname;
let user = &repo_details.forge.user();
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
let expose_secret = repo_details.forge.token();
use secrecy::ExposeSecret;
let expose_secret = &repo_details.forge.token;
let token = expose_secret.expose_secret();
let origin = format!("https://{user}:{token}@{hostname}/{repo_path}.git");
origin.into()
}
pub fn git_remote(&self) -> GitRemote {
GitRemote::new(self.forge.hostname.clone(), self.repo_path.clone())
GitRemote::new(self.forge.hostname().clone(), self.repo_path.clone())
}
}

View file

@ -48,7 +48,7 @@ pub fn find_default_remote(
info!(%host, %path, "found");
Ok(GitRemote::new(
Hostname::new(host),
RepoPath(path.to_string()),
RepoPath::new(path.to_string()),
))
}

View file

@ -37,7 +37,7 @@ impl RepoActor {
generation: Generation,
net: Network,
) -> Self {
let forge = match details.forge.forge_type {
let forge = match details.forge.forge_type() {
#[cfg(feature = "forgejo")]
ForgeType::ForgeJo => gitforge::Forge::new_forgejo(details.clone(), net.clone()),
ForgeType::MockForge => gitforge::Forge::new_mock(),
@ -84,7 +84,9 @@ impl std::fmt::Display for RepoActor {
write!(
f,
"{}:{}:{}",
self.generation, self.details.forge.forge_name, self.details.repo_alias
self.generation,
self.details.forge.forge_name(),
self.details.repo_alias
)
}
}

View file

@ -60,10 +60,10 @@ impl Deref for WebhookAuth {
#[tracing::instrument(skip_all, fields(%webhook_id))]
pub async fn unregister(webhook_id: WebhookId, repo_details: RepoDetails, net: network::Network) {
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = repo_details.repo_path;
use secrecy::ExposeSecret;
let token = repo_details.forge.token.expose_secret();
let token = repo_details.forge.token().expose_secret();
let url = network::NetUrl::new(format!(
"https://{hostname}/api/v1/repos/{repo_path}/hooks/{webhook_id}?token={token}"
));
@ -101,10 +101,10 @@ pub async fn register(
unregister(webhook_id, repo_details.clone(), net.clone()).await;
}
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = repo_details.repo_path;
use secrecy::ExposeSecret;
let token = repo_details.forge.token.expose_secret();
let token = repo_details.forge.token().expose_secret();
let url = network::NetUrl::new(format!(
"https://{hostname}/api/v1/repos/{repo_path}/hooks?token={token}"
));
@ -149,12 +149,12 @@ async fn find_existing_webhooks(
net: &network::Network,
) -> Vec<WebhookId> {
let mut ids: Vec<WebhookId> = vec![];
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
let mut page = 1;
loop {
use secrecy::ExposeSecret;
let token = &repo_details.forge.token.expose_secret();
let token = &repo_details.forge.token().expose_secret();
let url =
format!("https://{hostname}/api/v1/repos/{repo_path}/hooks?page={page}&token={token}");
let net_url = network::NetUrl::new(url);

View file

@ -45,7 +45,7 @@ impl ServerConfig {
pub(crate) fn forges(&self) -> impl Iterator<Item = (ForgeName, &ForgeConfig)> {
self.forge
.iter()
.map(|(name, forge)| (ForgeName(name.clone()), forge))
.map(|(name, forge)| (ForgeName::new(name.clone()), forge))
}
pub const fn storage(&self) -> &ServerStorage {

View file

@ -65,62 +65,62 @@ fn load_should_parse_server_config() -> Result<()> {
},
forge: HashMap::from([(
"default".to_string(),
ForgeConfig {
forge_type: ForgeType::MockForge,
hostname: "git.example.net".to_string(),
user: "Bob".to_string(),
token: "API-Token".to_string(),
repos: BTreeMap::from([
ForgeConfig::new(
ForgeType::MockForge,
"git.example.net".to_string(),
"Bob".to_string(),
"API-Token".to_string(),
BTreeMap::from([
(
"hello".to_string(),
ServerRepoConfig {
repo: "user/hello".to_string(),
branch: "main".to_string(),
gitdir: Some("/opt/git/user/hello.git".into()),
main: None,
next: None,
dev: None,
},
ServerRepoConfig::new(
"user/hello".to_string(),
"main".to_string(),
Some("/opt/git/user/hello.git".into()),
None,
None,
None,
),
),
(
"world".to_string(),
ServerRepoConfig {
repo: "user/world".to_string(),
branch: "master".to_string(),
gitdir: None,
main: Some("main".to_string()),
next: Some("next".to_string()),
dev: Some("dev".to_string()),
},
ServerRepoConfig::new(
"user/world".to_string(),
"master".to_string(),
None,
Some("main".to_string()),
Some("next".to_string()),
Some("dev".to_string()),
),
),
(
"sam".to_string(),
ServerRepoConfig {
repo: "user/sam".to_string(),
branch: "main".to_string(),
gitdir: None,
main: Some("master".to_string()),
next: Some("upcoming".to_string()),
dev: Some("sam-dev".to_string()),
},
ServerRepoConfig::new(
"user/sam".to_string(),
"main".to_string(),
None,
Some("master".to_string()),
Some("upcoming".to_string()),
Some("sam-dev".to_string()),
),
),
]),
},
),
)]),
};
assert_eq!(config, expected, "ServerConfig");
if let Some(forge) = config.forge.get("world") {
if let Some(repo) = forge.repos.get("sam") {
if let Some(repo) = forge.get_repo("sam") {
let repo_config = repo.repo_config();
let expected = Some(RepoConfig {
branches: RepoBranches {
main: "master".to_string(),
next: "upcoming".to_string(),
dev: "sam-dev".to_string(),
},
source: RepoConfigSource::Server,
});
let expected = Some(RepoConfig::new(
RepoBranches::new(
"master".to_string(),
"upcoming".to_string(),
"sam-dev".to_string(),
),
RepoConfigSource::Server,
));
assert_eq!(repo_config, expected, "RepoConfig");
}
}
@ -141,14 +141,10 @@ fn test_repo_config_load() -> Result<()> {
assert_eq!(
config,
RepoConfig {
branches: RepoBranches {
main: "main".to_string(),
next: "next".to_string(),
dev: "dev".to_string(),
},
source: RepoConfigSource::Repo
}
RepoConfig::new(
RepoBranches::new("main".to_string(), "next".to_string(), "dev".to_string(),),
RepoConfigSource::Repo
)
);
Ok(())
@ -178,8 +174,10 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> {
None,
GitDir::new(root), // Server GitDir - should be ignored
);
repo_details.forge.hostname = Hostname::new("git.kemitix.net");
repo_details.repo_path = RepoPath("kemitix/git-next".to_string());
repo_details.forge = repo_details
.forge
.with_hostname(Hostname::new("git.kemitix.net"));
repo_details.repo_path = RepoPath::new("kemitix/git-next".to_string());
let gitdir = &repo_details.gitdir;
let repository = Repository::open(gitdir)?;
let found_git_remote = git::validate::find_default_remote(&repository, Direction::Push)?;
@ -204,8 +202,10 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> {
None,
GitDir::new(root), // Server GitDir - should be ignored
);
repo_details.forge.hostname = Hostname::new("git.kemitix.net");
repo_details.repo_path = RepoPath("kemitix/git-next".to_string());
repo_details.forge = repo_details
.forge
.with_hostname(Hostname::new("git.kemitix.net"));
repo_details.repo_path = RepoPath::new("kemitix/git-next".to_string());
let gitdir = &repo_details.gitdir;
let repository = Repository::open(gitdir)?;
git::validate(&repository, &repo_details)?;
@ -224,8 +224,7 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
None,
GitDir::new(root), // Server GitDir - should be ignored
);
repo_details.forge.hostname = Hostname::new("localhost");
repo_details.repo_path = RepoPath("hello/world".to_string());
repo_details.repo_path = RepoPath::new("hello/world".to_string());
let gitdir = &repo_details.gitdir;
let repository = Repository::open(gitdir)?;
let_assert!(Err(_) = git::validate(&repository, &repo_details));
@ -235,7 +234,7 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> {
#[test]
fn git_remote_to_string_is_as_expected() {
let git_remote = GitRemote::new(Hostname::new("foo"), RepoPath("bar".to_string()));
let git_remote = GitRemote::new(Hostname::new("foo"), RepoPath::new("bar".to_string()));
let as_string = git_remote.to_string();
assert_eq!(as_string, "foo:bar");

View file

@ -9,10 +9,10 @@ pub async fn get_all(
repo_details: &RepoDetails,
net: &Network,
) -> Result<Vec<BranchName>, ForgeBranchError> {
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
use secrecy::ExposeSecret;
let token = repo_details.forge.token.expose_secret();
let token = repo_details.forge.token().expose_secret();
let url = network::NetUrl::new(format!(
"https://{hostname}/api/v1/repos/{repo_path}/branches?token={token}"
));

View file

@ -190,7 +190,7 @@ async fn get_commit_history(
find_commits: Vec<git::Commit>,
net: &kxio::network::Network,
) -> Result<Vec<git::Commit>, network::NetworkError> {
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
let mut page = 1;
@ -201,7 +201,7 @@ async fn get_commit_history(
let options = "stat=false&verification=false&files=false";
let mut all_commits = Vec::new();
loop {
let api_token = &repo_details.forge.token;
let api_token = &repo_details.forge.token();
use secrecy::ExposeSecret;
let token = api_token.expose_secret();
let url = network::NetUrl::new(format!(

View file

@ -11,9 +11,9 @@ pub(super) async fn contents_get(
branch: &BranchName,
file_path: &str,
) -> Result<String, ForgeFileError> {
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
let api_token = &repo_details.forge.token;
let api_token = &repo_details.forge.token();
use secrecy::ExposeSecret;
let token = api_token.expose_secret();
let url = network::NetUrl::new(format!(

View file

@ -93,9 +93,9 @@ impl super::ForgeLike for ForgeJoEnv {
async fn commit_status(&self, commit: &git::Commit) -> gitforge::CommitStatus {
let repo_details = &self.repo_details;
let hostname = &repo_details.forge.hostname;
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
let api_token = &repo_details.forge.token;
let api_token = &repo_details.forge.token();
use secrecy::ExposeSecret;
let token = api_token.expose_secret();
let url = network::NetUrl::new(format!(

View file

@ -6,21 +6,21 @@ use git_next_config::{
use git_next_git::{Generation, RepoDetails};
pub fn forge_details(n: u32, forge_type: ForgeType) -> ForgeDetails {
ForgeDetails {
forge_name: forge_name(n),
ForgeDetails::new(
forge_name(n),
forge_type,
hostname: hostname(n),
user: user(n),
token: api_token(n),
}
hostname(n),
user(n),
api_token(n),
)
}
pub fn api_token(n: u32) -> ApiToken {
ApiToken::from(format!("api-{}", n))
ApiToken::new(format!("api-{}", n).into())
}
pub fn user(n: u32) -> User {
User(format!("user-{}", n))
User::new(format!("user-{}", n))
}
pub fn hostname(n: u32) -> Hostname {
@ -28,7 +28,7 @@ pub fn hostname(n: u32) -> Hostname {
}
pub fn forge_name(n: u32) -> ForgeName {
ForgeName(format!("forge-name-{}", n))
ForgeName::new(format!("forge-name-{}", n))
}
pub fn repo_details(
n: u32,
@ -53,7 +53,7 @@ pub fn branch_name(n: u32) -> BranchName {
}
pub fn repo_path(n: u32) -> RepoPath {
RepoPath(format!("repo-path-{}", n))
RepoPath::new(format!("repo-path-{}", n))
}
pub fn repo_alias(n: u32) -> RepoAlias {
@ -61,12 +61,8 @@ pub fn repo_alias(n: u32) -> RepoAlias {
}
pub fn repo_config(n: u32, source: RepoConfigSource) -> RepoConfig {
RepoConfig {
branches: RepoBranches {
main: format!("main-{n}"),
next: format!("next-{n}"),
dev: format!("dev-{n}"),
},
RepoConfig::new(
RepoBranches::new(format!("main-{n}"), format!("next-{n}"), format!("dev-{n}")),
source,
}
)
}