diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-05-09 16:17:05 -0500 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-05-13 17:55:42 -0500 |
commit | e001bd5e3d813fa72f724fc0e661b36099f678ea (patch) | |
tree | c0fb3c1e97ebc2303e3c2c098c1e81c8f7b45a03 /lib/gitlab/github_import | |
parent | 7e1f14e21517d3907a0e096d44b30797612f69cd (diff) | |
download | gitlab-ce-e001bd5e3d813fa72f724fc0e661b36099f678ea.tar.gz |
Import PRs where branch names were reused across PRs
Diffstat (limited to 'lib/gitlab/github_import')
-rw-r--r-- | lib/gitlab/github_import/pull_request_formatter.rb | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/gitlab/github_import/pull_request_formatter.rb b/lib/gitlab/github_import/pull_request_formatter.rb index 3b541a04d5c..9f8182f643e 100644 --- a/lib/gitlab/github_import/pull_request_formatter.rb +++ b/lib/gitlab/github_import/pull_request_formatter.rb @@ -30,11 +30,19 @@ module Gitlab end def source_branch_exists? - source_project.repository.branch_names.include?(source_branch) + source_project.repository.branch_exists?(source_ref) end def source_branch - raw_data.head.ref + @source_branch ||= if source_branch_exists? + source_ref + else + "#{source_ref}-#{short_id(source_sha)}" + end + end + + def short_id(sha, length = 7) + sha.to_s[0..length] end def source_sha @@ -42,11 +50,15 @@ module Gitlab end def target_branch_exists? - target_project.repository.branch_names.include?(target_branch) + target_project.repository.branch_exists?(target_ref) end def target_branch - raw_data.base.ref + @target_branch ||= if target_branch_exists? + target_ref + else + "#{target_ref}-#{short_id(target_sha)}" + end end def target_sha @@ -99,6 +111,10 @@ module Gitlab raw_data.head.repo end + def source_ref + raw_data.head.ref + end + def target_project project end @@ -107,6 +123,10 @@ module Gitlab raw_data.base.repo end + def target_ref + raw_data.base.ref + end + def state @state ||= case true when raw_data.state == 'closed' && raw_data.merged_at.present? |