travis-api/lib/travis/model/commit.rb
Aakriti Gupta 65f1a29d86 Move travis-core files from /vendor to /lib.
- Re-factor
- Remove code for notifications
- Remove addons
- Remove travis-core gem.
- Ignore logs directory only
- Move core tests to spec/lib
2016-07-20 11:22:25 +02:00

29 lines
651 B
Ruby

require 'travis/model'
# Encapsulates a commit that a Build belongs to (and that a Github Request
# referred to).
class Commit < Travis::Model
has_one :request
belongs_to :repository
validates :commit, :branch, :committed_at, :presence => true
def pull_request?
ref =~ %r(^refs/pull/\d+/merge$)
end
def pull_request_number
if pull_request? && (num = ref.scan(%r(^refs/pull/(\d+)/merge$)).flatten.first)
num.to_i
end
end
def range
if pull_request?
"#{request.base_commit}...#{request.head_commit}"
elsif compare_url && compare_url =~ /\/([0-9a-f]+\^*\.\.\.[0-9a-f]+\^*$)/
$1
end
end
end