summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-15 15:07:43 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-15 15:07:43 +0000
commitf8a5275c45ed2276daf843764113476749e680d2 (patch)
tree4856524dbeebf0280a87ff71bcc274f496975e72 /lib
parente6fed37d941271b897d37820fd3b571feab280b0 (diff)
downloadgitlab-ce-f8a5275c45ed2276daf843764113476749e680d2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/github_import/importer/pull_request_merged_by_importer.rb69
-rw-r--r--lib/gitlab/github_import/importer/pull_requests/all_merged_by_importer.rb59
-rw-r--r--lib/gitlab/github_import/importer/pull_requests/merged_by_importer.rb71
-rw-r--r--lib/gitlab/github_import/importer/pull_requests_merged_by_importer.rb57
4 files changed, 130 insertions, 126 deletions
diff --git a/lib/gitlab/github_import/importer/pull_request_merged_by_importer.rb b/lib/gitlab/github_import/importer/pull_request_merged_by_importer.rb
deleted file mode 100644
index 51a72a80268..00000000000
--- a/lib/gitlab/github_import/importer/pull_request_merged_by_importer.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module GithubImport
- module Importer
- class PullRequestMergedByImporter
- # pull_request - An instance of
- # `Gitlab::GithubImport::Representation::PullRequest`
- # project - An instance of `Project`
- # client - An instance of `Gitlab::GithubImport::Client`
- def initialize(pull_request, project, client)
- @pull_request = pull_request
- @project = project
- @client = client
- end
-
- def execute
- user_finder = GithubImport::UserFinder.new(project, client)
-
- gitlab_user_id = user_finder.user_id_for(pull_request.merged_by)
-
- metrics_upsert(gitlab_user_id)
-
- add_note!
- end
-
- private
-
- attr_reader :project, :pull_request, :client
-
- def metrics_upsert(gitlab_user_id)
- MergeRequest::Metrics.upsert({
- target_project_id: project.id,
- merge_request_id: merge_request.id,
- merged_by_id: gitlab_user_id,
- merged_at: pull_request.merged_at,
- created_at: timestamp,
- updated_at: timestamp
- }, unique_by: :merge_request_id)
- end
-
- def add_note!
- merge_request.notes.create!(
- importing: true,
- note: missing_author_note,
- author_id: project.creator_id,
- project: project,
- created_at: pull_request.merged_at
- )
- end
-
- def merge_request
- @merge_request ||= project.merge_requests.find_by_iid(pull_request.iid)
- end
-
- def timestamp
- @timestamp ||= Time.new.utc
- end
-
- def missing_author_note
- s_("GitHubImporter|*Merged by: %{author} at %{timestamp}*") % {
- author: pull_request.merged_by&.login || 'ghost',
- timestamp: pull_request.merged_at
- }
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/github_import/importer/pull_requests/all_merged_by_importer.rb b/lib/gitlab/github_import/importer/pull_requests/all_merged_by_importer.rb
new file mode 100644
index 00000000000..9aa55fd3eae
--- /dev/null
+++ b/lib/gitlab/github_import/importer/pull_requests/all_merged_by_importer.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module PullRequests
+ class AllMergedByImporter
+ include ParallelScheduling
+
+ def importer_class
+ MergedByImporter
+ end
+
+ def representation_class
+ Gitlab::GithubImport::Representation::PullRequest
+ end
+
+ def sidekiq_worker_class
+ Gitlab::GithubImport::PullRequests::ImportMergedByWorker
+ end
+
+ def collection_method
+ :pull_requests_merged_by
+ end
+
+ def object_type
+ :pull_request_merged_by
+ end
+
+ def id_for_already_imported_cache(merge_request)
+ merge_request.id
+ end
+
+ def each_object_to_import
+ merge_requests_to_import.find_each do |merge_request|
+ Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
+
+ pull_request = client.pull_request(project.import_source, merge_request.iid)
+ yield(pull_request)
+
+ mark_as_imported(merge_request)
+ end
+ end
+
+ private
+
+ # Returns only the merge requests that still have merged_by to be imported.
+ def merge_requests_to_import
+ project.merge_requests.id_not_in(already_imported_objects).with_state(:merged)
+ end
+
+ def already_imported_objects
+ Gitlab::Cache::Import::Caching.values_from_set(already_imported_cache_key)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/pull_requests/merged_by_importer.rb b/lib/gitlab/github_import/importer/pull_requests/merged_by_importer.rb
new file mode 100644
index 00000000000..19880716832
--- /dev/null
+++ b/lib/gitlab/github_import/importer/pull_requests/merged_by_importer.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module PullRequests
+ class MergedByImporter
+ # pull_request - An instance of
+ # `Gitlab::GithubImport::Representation::PullRequest`
+ # project - An instance of `Project`
+ # client - An instance of `Gitlab::GithubImport::Client`
+ def initialize(pull_request, project, client)
+ @pull_request = pull_request
+ @project = project
+ @client = client
+ end
+
+ def execute
+ user_finder = GithubImport::UserFinder.new(project, client)
+
+ gitlab_user_id = user_finder.user_id_for(pull_request.merged_by)
+
+ metrics_upsert(gitlab_user_id)
+
+ add_note!
+ end
+
+ private
+
+ attr_reader :project, :pull_request, :client
+
+ def metrics_upsert(gitlab_user_id)
+ MergeRequest::Metrics.upsert({
+ target_project_id: project.id,
+ merge_request_id: merge_request.id,
+ merged_by_id: gitlab_user_id,
+ merged_at: pull_request.merged_at,
+ created_at: timestamp,
+ updated_at: timestamp
+ }, unique_by: :merge_request_id)
+ end
+
+ def add_note!
+ merge_request.notes.create!(
+ importing: true,
+ note: missing_author_note,
+ author_id: project.creator_id,
+ project: project,
+ created_at: pull_request.merged_at
+ )
+ end
+
+ def merge_request
+ @merge_request ||= project.merge_requests.find_by_iid(pull_request.iid)
+ end
+
+ def timestamp
+ @timestamp ||= Time.new.utc
+ end
+
+ def missing_author_note
+ format(s_("GitHubImporter|*Merged by: %{author} at %{timestamp}*"),
+ author: pull_request.merged_by&.login || 'ghost',
+ timestamp: pull_request.merged_at
+ )
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/pull_requests_merged_by_importer.rb b/lib/gitlab/github_import/importer/pull_requests_merged_by_importer.rb
deleted file mode 100644
index c56b391cbec..00000000000
--- a/lib/gitlab/github_import/importer/pull_requests_merged_by_importer.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module GithubImport
- module Importer
- class PullRequestsMergedByImporter
- include ParallelScheduling
-
- def importer_class
- PullRequestMergedByImporter
- end
-
- def representation_class
- Gitlab::GithubImport::Representation::PullRequest
- end
-
- def sidekiq_worker_class
- ImportPullRequestMergedByWorker
- end
-
- def collection_method
- :pull_requests_merged_by
- end
-
- def object_type
- :pull_request_merged_by
- end
-
- def id_for_already_imported_cache(merge_request)
- merge_request.id
- end
-
- def each_object_to_import
- merge_requests_to_import.find_each do |merge_request|
- Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
-
- pull_request = client.pull_request(project.import_source, merge_request.iid)
- yield(pull_request)
-
- mark_as_imported(merge_request)
- end
- end
-
- private
-
- # Returns only the merge requests that still have merged_by to be imported.
- def merge_requests_to_import
- project.merge_requests.id_not_in(already_imported_objects).with_state(:merged)
- end
-
- def already_imported_objects
- Gitlab::Cache::Import::Caching.values_from_set(already_imported_cache_key)
- end
- end
- end
- end
-end