# frozen_string_literal: true require "thor" require_relative "base" module Neetob class CLI module Github module MakePr class Script < Base attr_accessor :repos, :sandbox, :path_to_the_script_file, :pr_description, :should_fix_nanos, :should_fix_frontend_packages, :labels, :local def initialize(repos, path_to_the_script_file, pr_title, branch_name, pr_description, should_fix_nanos, should_fix_frontend_packages = false, sandbox = false, labels = "", local = false) super(pr_title, branch_name) @repos = repos @sandbox = sandbox @path_to_the_script_file = path_to_the_script_file @pr_description = pr_description @should_fix_nanos = should_fix_nanos @should_fix_frontend_packages = should_fix_frontend_packages @labels = labels @local = local end def run matching_repos = build_matching_repos_list(should_fix_nanos, should_fix_frontend_packages) local ? warn_about_local_repos : delete_and_create_temp_neetob_dir matching_repos.each do |repo| ui.info("\n Working on #{repo} \n") begin 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) update_script_file_permissions execute_script(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, pr_description) ui.success("PR created in \"#{repo}\" project successfully.") client.add_labels_to_an_issue(repo, pull_request[:number], labels.split(",")) rescue StandardError => e ExceptionHandler.new(e).process end end `rm -rf /tmp/neetob` if !local end private def update_script_file_permissions `chmod +x #{path_to_the_script_file}` end def execute_script(repo, local_repo) `#{cd_to_repo(repo, local_repo)} && #{path_to_the_script_file}` end end end end end end