Skip to content

Commit

Permalink
remove gitlab. breaking changes in API.
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Mar 4, 2024
1 parent a059293 commit a3d34ec
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 797 deletions.
901 changes: 222 additions & 679 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ rand = "0.8"
crossbeam = "0"
indicatif = "0"
openssl-probe = "0.1"
gitlab = "0.1608"
reqwest = { version = "0", features = ["json", "blocking"] }
tokio = { version = "1", features = ["full"] }
openssl = { version = "0.10", features = ["vendored"] }
Expand Down
7 changes: 0 additions & 7 deletions doc/example_config/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ shell = [
]
github_token = 'onhrefhprqrfovgrf'

[gitlab]
token = 'onhrefhprqrfovgrf'
host = 'gitlab.com'

# Example:
# workspace = '~/workspace'
# shell = [
Expand All @@ -18,6 +14,3 @@ host = 'gitlab.com'
# default_after_workon = 'echo default after workon'
# default_after_clone = 'echo default after clone'
# github_token = 'githubtokensecret'
# [gitlab]
# token = 'token'
# host = 'localhost'
5 changes: 0 additions & 5 deletions man/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ fn main() {
.long("gen-workon")
.help("Generate sourceable shell code to work on project.")
)
.option(
Opt::new("<OPTIONS>")
.long("gitlab-import")
.help("Import all owned repositories / your organizations repositories from gitlab into fw.")
)
.option(
Opt::new("<SUBCOMMANDS>")
.long("help")
Expand Down
17 changes: 1 addition & 16 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::{builder::EnumValueParser, crate_version, value_parser, Arg, ArgAction, Command};
use clap::{crate_version, value_parser, Arg, ArgAction, Command};

use crate::setup::ProjectState;

pub fn app() -> Command {
let arg_with_fzf = Arg::new("with-fzf")
Expand Down Expand Up @@ -111,20 +110,6 @@ For further information please have a look at our README https://github.com/broc
)
.arg(Arg::new("ORG_NAME").value_name("ORG_NAME").index(1).required(true)),
)
.subcommand(
Command::new("gitlab-import")
.about("Import all owned repositories / your organizations repositories from gitlab into fw")
.arg(
Arg::new("include")
.help("Filter projects to import by state")
.long("include")
.short('a')
.num_args(1)
.value_name("state")
.value_parser(EnumValueParser::<ProjectState>::new())
.default_value("active"),
),
)
.subcommand(
Command::new("add-remote")
.about("Add remote to project")
Expand Down
2 changes: 0 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub fn read_config() -> Result<Config, AppError> {
default_after_clone: settings.default_after_clone,
default_tags: Some(default_tags),
github_token: settings.github_token,
gitlab: settings.gitlab,
},
})
}
Expand Down Expand Up @@ -451,7 +450,6 @@ mod tests {
shell: None,
tags: Some(tags),
github_token: None,
gitlab: None,
};
Config { projects, settings }
}
Expand Down
11 changes: 0 additions & 11 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ impl Tag {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GitlabSettings {
pub token: String,
pub host: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Settings {
Expand All @@ -41,7 +36,6 @@ pub struct Settings {
pub default_tags: Option<BTreeSet<String>>,
pub tags: Option<BTreeMap<String, Tag>>,
pub github_token: Option<String>,
pub gitlab: Option<GitlabSettings>,
}

impl Settings {
Expand All @@ -57,7 +51,6 @@ pub struct PersistedSettings {
pub default_after_workon: Option<String>,
pub default_after_clone: Option<String>,
pub github_token: Option<String>,
pub gitlab: Option<GitlabSettings>,
}

impl PersistedSettings {
Expand All @@ -68,10 +61,6 @@ impl PersistedSettings {
default_after_clone: Some("echo default after clone".to_string()),
shell: Some(vec!["/usr/bin/zsh".to_string(), "-c".to_string()]),
github_token: Some("githubtokensecret".to_string()),
gitlab: Some(GitlabSettings {
host: "localhost".to_string(),
token: "token".to_string(),
}),
}
}
}
5 changes: 0 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::errors::AppError;
use setup::ProjectState;
use std::collections::BTreeSet;

fn main() {
Expand Down Expand Up @@ -84,10 +83,6 @@ fn _main() -> i32 {
subcommand_matches.get_one::<String>("ORG_NAME").expect("argument required by clap.rs"),
subcommand_matches.get_flag("include-archived"),
),
"gitlab-import" => {
let state = *subcommand_matches.get_one::<ProjectState>("include").expect("argument required by clap.rs");
setup::gitlab_import(config, state)
}
"gen-workon" => workon::gen(
subcommand_matches.get_one::<String>("PROJECT_NAME").expect("argument required by clap.rs"),
config,
Expand Down
67 changes: 0 additions & 67 deletions src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,72 +91,6 @@ fn determine_projects(path: PathBuf) -> Result<BTreeMap<String, Project>, AppErr
Ok(projects)
}

pub fn gitlab_import(maybe_config: Result<Config, AppError>, state: ProjectState) -> Result<(), AppError> {
use gitlab::api::Query;
let current_config = maybe_config?;

let gitlab_config = current_config.settings.gitlab.clone().ok_or_else(|| {
AppError::UserError(
r#"Can't call Gitlab API, because no gitlab settings ("gitlab": { "token": "some-token", "url": "some-url" }) specified in the configuration."#
.to_string(),
)
})?;

let gitlab_client =
gitlab::Gitlab::new(gitlab_config.host, gitlab_config.token).map_err(|e| AppError::RuntimeError(format!("Failed to create gitlab client: {}", e)))?;

let mut builder = gitlab::api::projects::Projects::builder();
builder.owned(true);
match state {
ProjectState::Active => {
builder.archived(false);
}
ProjectState::Archived => {
builder.archived(true);
}
ProjectState::Both => {}
}

// owned repos and your organizations repositories
let owned_projects: Vec<gitlab::Project> = gitlab::api::paged(builder.build().unwrap(), gitlab::api::Pagination::All)
.query(&gitlab_client)
.map_err(|e| AppError::RuntimeError(format!("Failed to query gitlab: {}", e)))?;

let names_and_urls: Vec<(String, String)> = owned_projects
.iter()
.map(|repo| (repo.name.to_owned(), repo.ssh_url_to_repo.to_owned()))
.collect();

let after_clone = current_config.settings.default_after_clone.clone();
let after_workon = current_config.settings.default_after_workon.clone();
let tags = current_config.settings.default_tags.clone();
let mut current_projects = current_config.projects;

for (name, url) in names_and_urls {
let p = Project {
name,
git: url,
after_clone: after_clone.clone(),
after_workon: after_workon.clone(),
override_path: None,
tags: tags.clone(),
additional_remotes: None,
bare: None,
trusted: false,
project_config_path: "gitlab".to_string(),
};

if current_projects.contains_key(&p.name) {
//Skipping new project from Gitlab import because it already exists in the current fw config
} else {
config::write_project(&p)?; // TODO not sure if this should be default or gitlab subfolder? or even user specified?
current_projects.insert(p.name.clone(), p); // to ensure no duplicated name encountered during processing
}
}

Ok(())
}

pub fn org_import(maybe_config: Result<Config, AppError>, org_name: &str, include_archived: bool) -> Result<(), AppError> {
let current_config = maybe_config?;
let token = env::var_os("FW_GITHUB_TOKEN")
Expand Down Expand Up @@ -241,7 +175,6 @@ fn write_new_config_with_projects(projects: BTreeMap<String, Project>, workspace
default_after_clone: None,
shell: None,
github_token: None,
gitlab: None,
};
config::write_settings(&settings)?;
for p in projects.values() {
Expand Down
1 change: 0 additions & 1 deletion src/shell/setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ __fw_complete()
'add-remote'
'add'
'foreach'
'gitlab-import'
'help '
'import'
'inspect'
Expand Down
3 changes: 1 addition & 2 deletions src/shell/setup.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ function __fw_subcommands
'update:Update project settings' \
'tag:Manipulate tags' \
'print-path:Print project path to stdout' \
'org-import:Import all repositories from a github org' \
'gitlab-import:Import all owned repositories / your organizations repositories from gitlab'
'org-import:Import all repositories from a github org'

for subcmd in $__fw_subcommands_in_zsh_format
echo (string replace -r ':' '\t' $subcmd)
Expand Down
1 change: 0 additions & 1 deletion src/shell/setup.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ _fw() {
'tag:Manipulate tags'
'print-path:Print project path to stdout'
'org-import:Import all repositories from a github org'
'gitlab-import:Import all owned repositories / your organizations repositories from gitlab'
);
_describe action actions && ret=0;
;;
Expand Down

0 comments on commit a3d34ec

Please sign in to comment.