Class: Gitlab::BitbucketServerImport::Importers::PullRequestImporter

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb

Instance Method Summary collapse

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Constructor Details

#initialize(project, hash) ⇒ PullRequestImporter

Returns a new instance of PullRequestImporter.



9
10
11
12
13
14
15
16
17
# File 'lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb', line 9

def initialize(project, hash)
  @project = project
  @formatter = Gitlab::ImportFormatter.new
  @user_finder = UserFinder.new(project)

  # Object should behave as a object so we can remove object.is_a?(Hash) check
  # This will be fixed in https://gitlab.com/gitlab-org/gitlab/-/issues/412328
  @object = hash.with_indifferent_access
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb', line 19

def execute
  log_info(import_stage: 'import_pull_request', message: 'starting', iid: object[:iid])

  description = ''
  description += author_line
  description += object[:description] if object[:description]

  attributes = {
    iid: object[:iid],
    title: object[:title],
    description: description,
    reviewer_ids: reviewers,
    source_project_id: project.id,
    source_branch: Gitlab::Git.ref_name(object[:source_branch_name]),
    source_branch_sha: source_branch_sha,
    target_project_id: project.id,
    target_branch: Gitlab::Git.ref_name(object[:target_branch_name]),
    target_branch_sha: object[:target_branch_sha],
    state_id: MergeRequest.available_states[object[:state]],
    author_id: user_finder.author_id(object),
    created_at: object[:created_at],
    updated_at: object[:updated_at]
  }

  creator = Gitlab::Import::MergeRequestCreator.new(project)

  creator.execute(attributes)

  log_info(import_stage: 'import_pull_request', message: 'finished', iid: object[:iid])
end