2016-05-09 22:45:37 +00:00
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class BranchFormatter < BaseFormatter
|
|
|
|
delegate :repo, :sha, :ref, to: :raw_data
|
|
|
|
|
|
|
|
def exists?
|
2016-07-06 05:52:59 +00:00
|
|
|
branch_exists? && commit_exists?
|
2016-05-09 22:45:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
2016-12-01 02:03:12 +00:00
|
|
|
sha.present? && ref.present?
|
2016-05-09 22:45:37 +00:00
|
|
|
end
|
|
|
|
|
2017-03-16 09:42:58 +00:00
|
|
|
def user
|
2017-03-22 17:45:35 +00:00
|
|
|
raw_data.user&.login || 'unknown'
|
2017-03-16 09:42:58 +00:00
|
|
|
end
|
|
|
|
|
2017-03-26 01:16:27 +00:00
|
|
|
def short_sha
|
|
|
|
Commit.truncate_sha(sha)
|
2017-03-16 21:55:50 +00:00
|
|
|
end
|
|
|
|
|
2016-07-06 05:52:59 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def branch_exists?
|
|
|
|
project.repository.branch_exists?(ref)
|
2016-05-10 21:23:59 +00:00
|
|
|
end
|
|
|
|
|
2016-07-06 05:52:59 +00:00
|
|
|
def commit_exists?
|
2017-03-07 04:10:52 +00:00
|
|
|
project.repository.branch_names_contains(sha).include?(ref)
|
2016-07-06 05:52:59 +00:00
|
|
|
end
|
2016-05-09 22:45:37 +00:00
|
|
|
|
|
|
|
def short_id
|
|
|
|
sha.to_s[0..7]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|