From d0336ae88f9ed7bfee1f74d8945e4f8770d0b9b0 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 23 Mar 2019 07:24:44 -0700 Subject: GitHub importer: Use the project creator to create branches from forks The project owner may actually be a group, in which case the branch creation would fail due to a lack of username. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59396 --- changelogs/unreleased/sh-fix-github-import-creator.yml | 5 +++++ lib/gitlab/github_import/importer/pull_request_importer.rb | 2 +- .../lib/gitlab/github_import/importer/pull_request_importer_spec.rb | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/sh-fix-github-import-creator.yml diff --git a/changelogs/unreleased/sh-fix-github-import-creator.yml b/changelogs/unreleased/sh-fix-github-import-creator.yml new file mode 100644 index 00000000000..6159c1fa321 --- /dev/null +++ b/changelogs/unreleased/sh-fix-github-import-creator.yml @@ -0,0 +1,5 @@ +--- +title: 'GitHub importer: Use the project creator to create branches from forks' +merge_request: 26510 +author: +type: fixed diff --git a/lib/gitlab/github_import/importer/pull_request_importer.rb b/lib/gitlab/github_import/importer/pull_request_importer.rb index 72451e5e01e..1b293ddc7c7 100644 --- a/lib/gitlab/github_import/importer/pull_request_importer.rb +++ b/lib/gitlab/github_import/importer/pull_request_importer.rb @@ -89,7 +89,7 @@ module Gitlab return if project.repository.branch_exists?(source_branch) - project.repository.add_branch(project.owner, source_branch, pull_request.source_branch_sha) + project.repository.add_branch(project.creator, source_branch, pull_request.source_branch_sha) rescue Gitlab::Git::CommandError => e Gitlab::Sentry.track_acceptable_exception(e, extra: { diff --git a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb index 37c3fae7cb7..680de47de2b 100644 --- a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb @@ -273,10 +273,10 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi mr.state = 'opened' mr.save - # Ensure the project owner is creating the branches because the + # Ensure the project creator is creating the branches because the # merge request author may not have access to push to this - # repository. - allow(project.repository).to receive(:add_branch).with(project.owner, anything, anything).and_call_original + # repository. The project owner may also be a group. + allow(project.repository).to receive(:add_branch).with(project.creator, anything, anything).and_call_original importer.insert_git_data(mr, exists) -- cgit v1.2.1