Class: Gitlab::GithubImport::Importer::PullRequestsImporter
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::Importer::PullRequestsImporter
show all
- Includes:
- ParallelScheduling
- Defined in:
- lib/gitlab/github_import/importer/pull_requests_importer.rb
Constant Summary
ParallelScheduling::ALREADY_IMPORTED_CACHE_KEY, ParallelScheduling::JOB_WAITER_CACHE_KEY, ParallelScheduling::JOB_WAITER_REMAINING_CACHE_KEY
Instance Attribute Summary
#already_imported_cache_key, #client, #job_waiter_cache_key, #job_waiter_remaining_cache_key, #page_counter, #project
Instance Method Summary
collapse
#abort_on_failure, #already_imported?, #execute, #increment_object_counter?, #initialize, #mark_as_imported, #parallel?, #parallel_import, #sequential_import, #spread_parallel_import
Instance Method Details
#collection_method ⇒ Object
69
70
71
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 69
def collection_method
:pull_requests
end
|
#collection_options ⇒ Object
73
74
75
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 73
def collection_options
{ state: 'all', sort: 'created', direction: 'asc' }
end
|
#commit_exists?(sha) ⇒ Boolean
65
66
67
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 65
def commit_exists?(sha)
project.repository.commit(sha).present?
end
|
#each_object_to_import ⇒ Object
29
30
31
32
33
34
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 29
def each_object_to_import
super do |pr|
update_repository if update_repository?(pr)
yield pr
end
end
|
#id_for_already_imported_cache(pr) ⇒ Object
21
22
23
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 21
def id_for_already_imported_cache(pr)
pr[:number]
end
|
#importer_class ⇒ Object
9
10
11
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 9
def importer_class
PullRequestImporter
end
|
#object_type ⇒ Object
25
26
27
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 25
def object_type
:pull_request
end
|
#parallel_import_batch ⇒ Object
77
78
79
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 77
def parallel_import_batch
{ size: 200, delay: 1.minute }
end
|
#repository_updates_counter ⇒ Object
81
82
83
84
85
86
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 81
def repository_updates_counter
@repository_updates_counter ||= Gitlab::Metrics.counter(
:github_importer_repository_updates,
'The number of times repositories have to be updated again'
)
end
|
#representation_class ⇒ Object
#sidekiq_worker_class ⇒ Object
17
18
19
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 17
def sidekiq_worker_class
ImportPullRequestWorker
end
|
#update_repository ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 36
def update_repository
project.touch(:last_repository_updated_at)
project.repository.fetch_remote(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: true)
pname = project.path_with_namespace
Gitlab::Import::Logger.info(
message: 'GitHub importer finished updating repository',
project_name: pname
)
repository_updates_counter.increment
end
|
#update_repository?(pr) ⇒ Boolean
55
56
57
58
59
60
61
62
63
|
# File 'lib/gitlab/github_import/importer/pull_requests_importer.rb', line 55
def update_repository?(pr)
last_update = project.last_repository_updated_at || project.created_at
return false if pr[:updated_at] < last_update
!(commit_exists?(pr.dig(:head, :sha)) && commit_exists?(pr.dig(:base, :sha)))
end
|