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

40 lines
703 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
module Gitlab
2018-03-17 18:26:18 +05:30
module LegacyGithubImport
2016-06-02 11:05:42 +05:30
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