Sha256: 15c542589210693c1e88d61751a82fa727be6b01ef57c94f958f01a7f74aa993

Contents?: true

Size: 1.93 KB

Versions: 5

Compression:

Stored size: 1.93 KB

Contents

# 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

          def initialize(repos, path_to_the_script_file, pr_title,
            branch_name, pr_description, should_fix_nanos, sandbox = 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
          end

          def run
            matching_repos = should_fix_nanos ?
              add_org_suffix(find_all_matching_gems) :
              find_all_matching_apps_or_repos(repos, :github, sandbox)
            delete_and_create_temp_neetob_dir
            matching_repos.each do |repo|
              ui.info("\n  Working on #{repo}  \n")
              begin
                clone_repo_in_tmp_dir(repo)
                check_and_delete_remote_branch(repo)
                update_script_file_permissions
                execute_script(repo)
                ui.info(add_commmit_and_push_changes(repo))
                delete_local_feature_branch(repo)
                res = client.create_pull_request(repo, "main", branch_name, pr_title, pr_description)
                ui.success("PR created in \"#{repo}\" project successfully.")
              rescue StandardError => e
                ExceptionHandler.new(e).process
              end
            end
            `rm -rf /tmp/neetob`
          end

          private

            def update_script_file_permissions
              `chmod +x #{path_to_the_script_file}`
            end

            def execute_script(repo)
              `#{cd_to_repo_in_tmp_dir(repo)} && #{path_to_the_script_file}`
            end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
neetob-0.2.7 lib/neetob/cli/github/make_pr/script.rb
neetob-0.2.6 lib/neetob/cli/github/make_pr/script.rb
neetob-0.2.5 lib/neetob/cli/github/make_pr/script.rb
neetob-0.2.4 lib/neetob/cli/github/make_pr/script.rb
neetob-0.2.3 lib/neetob/cli/github/make_pr/script.rb