class GH::MergeCommit

Public: …

Public Instance Methods

modify_hash(hash) click to toggle source
Calls superclass method
# File lib/gh/merge_commit.rb, line 15
def modify_hash(hash)
  setup_lazy_loading(super)
rescue Exception => error
  raise Error.new(error, hash)
end
setup(backend, options) click to toggle source
Calls superclass method
# File lib/gh/merge_commit.rb, line 10
def setup(backend, options)
  @ssl = options[:ssl]
  super
end

Private Instance Methods

commit_for(from, hash) click to toggle source
# File lib/gh/merge_commit.rb, line 34
def commit_for(from, hash)
  { 'sha' => hash['sha'], 'ref' => hash['ref'],
    '_links' => { 'self' => { 'href' => git_url_for(from, hash['sha']) } } }
end
force_merge_commit(hash) click to toggle source
# File lib/gh/merge_commit.rb, line 68
def force_merge_commit(hash)
  Timeout.timeout(180) do
    update(hash) until github_done_checking? hash
  end
rescue TimeoutError
  status = hash['mergeable_state'].inspect
  raise TimeoutError, "gave up waiting for github to check the merge status (current status is #{status})"
end
git_url_for(hash, commitish) click to toggle source
# File lib/gh/merge_commit.rb, line 39
def git_url_for(hash, commitish)
  hash['_links']['self']['href'].gsub(%r{/pulls/(\d+)$}, "/git/#{commitish}")
end
github_done_checking?(hash) click to toggle source
# File lib/gh/merge_commit.rb, line 59
def github_done_checking?(hash)
  case hash['mergeable_state']
  when 'checking'                                                  then false
  when 'unknown'                                                   then hash['merged']
  when 'clean', 'dirty', 'unstable', 'stable', 'blocked', 'behind' then true
  else fail "unknown mergeable_state #{hash['mergeable_state'].inspect} for #{url(hash)}"
  end
end
has_merge_commit?(hash) click to toggle source
# File lib/gh/merge_commit.rb, line 54
def has_merge_commit?(hash)
  force_merge_commit(hash)
  hash['mergeable']
end
lazy_load(hash, key) click to toggle source
# File lib/gh/merge_commit.rb, line 23
def lazy_load(hash, key)
  return unless key =~ /^(merge|head|base)_commit$/ and hash.include? 'mergeable'
  return unless has_merge_commit?(hash)
  fields = pull_request_refs(hash)
  fields['base_commit'] ||= commit_for hash, hash['base']
  fields['head_commit'] ||= commit_for hash, hash['head']
  fields
rescue Exception => error
  raise Error.new(error, hash)
end
pull_request_refs(hash) click to toggle source
# File lib/gh/merge_commit.rb, line 43
def pull_request_refs(hash)
  link     = git_url_for(hash, 'refs/pull/\1')
  commits  = self[link].map do |data|
    ref    = data['ref']
    name   = ref.split('/').last + "_commit"
    object = data['object'].merge 'ref' => ref
    [name, object]
  end
  Hash[commits]
end
update(hash) click to toggle source
# File lib/gh/merge_commit.rb, line 77
def update(hash)
  hash.merge! backend[url(hash)]
  sleep 0.5
end
url(hash) click to toggle source
# File lib/gh/merge_commit.rb, line 82
def url(hash)
  hash['_links']['self']['href']
end