MCPcopy Create free account
hub / github.com/brocode/fw / org_import

Function org_import

src/setup/mod.rs:94–134  ·  view source on GitHub ↗
(maybe_config: Result<Config, AppError>, org_name: &str, include_archived: bool)

Source from the content-addressed store, hash-verified

92}
93
94pub fn org_import(maybe_config: Result<Config, AppError>, org_name: &str, include_archived: bool) -> Result<(), AppError> {
95 let current_config = maybe_config?;
96 let token = env::var_os("FW_GITHUB_TOKEN")
97 .map(|s| s.to_string_lossy().to_string())
98 .or_else(|| current_config.settings.github_token.clone())
99 .ok_or_else(|| {
100 AppError::UserError(format!(
101 "Can't call GitHub API for org {} because no github oauth token (settings.github_token) specified in the configuration.",
102 org_name
103 ))
104 })?;
105 let mut api = github::github_api(&token)?;
106 let org_repository_names: Vec<String> = api.list_repositories(org_name, include_archived)?;
107 let after_clone = current_config.settings.default_after_clone.clone();
108 let after_workon = current_config.settings.default_after_workon.clone();
109 let tags = current_config.settings.default_tags.clone();
110 let mut current_projects = current_config.projects;
111
112 for name in org_repository_names {
113 let p = Project {
114 name: name.clone(),
115 git: format!("git@github.com:{}/{}.git", org_name, name),
116 after_clone: after_clone.clone(),
117 after_workon: after_workon.clone(),
118 override_path: None,
119 tags: tags.clone(),
120 additional_remotes: None,
121 bare: None,
122 trusted: false,
123 project_config_path: org_name.to_string(),
124 };
125
126 if current_projects.contains_key(&p.name) {
127 // "Skipping new project from Github import because it already exists in the current fw config
128 } else {
129 config::write_project(&p)?;
130 current_projects.insert(p.name.clone(), p); // to ensure no duplicated name encountered during processing
131 }
132 }
133 Ok(())
134}
135
136pub fn import(maybe_config: Result<Config, AppError>, path: &str) -> Result<(), AppError> {
137 let path = fs::canonicalize(Path::new(path))?;

Callers 1

_mainFunction · 0.85

Calls 3

github_apiFunction · 0.85
write_projectFunction · 0.85
list_repositoriesMethod · 0.80

Tested by

no test coverage detected