diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb index b33923dd80c3ee2f8e24b1eb5f810a2178e7c17a..aa164f1a61a1e3315e0286584c7f20ba75b7b5de 100644 --- a/lib/gitlab/bitbucket_server_import/importer.rb +++ b/lib/gitlab/bitbucket_server_import/importer.rb @@ -2,6 +2,7 @@ module Gitlab module BitbucketServerImport class Importer include Gitlab::ShellAdapter + attr_reader :recover_missing_commits attr_reader :project, :project_key, :repository_slug, :client, :errors, :users REMOTE_NAME = 'bitbucket_server'.freeze @@ -17,8 +18,14 @@ module Gitlab [:heads, :tags, '+refs/pull-requests/*/to:refs/merge-requests/*/head'] end - def initialize(project) + # Unlike GitHub, you can't grab the commit SHAs for pull requests that + # have been closed but not merged even though Bitbucket has these + # commits internally. We can recover these pull requests by creating a + # branch with the Bitbucket REST API, but by default we turn this + # behavior off. + def initialize(project, recover_missing_commits: false) @project = project + @recover_missing_commits = recover_missing_commits @project_key = project.import_data.data['project_key'] @repository_slug = project.import_data.data['repo_slug'] @client = BitbucketServer::Client.new(project.import_data.credentials) @@ -141,7 +148,7 @@ module Gitlab # may take a number of network round-trips. Do this in batches so that we can # avoid doing a git fetch for every new branch. pull_requests.each_slice(BATCH_SIZE) do |batch| - restore_branches(batch) + restore_branches(batch) if recover_missing_commits batch.each do |pull_request| begin diff --git a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb index 5c9767bcfec155739f75de166c8f0bc2f3aad65b..20b0dcdd8a04e49726ea1139d94810e3583500a6 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::BitbucketServerImport::Importer do let(:repo_slug) { 'rouge' } let(:sample) { RepoHelpers.sample_compare } - subject { described_class.new(project) } + subject { described_class.new(project, recover_missing_commits: true) } before do data = project.create_or_update_import_data(