GitHub import: Create new branches as project owner

This avoids permission errors when importing merge requests whose
authors don't have direct access to push to the main repository.
This commit is contained in:
Stan Hu 2019-03-19 10:07:05 -07:00
parent 934253c947
commit 1e6ea914a1
3 changed files with 11 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
title: 'GitHub import: Create new branches as project owner'
merge_request: 26335
author:
type: fixed

View File

@ -89,7 +89,7 @@ module Gitlab
return if project.repository.branch_exists?(source_branch)
project.repository.add_branch(merge_request.author, source_branch, pull_request.source_branch_sha)
project.repository.add_branch(project.owner, source_branch, pull_request.source_branch_sha)
rescue Gitlab::Git::CommandError => e
Gitlab::Sentry.track_acceptable_exception(e,
extra: {

View File

@ -273,6 +273,11 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi
mr.state = 'opened'
mr.save
# Ensure the project owner 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
importer.insert_git_data(mr, exists)
expect(project.repository.branch_exists?(mr.source_branch)).to be_truthy