Class: Gitlab::BitbucketServerImport::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/bitbucket_server_import/importer.rb

Defined Under Namespace

Classes: TempBranch

Constant Summary collapse

BATCH_SIZE =
100
ALREADY_IMPORTED_CACHE_KEY =

The base cache key to use for tracking already imported objects.

'bitbucket_server-importer/already-imported/%{project}/%{collection}'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, recover_missing_commits: false) ⇒ Importer

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.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 31

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)
  @formatter = Gitlab::ImportFormatter.new
  @errors = []
  @users = {}
  @temp_branches = []
  @logger = Gitlab::Import::Logger.build
  @already_imported_cache_key = ALREADY_IMPORTED_CACHE_KEY %
    { project: project.id, collection: collection_method }
end

Instance Attribute Details

#already_imported_cache_keyObject (readonly)

Returns the value of attribute already_imported_cache_key.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def already_imported_cache_key
  @already_imported_cache_key
end

#clientObject (readonly)

Returns the value of attribute client.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def client
  @client
end

#errorsObject (readonly)

Returns the value of attribute errors.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def errors
  @errors
end

#loggerObject

Returns the value of attribute logger.


8
9
10
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 8

def logger
  @logger
end

#projectObject (readonly)

Returns the value of attribute project.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def project
  @project
end

#project_keyObject (readonly)

Returns the value of attribute project_key.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def project_key
  @project_key
end

#recover_missing_commitsObject (readonly)

Returns the value of attribute recover_missing_commits.


6
7
8
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 6

def recover_missing_commits
  @recover_missing_commits
end

#repository_slugObject (readonly)

Returns the value of attribute repository_slug.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def repository_slug
  @repository_slug
end

#usersObject (readonly)

Returns the value of attribute users.


7
8
9
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 7

def users
  @users
end

Class Method Details

.imports_repository?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 17

def self.imports_repository?
  true
end

.refmapObject


21
22
23
24
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 21

def self.refmap
  # We omit :heads and :tags since these are fetched in the import_repository
  ['+refs/pull-requests/*/to:refs/merge-requests/*/head']
end

Instance Method Details

#collection_methodObject


46
47
48
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 46

def collection_method
  :pull_requests
end

#executeObject


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitlab/bitbucket_server_import/importer.rb', line 50

def execute
  import_repository
  import_pull_requests
  download_lfs_objects
  delete_temp_branches
  handle_errors
  metrics.track_finished_import

  log_info(stage: "complete")

  Gitlab::Cache::Import::Caching.expire(already_imported_cache_key, Gitlab::Cache::Import::Caching::SHORTER_TIMEOUT)
  true
end