Class: Gitlab::BitbucketImport::Importer

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

Constant Summary collapse

LABELS =
[{ title: 'bug', color: '#FF0000' },
{ title: 'enhancement', color: '#428BCA' },
{ title: 'proposal', color: '#69D100' },
{ title: 'task', color: '#7F8C8D' }].freeze
ALREADY_IMPORTED_CACHE_KEY =
'bitbucket_cloud-importer/already-imported/%{project}/%{collection}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Importer

Returns a new instance of Importer.



15
16
17
18
19
20
21
22
# File 'lib/gitlab/bitbucket_import/importer.rb', line 15

def initialize(project)
  @project = project
  @client = Bitbucket::Client.new(project.import_data.credentials)
  @formatter = Gitlab::ImportFormatter.new
  @labels = {}
  @errors = []
  @users = {}
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/gitlab/bitbucket_import/importer.rb', line 11

def client
  @client
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/gitlab/bitbucket_import/importer.rb', line 11

def errors
  @errors
end

#projectObject (readonly)

Returns the value of attribute project.



11
12
13
# File 'lib/gitlab/bitbucket_import/importer.rb', line 11

def project
  @project
end

#usersObject (readonly)

Returns the value of attribute users.



11
12
13
# File 'lib/gitlab/bitbucket_import/importer.rb', line 11

def users
  @users
end

Instance Method Details

#create_labelsObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/bitbucket_import/importer.rb', line 34

def create_labels
  LABELS.each do |label_params|
    label = ::Labels::FindOrCreateService.new(nil, project, label_params).execute(skip_authorization: true)
    if label.valid?
      @labels[label_params[:title]] = label
    else
      raise "Failed to create label \"#{label_params[:title]}\" for project \"#{project.full_name}\""
    end
  end
end

#executeObject



24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/bitbucket_import/importer.rb', line 24

def execute
  import_wiki
  import_issues
  import_pull_requests
  handle_errors
  metrics.track_finished_import

  true
end