Class: Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
Constant Summary
collapse
- PROCESSED_PAGE_CACHE_KEY =
'issues/%{issuable_iid}/%{collection}'
- BATCH_SIZE =
100
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
#each_object_to_import, #parent_collection
#abort_on_failure, #already_imported?, #each_object_to_import, #execute, #increment_object_counter?, #mark_as_imported, #parallel?, #parallel_import, #sequential_import, #spread_parallel_import
#parallel_import_batch
Constructor Details
Returns a new instance of SingleEndpointIssueEventsImporter.
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 13
def initialize(project, client, parallel: true)
@project = project
@client = client
@parallel = parallel
@already_imported_cache_key = ALREADY_IMPORTED_CACHE_KEY %
{ project: project.id, collection: collection_method }
@job_waiter_cache_key = JOB_WAITER_CACHE_KEY %
{ project: project.id, collection: collection_method }
@job_waiter_remaining_cache_key = JOB_WAITER_REMAINING_CACHE_KEY %
{ project: project.id, collection: collection_method }
end
|
Instance Method Details
#collection_method ⇒ Object
66
67
68
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 66
def collection_method
:issue_timeline
end
|
#collection_options ⇒ Object
90
91
92
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 90
def collection_options
{ state: 'all', sort: 'created', direction: 'asc' }
end
|
#compose_associated_id!(issuable, event) ⇒ Object
Cross-referenced events on Github doesn’t have id.
95
96
97
98
99
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 95
def compose_associated_id!(issuable, event)
return if event[:event] != 'cross-referenced'
event[:id] = "cross-reference##{issuable.iid}-in-#{event.dig(:source, :issue, :id)}"
end
|
#each_associated(parent_record, associated) {|associated| ... } ⇒ Object
In single endpoint there is no issue info to which associated related To make it possible to identify issue in separated worker we need to patch Sawyer instances here with issue number
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 28
def each_associated(parent_record, associated)
associated = associated.to_h
compose_associated_id!(parent_record, associated)
return if already_imported?(associated)
Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
pull_request = parent_record.is_a? MergeRequest
associated[:issue] = { number: parent_record.iid, pull_request: pull_request }
yield(associated)
mark_as_imported(associated)
end
|
#each_associated_page(&block) ⇒ Object
In Github Issues and MergeRequests uses the same API to get their events. Even more - they have commonly uniq iid
45
46
47
48
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 45
def each_associated_page(&block)
issues_collection.each_batch(of: BATCH_SIZE, column: :iid) { |batch| process_batch(batch, &block) }
merge_requests_collection.each_batch(of: BATCH_SIZE, column: :iid) { |batch| process_batch(batch, &block) }
end
|
#id_for_already_imported_cache(event) ⇒ Object
86
87
88
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 86
def id_for_already_imported_cache(event)
event[:id]
end
|
#importer_class ⇒ Object
50
51
52
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 50
def importer_class
IssueEventImporter
end
|
#issues_collection ⇒ Object
70
71
72
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 70
def issues_collection
project.issues.where.not(iid: already_imported_parents).select(:id, :iid) end
|
#merge_requests_collection ⇒ Object
74
75
76
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 74
def merge_requests_collection
project.merge_requests.where.not(iid: already_imported_parents).select(:id, :iid) end
|
#object_type ⇒ Object
62
63
64
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 62
def object_type
:issue_event
end
|
#page_counter_id(issuable) ⇒ Object
82
83
84
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 82
def page_counter_id(issuable)
PROCESSED_PAGE_CACHE_KEY % { issuable_iid: issuable.iid, collection: collection_method }
end
|
#parent_imported_cache_key ⇒ Object
78
79
80
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 78
def parent_imported_cache_key
"github-importer/issues/#{collection_method}/already-imported/#{project.id}"
end
|
#representation_class ⇒ Object
54
55
56
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 54
def representation_class
Representation::IssueEvent
end
|
#sidekiq_worker_class ⇒ Object
58
59
60
|
# File 'lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb', line 58
def sidekiq_worker_class
ImportIssueEventWorker
end
|