Class: Octorule::Services::BranchProtection

Inherits:
Object
  • Object
show all
Defined in:
lib/octorule/services/branch_protection.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ BranchProtection

Returns a new instance of BranchProtection.



6
7
8
# File 'lib/octorule/services/branch_protection.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#update(org, repo, branch, settings, dry_run: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/octorule/services/branch_protection.rb', line 10

def update(org, repo, branch, settings, dry_run: false)
  if dry_run
    puts "Would update branch protection for #{branch} in #{repo}:"
    settings.each { |k, v| puts "    #{k}: #{v}" }
  else
    @client.protect_branch("#{org}/#{repo}", branch, settings)
    puts "Successfully updated branch protection for #{branch} in #{repo}"
  end
rescue Octokit::Error => e
  warn "Failed to update branch protection for #{branch} in #{repo}: #{e.message}"
end