summaryrefslogtreecommitdiff
path: root/lib/gitlab/legacy_github_import/branch_formatter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/legacy_github_import/branch_formatter.rb')
-rw-r--r--lib/gitlab/legacy_github_import/branch_formatter.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/legacy_github_import/branch_formatter.rb b/lib/gitlab/legacy_github_import/branch_formatter.rb
new file mode 100644
index 00000000000..80fe1d67209
--- /dev/null
+++ b/lib/gitlab/legacy_github_import/branch_formatter.rb
@@ -0,0 +1,37 @@
+module Gitlab
+ module LegacyGithubImport
+ class BranchFormatter < BaseFormatter
+ delegate :repo, :sha, :ref, to: :raw_data
+
+ def exists?
+ branch_exists? && commit_exists?
+ end
+
+ def valid?
+ sha.present? && ref.present?
+ end
+
+ def user
+ raw_data.user&.login || 'unknown'
+ end
+
+ def short_sha
+ Commit.truncate_sha(sha)
+ end
+
+ private
+
+ def branch_exists?
+ project.repository.branch_exists?(ref)
+ end
+
+ def commit_exists?
+ project.repository.branch_names_contains(sha).include?(ref)
+ end
+
+ def short_id
+ sha.to_s[0..7]
+ end
+ end
+ end
+end