lib/neetob/cli/github/make_pr/compliance_fix.rb in neetob-0.4.6 vs lib/neetob/cli/github/make_pr/compliance_fix.rb in neetob-0.4.7

- old
+ new

@@ -7,49 +7,59 @@ module Neetob class CLI module Github module MakePr class ComplianceFix < Base - attr_accessor :repos, :sandbox, :should_fix_nanos, :labels + attr_accessor :repos, :sandbox, :should_fix_nanos, :labels, :local - def initialize(repos, should_fix_nanos = false, sandbox = false, labels = "") + def initialize(repos, should_fix_nanos = false, sandbox = false, labels = "", local = false) super() @repos = repos @sandbox = sandbox @should_fix_nanos = should_fix_nanos @failed_repos = [] @labels = labels + @local = local end def run matching_repos = build_matching_repos_list(should_fix_nanos) @failed_repos = matching_repos.clone - delete_and_create_temp_neetob_dir + local ? + warn_about_local_repos : + delete_and_create_temp_neetob_dir matching_repos.each do |repo| ui.info("\nWorking on #{repo}\n") begin - shallow_clone_repo_in_tmp_dir(repo) - check_and_delete_remote_branch(repo) - bundle_install(repo) - fix_neeto_audit(repo) - ui.info(add_commmit_and_push_changes(repo)) - delete_local_feature_branch(repo) + if local + unless Dir.exist?("./#{repo_name_without_org_suffix(repo)}") + ui.error("#{repo_name_without_org_suffix(repo)} don't exist in current dir") + next + end + stash_local_changes(repo, local) + end + shallow_clone_repo_in_tmp_dir(repo) if !local + check_and_delete_remote_branch(repo, local) + bundle_install(repo, local) + fix_neeto_audit(repo, local) + ui.info(add_commmit_and_push_changes(repo, local)) + delete_local_feature_branch(repo, local) pull_request = client.create_pull_request(repo, "main", BRANCH_NAME, PR_TITLE) ui.success("PR created in \"#{repo}\" project successfully.") client.add_labels_to_an_issue(repo, pull_request[:number], labels.split(",")) @failed_repos.delete(repo) rescue StandardError => e ExceptionHandler.new(e).process end end print_failed_repos if @failed_repos.length > 0 - `rm -rf /tmp/neetob` + `rm -rf /tmp/neetob` if !local end private - def fix_neeto_audit(repo) - `#{cd_to_repo_in_tmp_dir(repo)} && bundle exec neeto-audit -a` + def fix_neeto_audit(repo, local_repo) + `#{cd_to_repo(repo, local_repo)} && bundle exec neeto-audit -a` end def print_failed_repos ui.info("\nCompliance fix failed for repos:-") @failed_repos.each do |repo|