debian-mirror-gitlab/lib/gitlab/github_import/branch_formatter.rb

38 lines
666 B
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
module Gitlab
module GithubImport
class BranchFormatter < BaseFormatter
delegate :repo, :sha, :ref, to: :raw_data
def exists?
2016-08-24 12:49:21 +05:30
branch_exists? && commit_exists?
2016-06-02 11:05:42 +05:30
end
def valid?
2017-08-17 22:00:37 +05:30
sha.present? && ref.present?
end
def user
raw_data.user&.login || 'unknown'
end
def short_sha
Commit.truncate_sha(sha)
2016-06-02 11:05:42 +05:30
end
2016-08-24 12:49:21 +05:30
private
def branch_exists?
project.repository.branch_exists?(ref)
2016-06-02 11:05:42 +05:30
end
2016-08-24 12:49:21 +05:30
def commit_exists?
2017-08-17 22:00:37 +05:30
project.repository.branch_names_contains(sha).include?(ref)
2016-08-24 12:49:21 +05:30
end
2016-06-02 11:05:42 +05:30
def short_id
sha.to_s[0..7]
end
end
end
end