Class: Neetob::CLI::Github::ProtectBranch

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/github/protect_branch.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from Base

#client

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods inherited from Base

#check_for_apps_and_all_neeto_repos_option

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(branch_name, apps, required_rules_json_file_path = "", sandbox = false, all_neeto_repos = false) ⇒ ProtectBranch

Returns a new instance of ProtectBranch.



11
12
13
14
15
16
17
18
# File 'lib/neetob/cli/github/protect_branch.rb', line 11

def initialize(branch_name, apps, required_rules_json_file_path = "", sandbox = false, all_neeto_repos = false)
  super()
  @branch_name = branch_name
  @required_rules_json_file_path = required_rules_json_file_path
  @apps = apps
  @sandbox = sandbox
  @all_neeto_repos = all_neeto_repos
end

Instance Attribute Details

#all_neeto_reposObject

Returns the value of attribute all_neeto_repos.



9
10
11
# File 'lib/neetob/cli/github/protect_branch.rb', line 9

def all_neeto_repos
  @all_neeto_repos
end

#appsObject

Returns the value of attribute apps.



9
10
11
# File 'lib/neetob/cli/github/protect_branch.rb', line 9

def apps
  @apps
end

#branch_nameObject

Returns the value of attribute branch_name.



9
10
11
# File 'lib/neetob/cli/github/protect_branch.rb', line 9

def branch_name
  @branch_name
end

#required_rules_json_file_pathObject

Returns the value of attribute required_rules_json_file_path.



9
10
11
# File 'lib/neetob/cli/github/protect_branch.rb', line 9

def required_rules_json_file_path
  @required_rules_json_file_path
end

#sandboxObject

Returns the value of attribute sandbox.



9
10
11
# File 'lib/neetob/cli/github/protect_branch.rb', line 9

def sandbox
  @sandbox
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/neetob/cli/github/protect_branch.rb', line 20

def run
  check_for_apps_and_all_neeto_repos_option(apps, all_neeto_repos)
  matching_apps = find_all_matching_apps(apps, :github, sandbox, false, all_neeto_repos)
  inform_about_default_rules_file
  matching_apps.each do |app|
    ui.info("\n Working on \"#{app}\" repo")
    ui.info(" Updating \"#{branch_name}\" branch protection rules")
    rules = read_json_file(required_rules_json_file_path || default_rules_file_path)
    rules_with_symbol_keys = rules.transform_keys(&:to_sym)
    client.protect_branch(app, branch_name, rules_with_symbol_keys)
    ui.success("Branch protection rules updated successfully")
  end
end