Give repos a namespace to allow subdirectories

This commit is contained in:
2022-05-26 16:30:32 +02:00
parent f2d2482476
commit b8c552fb62
7 changed files with 92 additions and 36 deletions

View File

@@ -32,12 +32,12 @@ impl Project for GithubProject {
self.name.clone()
}
fn namespace(&self) -> String {
self.full_name
.rsplit_once('/')
.expect("Github project name did not include a namespace")
.0
.to_string()
fn namespace(&self) -> Option<String> {
if let Some((namespace, _name)) = self.full_name.rsplit_once('/') {
Some(namespace.to_string())
} else {
None
}
}
fn ssh_url(&self) -> String {

View File

@@ -39,12 +39,12 @@ impl Project for GitlabProject {
self.name.clone()
}
fn namespace(&self) -> String {
self.path_with_namespace
.rsplit_once('/')
.expect("Gitlab project name did not include a namespace")
.0
.to_string()
fn namespace(&self) -> Option<String> {
if let Some((namespace, _name)) = self.path_with_namespace.rsplit_once('/') {
Some(namespace.to_string())
} else {
None
}
}
fn ssh_url(&self) -> String {

View File

@@ -35,6 +35,7 @@ pub trait Project {
{
Repo {
name: self.name(),
namespace: self.namespace(),
worktree_setup,
remotes: Some(vec![Remote {
name: String::from(provider_name),
@@ -53,7 +54,7 @@ pub trait Project {
}
fn name(&self) -> String;
fn namespace(&self) -> String;
fn namespace(&self) -> Option<String>;
fn ssh_url(&self) -> String;
fn http_url(&self) -> String;
fn private(&self) -> bool;
@@ -200,7 +201,7 @@ pub trait Provider {
&self,
worktree_setup: bool,
force_ssh: bool,
) -> Result<HashMap<String, Vec<Repo>>, String> {
) -> Result<HashMap<Option<String>, Vec<Repo>>, String> {
let mut repos = vec![];
if self.filter().owner {
@@ -277,12 +278,16 @@ pub trait Provider {
}
}
let mut ret: HashMap<String, Vec<Repo>> = HashMap::new();
let mut ret: HashMap<Option<String>, Vec<Repo>> = HashMap::new();
for repo in repos {
let namespace = repo.namespace().clone();
let namespace = repo.namespace();
let repo = repo.into_repo_config(&self.name(), worktree_setup, force_ssh);
let mut repo = repo.into_repo_config(&self.name(), worktree_setup, force_ssh);
// Namespace is already part of the hashmap key. I'm not too happy
// about the data exchange format here.
repo.remove_namespace();
ret.entry(namespace).or_insert(vec![]).push(repo);
}