blob: 09aa5edc73b8e7adb26bc5df7199411b08c3a155 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
39
40
41
42
43
44
45
46
47
48
49
|
# frozen_string_literal: true
module JiraConnect
class SyncProjectWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
include SortingTitlesValuesHelper
sidekiq_options retry: 3
queue_namespace :jira_connect
feature_category :integrations
data_consistency :delayed
urgency :low
worker_has_external_dependencies!
MAX_RECORDS_LIMIT = 400
def perform(project_id, update_sequence_id)
project = Project.find_by_id(project_id)
return if project.nil?
sync_params = {
branches: branches_to_sync(project),
merge_requests: merge_requests_to_sync(project),
update_sequence_id: update_sequence_id
}
JiraConnect::SyncService.new(project).execute(**sync_params)
end
private
# rubocop: disable CodeReuse/ActiveRecord
def merge_requests_to_sync(project)
project.merge_requests.with_jira_issue_keys
.preload(:author, :approvals, merge_request_reviewers: :reviewer)
.limit(MAX_RECORDS_LIMIT)
.order(id: :desc)
end
# rubocop: enable CodeReuse/ActiveRecord
def branches_to_sync(project)
project.repository.branches_sorted_by(SORT_UPDATED_RECENT).filter_map do |branch|
branch if branch.name.match(Gitlab::Regex.jira_issue_key_regex)
end.first(MAX_RECORDS_LIMIT)
end
end
end
|