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
7 changes: 4 additions & 3 deletions src/commands/branch_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::cli::Args as CommonArgs;
use anyhow::Result;

use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Set a branch as default for all repositories that match a pattern
Expand All @@ -31,8 +32,8 @@ impl DefaultBranchArgs {
let repos =
common::query_and_filter_repositories(&organisation, self.regex.as_ref(), &token)?;

for repo in repos {
let result = set_default_branch(&repo, &self.default_branch, &token);
repos.par_iter().for_each(|repo| {
let result = set_default_branch(repo, &self.default_branch, &token);
match result {
Ok(_) => println!(
"Set default branch {} for repo {} successfully",
Expand All @@ -43,7 +44,7 @@ impl DefaultBranchArgs {
self.default_branch, repo.name, e
),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/branch_protect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::Result;

use crate::filter::Filter;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Set a branch as protected for all local repositories that match a pattern
Expand All @@ -32,8 +33,8 @@ impl ProtectedBranchArgs {
let filtered_repos =
common::query_and_filter_repositories(&organisation, self.regex.as_ref(), &user_token)?;

for repo in filtered_repos {
let result = set_protected_branch(&repo, &self.protected_branch, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = set_protected_branch(repo, &self.protected_branch, &user_token);
match result {
Ok(_) => println!(
"Set protected branch {} for repo {} successfully",
Expand All @@ -44,7 +45,7 @@ impl ProtectedBranchArgs {
self.protected_branch, repo.name, e
),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/branch_unprotect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::Result;

use crate::filter::Filter;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Remove branch protection for all local repositories that match a pattern
Expand All @@ -32,8 +33,8 @@ impl UnprotectedBranchArgs {
let filtered_repos =
common::query_and_filter_repositories(&organisation, self.regex.as_ref(), &user_token)?;

for repo in filtered_repos {
let result = set_unprotected_branch(&repo, &self.branch, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = set_unprotected_branch(repo, &self.branch, &user_token);
match result {
Ok(_) => println!(
"Removed protection on branch {} for repo {} successfully",
Expand All @@ -44,7 +45,7 @@ impl UnprotectedBranchArgs {
self.branch, repo.name, e
),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use git2::BranchType;
use crate::commands::topic_helper;
use crate::convert::try_from_one;
use crate::github::RemoteRepo;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Checkout a branch all repositories that their name matches a pattern or
Expand Down Expand Up @@ -68,9 +69,9 @@ impl CheckoutArgs {
return Ok(());
}

for repo in filtered_repos {
filtered_repos.par_iter().for_each(|repo| {
match checkout_branch(
&repo,
repo,
&self.branch,
&user,
"origin",
Expand All @@ -86,7 +87,7 @@ impl CheckoutArgs {
&self.branch, repo.name, e
),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/hook_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::str;

use crate::filter::Filter;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
pub struct CreateArgs {
Expand Down Expand Up @@ -91,9 +92,9 @@ impl CreateArgs {
return Ok(());
}

for repo in filtered_repos {
filtered_repos.par_iter().for_each(|repo| {
match create(
&repo,
repo,
self.url.as_deref(),
self.script.as_ref(),
&self.method,
Expand All @@ -103,7 +104,7 @@ impl CreateArgs {
Ok(response) => println!("Success with response {:?}", response),
Err(e) => println!("Failed because {:?}", e),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/hook_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str;

use crate::filter::Filter;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Delete ALL web hooks for all repositories that match given regex
Expand Down Expand Up @@ -38,8 +39,8 @@ impl DeleteArgs {
return Ok(());
}

for repo in filtered_repos {
let result = delete_all_hooks(&repo, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = delete_all_hooks(repo, &user_token);

match result {
Ok(n) => println!("Successfully deleted {} hook(s) of repo {}", n, repo.name),
Expand All @@ -48,7 +49,7 @@ impl DeleteArgs {
repo.name, e
),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/set_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::{anyhow, Result};

use crate::filter::Filter;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Set description and/or website for all repositories that match regex
Expand Down Expand Up @@ -48,13 +49,13 @@ impl InfoArgs {
let filtered_repos =
common::query_and_filter_repositories(&organisation, Some(&self.regex), &user_token)?;

for repo in filtered_repos {
let result = set_info(&repo, self, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = set_info(repo, self, &user_token);
match result {
Ok(_) => println!("Set info for repo {} successfully", repo.name),
Err(e) => println!("Failed to set info for repo {} because {:?}", repo.name, e),
}
}
});
Ok(())
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/set_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::github::RemoteRepo;
use anyhow::{Context, Result};
use clap::Parser;
use dryoc::dryocbox::{DryocBox, PublicKey};
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Set a secret all repositories that match regex
Expand Down Expand Up @@ -36,16 +37,16 @@ impl SecretArgs {
let filtered_repos =
common::query_and_filter_repositories(&organisation, Some(&self.regex), &user_token)?;

for repo in filtered_repos {
let result = set_secret(&repo, &self.value, &self.name, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = set_secret(repo, &self.value, &self.name, &user_token);
match result {
Ok(_) => println!("Set secret value for repo {} successfully", repo.name),
Err(e) => println!(
"Failed to set secret value for repo {} because {:?}",
repo.name, e
),
}
}
});
Ok(())
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/set_team_permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Result;

use crate::filter::Filter;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
pub struct SetTeamPermissionArgs {
Expand Down Expand Up @@ -37,7 +38,7 @@ impl SetTeamPermissionArgs {
let filtered_repos =
common::query_and_filter_repositories(&organisation, self.regex.as_ref(), &user_token)?;

for repo in filtered_repos {
filtered_repos.par_iter().for_each(|repo| {
let result = github::set_team_permission(
&organisation,
&self.team_slug,
Expand All @@ -56,7 +57,7 @@ impl SetTeamPermissionArgs {
self.team_slug, self.permission, repo.name, e
),
}
}
});

Ok(())
}
Expand Down
19 changes: 10 additions & 9 deletions src/commands/template/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::path;
use anyhow::{anyhow, Result};
use clap::Parser;
use git2::Repository;
use rayon::prelude::*;
use std::fs::{create_dir_all, write, File};
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
Expand Down Expand Up @@ -54,33 +55,33 @@ impl ApplyArgs {

if self.finish {
// finish apply process
for dir in target_dirs {
match continue_apply(&dir, !self.force_ci) {
target_dirs.par_iter().for_each(|dir| {
match continue_apply(dir, !self.force_ci) {
Ok(_) => println!("Apply changes finish successfully"),
Err(e) => println!("Apply changes finish failed because {:?}", e),
}
}
});
} else if self.abort {
// finish apply process
for dir in target_dirs {
match abort_apply(&dir) {
target_dirs.par_iter().for_each(|dir| {
match abort_apply(dir) {
Ok(_) => println!("Abort Apply process success"),
Err(e) => println!("Abort Apply failed because {:?}", e),
}
}
});
} else {
// start apply process
let template_delta =
TemplateDelta::get(&self.template.path.join(".gut/template.toml"))?;

// println!("template delta {:?}", template_delta);

for dir in target_dirs {
match start_apply(&self.template.path, &template_delta, &dir, self.optional) {
target_dirs.par_iter().for_each(|dir| {
match start_apply(&self.template.path, &template_delta, dir, self.optional) {
Ok(_) => println!("Applied changes success. Please resolve conflict and use \"git add\" to add all changes before continue."),
Err(e) => println!("Applied changes failed {:?}\n Please use \"--abort\" option to abort the process.", e),
}
}
});
}

Ok(())
Expand Down
7 changes: 4 additions & 3 deletions src/commands/topic_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::filter::Filter;
use crate::github;
use anyhow::Result;
use clap::Parser;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Add topics for all repositories that match a regex
Expand Down Expand Up @@ -37,8 +38,8 @@ impl TopicAddArgs {
return Ok(());
}

for repo in filtered_repos {
let result = add_topics(&repo, &self.topics, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = add_topics(repo, &self.topics, &user_token);
match result {
Ok(topics) => {
println!("Add topics for repo {} successfully", repo.name);
Expand All @@ -49,7 +50,7 @@ impl TopicAddArgs {
repo.name, e
),
}
}
});
Ok(())
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/topic_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::github::RemoteRepoWithTopics;
use crate::user::User;
use anyhow::Result;
use clap::Parser;
use rayon::prelude::*;
use std::process::Output;

/// Apply a script to all repositories that has a topics that match a pattern
Expand Down Expand Up @@ -52,12 +53,12 @@ impl TopicApplyArgs {

println!("repos {:?}", repos);

for repo in repos {
match apply(&repo, script_path, &user, self.use_https) {
repos.par_iter().for_each(|repo| {
match apply(repo, script_path, &user, self.use_https) {
Ok(_) => println!("Apply success"),
Err(e) => println!("Apply failed because {:?}", e),
}
}
});

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/topic_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::github;
use anyhow::Result;
use clap::Parser;
use crate::cli::Args as CommonArgs;
use rayon::prelude::*;

#[derive(Debug, Parser)]
/// Get topics for all repositories that match a regex
Expand Down Expand Up @@ -34,8 +35,8 @@ impl TopicGetArgs {
return Ok(());
}

for repo in filtered_repos {
let result = github::get_topics(&repo, &user_token);
filtered_repos.par_iter().for_each(|repo| {
let result = github::get_topics(repo, &user_token);
match result {
Ok(topics) => {
println!("List of topics for {} is: {:?}", repo.name, topics);
Expand All @@ -45,7 +46,7 @@ impl TopicGetArgs {
repo.name, e
),
}
}
});
Ok(())
}
}
Loading