Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 96 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ clap = { version = "4.0.32", features = ["cargo"] }
eyre = "0.6.8"
dirs = "4.0.0"
walkdir = "2.3.2"
rayon = "1.7.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions crates/github/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ util = { path = "../util" }
eyre.workspace = true
clap.workspace = true
dirs.workspace = true
rayon.workspace = true

serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
Expand Down
99 changes: 62 additions & 37 deletions crates/github/src/fuzzy_clone.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::Write;
use std::sync::{Arc, Mutex};

use clap::value_parser;
use eyre::Context;
Expand Down Expand Up @@ -137,45 +138,69 @@ impl FuzzyClone {
}

fn get_entries() -> eyre::Result<Vec<GitHubEntry>> {
let mut entries = Vec::new();

for org in Self::get_settings()?.orgs {
let private_entires = util::shell::run_with_input_and_output(
&[
"gh",
"repo",
"list",
&org,
"--visibility",
"private",
"--limit",
"1000",
],
"".into(),
)?;

let public_entires = util::shell::run_with_input_and_output(
&[
"gh",
"repo",
"list",
&org,
"--visibility",
"public",
"--limit",
"1000",
],
"".into(),
)?;

let private = std::str::from_utf8(private_entires.stdout.as_slice())?;
let public = std::str::from_utf8(public_entires.stdout.as_slice())?;
let raw_entries = format!("{private}{public}");
let mut entries = Arc::new(Mutex::new(Vec::new()));

rayon::scope(|s| {
for org in Self::get_settings().unwrap().orgs {
s.spawn({
let entries = entries.clone();
let org = org.clone();

move |_| {
println!("fetching private repos for {}", org);
let private_entires = util::shell::run_with_input_and_output(
&[
"gh",
"repo",
"list",
&org,
"--visibility",
"private",
"--limit",
"1000",
],
"".into(),
)
.unwrap();
let private =
std::str::from_utf8(private_entires.stdout.as_slice()).unwrap();
let mut entries = entries.lock().unwrap();
entries.push(Self::parse_entries(private.to_string()).unwrap());
println!("done: fetching private repos for {}", org);
}
});

let entries = entries.clone();
let org = org.clone();
s.spawn(move |_| {
println!("fetching public repos for {}", org);
let public_entires = util::shell::run_with_input_and_output(
&[
"gh",
"repo",
"list",
&org,
"--visibility",
"public",
"--limit",
"1000",
],
"".into(),
)
.unwrap();

let public = std::str::from_utf8(public_entires.stdout.as_slice()).unwrap();
let mut entries = entries.lock().unwrap();
entries.push(Self::parse_entries(public.to_string()).unwrap());
println!("done: fetching public repos for {}", org);
})
}
});

entries.push(Self::parse_entries(raw_entries)?);
}
let entries = Arc::try_unwrap(entries).unwrap().into_inner().unwrap();
let entries = entries.into_iter().flat_map(|s| s).collect();

Ok(entries.into_iter().flat_map(|s| s).collect())
Ok(entries)
}

fn clone(chosen: GitHubEntry) -> eyre::Result<std::path::PathBuf> {
Expand Down