Class: Neetob::CLI::Github::MakePr::Script

Inherits:
Base show all
Defined in:
lib/neetob/cli/github/make_pr/script.rb

Constant Summary

Constants inherited from Base

Base::BRANCH_NAME, Base::PR_TITLE

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from Base

#branch_name, #pr_title

Attributes inherited from Base

#client

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#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) ⇒ Script

Returns a new instance of Script.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/neetob/cli/github/make_pr/script.rb', line 15

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

Instance Attribute Details

#labelsObject

Returns the value of attribute labels.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def labels
  @labels
end

#localObject

Returns the value of attribute local.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def local
  @local
end

#path_to_the_script_fileObject

Returns the value of attribute path_to_the_script_file.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def path_to_the_script_file
  @path_to_the_script_file
end

#pr_descriptionObject

Returns the value of attribute pr_description.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def pr_description
  @pr_description
end

#reposObject

Returns the value of attribute repos.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def repos
  @repos
end

#sandboxObject

Returns the value of attribute sandbox.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def sandbox
  @sandbox
end

#should_fix_frontend_packagesObject

Returns the value of attribute should_fix_frontend_packages.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def should_fix_frontend_packages
  @should_fix_frontend_packages
end

#should_fix_nanosObject

Returns the value of attribute should_fix_nanos.



12
13
14
# File 'lib/neetob/cli/github/make_pr/script.rb', line 12

def should_fix_nanos
  @should_fix_nanos
end

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/neetob/cli/github/make_pr/script.rb', line 29

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