2020-11-28 06:09:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
module Importer
|
|
|
|
class PullRequestMergedByImporter
|
|
|
|
def initialize(pull_request, project, client)
|
|
|
|
@project = project
|
|
|
|
@pull_request = pull_request
|
|
|
|
@client = client
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
merge_request = project.merge_requests.find_by_iid(pull_request.iid)
|
2021-02-25 12:11:01 +00:00
|
|
|
timestamp = Time.new.utc
|
|
|
|
merged_at = pull_request.merged_at
|
2020-11-28 06:09:28 +00:00
|
|
|
user_finder = GithubImport::UserFinder.new(project, client)
|
|
|
|
gitlab_user_id = user_finder.user_id_for(pull_request.merged_by)
|
|
|
|
|
2021-02-25 12:11:01 +00:00
|
|
|
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
|
2020-11-28 06:09:28 +00:00
|
|
|
merge_request.notes.create!(
|
2020-11-30 18:09:46 +00:00
|
|
|
importing: true,
|
2021-02-25 12:11:01 +00:00
|
|
|
note: missing_author_note,
|
2020-11-28 06:09:28 +00:00
|
|
|
author_id: project.creator_id,
|
|
|
|
project: project,
|
2021-02-25 12:11:01 +00:00
|
|
|
created_at: merged_at
|
2020-11-28 06:09:28 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :project, :pull_request, :client
|
2021-02-25 12:11:01 +00:00
|
|
|
|
|
|
|
def missing_author_note
|
|
|
|
s_("GitHubImporter|*Merged by: %{author} at %{timestamp}*") % {
|
|
|
|
author: pull_request.merged_by.login,
|
|
|
|
timestamp: pull_request.merged_at
|
|
|
|
}
|
|
|
|
end
|
2020-11-28 06:09:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|