gitlab-org--gitlab-foss/lib/gitlab/github_import/branch_formatter.rb
2016-07-06 13:08:12 -03:00

33 lines
580 B
Ruby

module Gitlab
module GithubImport
class BranchFormatter < BaseFormatter
delegate :repo, :sha, :ref, to: :raw_data
def exists?
branch_exists? && commit_exists?
end
def name
@name ||= exists? ? ref : "#{ref}-#{short_id}"
end
def valid?
repo.present?
end
private
def branch_exists?
project.repository.branch_exists?(ref)
end
def commit_exists?
project.repository.commit(sha).present?
end
def short_id
sha.to_s[0..7]
end
end
end
end