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

#access_token, #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(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_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

#reposObject

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_semaphoreObject

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_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
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