2016-05-09 18:45:37 -04:00
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class BranchFormatter < BaseFormatter
|
|
|
|
delegate :repo, :sha, :ref, to: :raw_data
|
|
|
|
|
|
|
|
def exists?
|
2016-07-06 01:52:59 -04:00
|
|
|
branch_exists? && commit_exists?
|
2016-05-09 18:45:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
2016-11-30 21:03:12 -05:00
|
|
|
sha.present? && ref.present?
|
2016-05-09 18:45:37 -04:00
|
|
|
end
|
|
|
|
|
2016-07-06 01:52:59 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def branch_exists?
|
|
|
|
project.repository.branch_exists?(ref)
|
2016-05-10 17:23:59 -04:00
|
|
|
end
|
|
|
|
|
2016-07-06 01:52:59 -04:00
|
|
|
def commit_exists?
|
2017-03-06 23:10:52 -05:00
|
|
|
project.repository.branch_names_contains(sha).include?(ref)
|
2016-07-06 01:52:59 -04:00
|
|
|
end
|
2016-05-09 18:45:37 -04:00
|
|
|
|
|
|
|
def short_id
|
|
|
|
sha.to_s[0..7]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|