branch_formatter.rb 703 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
module Gitlab
4
  module LegacyGithubImport
5 6 7 8
    class BranchFormatter < BaseFormatter
      delegate :repo, :sha, :ref, to: :raw_data

      def exists?
9
        branch_exists? && commit_exists?
10 11 12
      end

      def valid?
13
        sha.present? && ref.present?
14 15
      end

16
      def user
17
        raw_data.user&.login || 'unknown'
18 19
      end

Gabriel Mazetto's avatar
Gabriel Mazetto committed
20 21
      def short_sha
        Commit.truncate_sha(sha)
22 23
      end

24 25 26 27
      private

      def branch_exists?
        project.repository.branch_exists?(ref)
28 29
      end

30
      def commit_exists?
31
        project.repository.branch_names_contains(sha).include?(ref)
32
      end
33 34 35 36 37 38 39

      def short_id
        sha.to_s[0..7]
      end
    end
  end
end