diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ea8c4bf..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index c40a069..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "clone_repos" -version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index e69b68a..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "clone_repos" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/clone.py b/clone.py new file mode 100644 index 0000000..671f2c1 --- /dev/null +++ b/clone.py @@ -0,0 +1,62 @@ +import os +import subprocess + +def main(): + github_user = input("Enter your GitHub username: ").strip() + clone_dir = input("Enter the directory where you want to clone the repos: ").strip() + + os.makedirs(clone_dir, exist_ok=True) + os.chdir(clone_dir) + + try: + result = subprocess.run( + [ + "gh", "repo", "list", github_user, "--limit", "100", "--json", + "nameWithOwner,isFork,isArchived", "--jq", + ".[] | select(.isFork == false and .isArchived == false) | .nameWithOwner" + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + + if result.returncode != 0: + print("Failed to fetch repositories. Make sure 'gh' is installed and configured.") + print(result.stderr) + return + + repos = result.stdout.strip().splitlines() + except Exception as e: + print(f"Error fetching repositories: {e}") + return + + for repo in repos: + repo = repo.strip() + + repo_name = repo.split("/")[1] if "/" in repo else repo + repo_dir = repo_name.replace("/", "_") # Replace '/' with '_' to avoid invalid directory names + clone_path = os.path.join(clone_dir, repo_dir) + + os.makedirs(clone_path, exist_ok=True) + + clone_command = f"git clone git@github.com:{repo} {clone_path}" + try: + result = subprocess.run( + ["sh", "-c", clone_command], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + + if result.returncode == 0: + print(f"{repo} has been cloned into {clone_path}") + else: + print(f"Failed to clone {repo} into {clone_path}") + print(result.stderr) + except Exception as e: + print(f"Error cloning {repo}: {e}") + + print(f"All repos have been cloned into {clone_dir}") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/clone_repos b/clone_repos deleted file mode 100755 index c39820d..0000000 Binary files a/clone_repos and /dev/null differ diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index cf49434..0000000 --- a/src/main.rs +++ /dev/null @@ -1,77 +0,0 @@ -use std::env; -use std::fs; -use std::io::{self, Write}; -use std::process::Command; - -fn main() -> io::Result<()> { - // Prompt for GitHub username - let mut github_user = String::new(); - print!("Enter your GitHub username: "); - io::stdout().flush()?; - io::stdin().read_line(&mut github_user)?; - let github_user = github_user.trim(); - - // Prompt for directory for cloning - let mut clone_dir = String::new(); - print!("Enter the directory where you want to clone the repos: "); - io::stdout().flush()?; - io::stdin().read_line(&mut clone_dir)?; - let clone_dir = clone_dir.trim(); - - // Create the directory if not present - fs::create_dir_all(clone_dir)?; - - // Navigate to the directory - env::set_current_dir(clone_dir)?; - - // Fetch all repos - let output = Command::new("gh") - .arg("repo") - .arg("list") - .arg(github_user) - .arg("--limit") - .arg("100") - .arg("--json") - .arg("nameWithOwner") - .arg("--jq") - .arg(".[].nameWithOwner") - .output()?; - - if !output.status.success() { - eprintln!("Failed to fetch repositories. Make sure 'gh' is installed and configured."); - return Ok(()); - } - - let repos = String::from_utf8_lossy(&output.stdout); - - for repo in repos.lines() { - let repo = repo.trim(); - - // Extract the repository name (remove the username part) - let repo_name = repo.split('/').nth(1).unwrap_or(repo); - let repo_dir = repo_name.replace('/', "_"); // Replace '/' with '_' to avoid invalid directory names - let clone_path = format!("{}/{}", clone_dir, repo_dir); - - // Create a subdirectory for the repo - fs::create_dir_all(&clone_path)?; - - // Clone the repository into the subdirectory - let clone_command = format!("git clone git@github.com:{} {}", repo, clone_path); - - let status = Command::new("sh") - .arg("-c") - .arg(&clone_command) - .status()?; - - if status.success() { - println!("{} has been cloned into {}", repo, clone_path); - } else { - eprintln!("Failed to clone {} into {}", repo, clone_path); - } - } - - println!("All repos have been cloned into {}", clone_dir); - - Ok(()) -} -