summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-03-16 18:55:50 -0300
committerGabriel Mazetto <brodock@gmail.com>2017-04-03 12:45:31 +0200
commit59588ebac012e0bb300d1d7660f5a7360ace5e4e (patch)
treeada48ce0153a7645a8c34f7c6449648fb92bde2d /lib/gitlab
parenta3e65ef021c3c1ba90adf58654c2856001cf009a (diff)
downloadgitlab-ce-59588ebac012e0bb300d1d7660f5a7360ace5e4e.tar.gz
Prefixes source branch name with short SHA to avoid collision
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/github_import/branch_formatter.rb4
-rw-r--r--lib/gitlab/github_import/pull_request_formatter.rb22
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/gitlab/github_import/branch_formatter.rb b/lib/gitlab/github_import/branch_formatter.rb
index 48bed8fc296..18200809637 100644
--- a/lib/gitlab/github_import/branch_formatter.rb
+++ b/lib/gitlab/github_import/branch_formatter.rb
@@ -15,6 +15,10 @@ module Gitlab
raw_data.user.login
end
+ def short_sha(length = 7)
+ sha.to_s[0..length]
+ end
+
private
def branch_exists?
diff --git a/lib/gitlab/github_import/pull_request_formatter.rb b/lib/gitlab/github_import/pull_request_formatter.rb
index 3326fe4bf18..bc24c6de120 100644
--- a/lib/gitlab/github_import/pull_request_formatter.rb
+++ b/lib/gitlab/github_import/pull_request_formatter.rb
@@ -1,8 +1,8 @@
module Gitlab
module GithubImport
class PullRequestFormatter < IssuableFormatter
- delegate :user, :exists?, :project, :ref, :repo, :sha, to: :source_branch, prefix: true
- delegate :user, :exists?, :project, :ref, :repo, :sha, to: :target_branch, prefix: true
+ delegate :user, :project, :ref, :repo, :sha, to: :source_branch, prefix: true
+ delegate :user, :exists?, :project, :ref, :repo, :sha, :short_sha, to: :target_branch, prefix: true
def attributes
{
@@ -39,17 +39,17 @@ module Gitlab
def source_branch_name
@source_branch_name ||= begin
if cross_project?
- if source_branch_repo
- "pull/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}"
- else
- "pull/#{number}/#{source_branch_user}/#{source_branch_ref}"
- end
+ source_branch_name_prefixed
else
- source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}"
+ source_branch_exists? ? source_branch_ref : source_branch_name_prefixed
end
end
end
+ def source_branch_name_prefixed
+ "gh-#{target_branch_short_sha}/#{number}"
+ end
+
def source_branch_exists?
return false if cross_project?
@@ -62,10 +62,14 @@ module Gitlab
def target_branch_name
@target_branch_name ||= begin
- target_branch_exists? ? target_branch_ref : "pull/#{number}/#{target_branch_ref}"
+ target_branch_exists? ? target_branch_ref : target_branch_name_prefixed
end
end
+ def target_branch_name_prefixed
+ "gl-#{target_branch_short_sha}/#{number}"
+ end
+
def cross_project?
return true if source_branch_repo.nil?