Class: Gitlab::GithubImport::Importer::PullRequestMergedByImporter

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

Instance Method Summary collapse

Constructor Details

#initialize(pull_request, project, client) ⇒ PullRequestMergedByImporter

Returns a new instance of PullRequestMergedByImporter.


7
8
9
10
11
# File 'lib/gitlab/github_import/importer/pull_request_merged_by_importer.rb', line 7

def initialize(pull_request, project, client)
  @project = project
  @pull_request = pull_request
  @client = client
end

Instance Method Details

#executeObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/github_import/importer/pull_request_merged_by_importer.rb', line 13

def execute
  merge_request = project.merge_requests.find_by_iid(pull_request.iid)
  timestamp = Time.new.utc
  merged_at = pull_request.merged_at
  user_finder = GithubImport::UserFinder.new(project, client)
  gitlab_user_id = user_finder.user_id_for(pull_request.merged_by)

  MergeRequest::Metrics.upsert({
    target_project_id: project.id,
    merge_request_id: merge_request.id,
    merged_by_id: gitlab_user_id,
    merged_at: merged_at,
    created_at: timestamp,
    updated_at: timestamp
  }, unique_by: :merge_request_id)

  unless gitlab_user_id
    merge_request.notes.create!(
      importing: true,
      note: missing_author_note,
      author_id: project.creator_id,
      project: project,
      created_at: merged_at
    )
  end
end