Class: Neetob::CLI::Github::ProtectBranch
- Defined in:
- lib/neetob/cli/github/protect_branch.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#repos ⇒ Object
Returns the value of attribute repos.
-
#repos_integrated_with_semaphore ⇒ Object
Returns the value of attribute repos_integrated_with_semaphore.
-
#required_rules_json_file_path ⇒ Object
Returns the value of attribute required_rules_json_file_path.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(branch_name, repos, required_rules_json_file_path = "", sandbox = false) ⇒ ProtectBranch
constructor
A new instance of ProtectBranch.
- #run ⇒ Object
Methods included from Utils
#camel_case_to_slug, #is_upper?, #symbolize_keys
Constructor Details
#initialize(branch_name, repos, required_rules_json_file_path = "", sandbox = 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, repos, required_rules_json_file_path = "", sandbox = false) super() @branch_name = branch_name @required_rules_json_file_path = required_rules_json_file_path @repos = repos @sandbox = sandbox @repos_integrated_with_semaphore = build_repos_integrated_with_semaphore_list.compact end |
Instance Attribute Details
#branch_name ⇒ Object
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 |
#repos ⇒ Object
Returns the value of attribute repos.
9 10 11 |
# File 'lib/neetob/cli/github/protect_branch.rb', line 9 def repos @repos end |
#repos_integrated_with_semaphore ⇒ Object
Returns the value of attribute repos_integrated_with_semaphore.
9 10 11 |
# File 'lib/neetob/cli/github/protect_branch.rb', line 9 def repos_integrated_with_semaphore @repos_integrated_with_semaphore end |
#required_rules_json_file_path ⇒ Object
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 |
#sandbox ⇒ Object
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
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/neetob/cli/github/protect_branch.rb', line 20 def run matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox) inform_about_default_rules_file matching_repos.each do |repo| ui.info("\n Working on \"#{repo}\" repo") ui.info(" Updating \"#{branch_name}\" branch protection rules") has_semaphore_integrated = repos_integrated_with_semaphore.include?(repo) rules = read_json_file(required_rules_json_file_path || default_rules_file_path) rules.dig("required_status_checks", "contexts")&.clear if !has_semaphore_integrated rules_with_symbol_keys = rules.transform_keys(&:to_sym) client.protect_branch(repo, branch_name, rules_with_symbol_keys) ui.success("Branch protection rules updated successfully") end end |