diff options
author | Robert Speicher <robert@gitlab.com> | 2017-04-03 14:18:00 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-04-03 14:18:00 +0000 |
commit | 41396031162ab62cfac2837acdfcc200e74fda73 (patch) | |
tree | f2c2c8ce84401f1c34e59c6ca96933b451aa19ac /lib | |
parent | ff3703f5e6e386d28790c3b395341bcf15b04c13 (diff) | |
parent | d5f340943e76f952fb566509ea7bc9aefcedf6fd (diff) | |
download | gitlab-ce-41396031162ab62cfac2837acdfcc200e74fda73.tar.gz |
Merge branch '29541-fix-github-importer-deleted-fork' into 'master'
Fix GitHub importer for PRs of deleted forked repositories
Closes #29541
See merge request !9992
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/github_import/branch_formatter.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/github_import/pull_request_formatter.rb | 33 |
2 files changed, 30 insertions, 11 deletions
diff --git a/lib/gitlab/github_import/branch_formatter.rb b/lib/gitlab/github_import/branch_formatter.rb index 5d29e698b27..8aa885fb811 100644 --- a/lib/gitlab/github_import/branch_formatter.rb +++ b/lib/gitlab/github_import/branch_formatter.rb @@ -11,6 +11,14 @@ module Gitlab 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? diff --git a/lib/gitlab/github_import/pull_request_formatter.rb b/lib/gitlab/github_import/pull_request_formatter.rb index add7236e339..38660a7ccca 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 :exists?, :project, :ref, :repo, :sha, to: :source_branch, prefix: true - delegate :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 { @@ -37,13 +37,20 @@ module Gitlab end def source_branch_name - @source_branch_name ||= begin - if cross_project? - "pull/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}" + @source_branch_name ||= + if cross_project? || !source_branch_exists? + source_branch_name_prefixed else - source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}" + source_branch_ref end - end + end + + def source_branch_name_prefixed + "gh-#{target_branch_short_sha}/#{number}/#{source_branch_user}/#{source_branch_ref}" + end + + def source_branch_exists? + !cross_project? && source_branch.exists? end def target_branch @@ -51,13 +58,17 @@ module Gitlab end def target_branch_name - @target_branch_name ||= begin - target_branch_exists? ? target_branch_ref : "pull/#{number}/#{target_branch_ref}" - end + @target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed + end + + def target_branch_name_prefixed + "gl-#{target_branch_short_sha}/#{number}/#{target_branch_user}/#{target_branch_ref}" end def cross_project? - source_branch.repo.id != target_branch.repo.id + return true if source_branch_repo.nil? + + source_branch_repo.id != target_branch_repo.id end def opened? |