Class: DownloaderForDataCenter
Constant Summary
Constants inherited
from Downloader
Downloader::CURRENT_METADATA_VERSION
Instance Attribute Summary
Attributes inherited from Downloader
#board_id_to_filter_id, #file_system, #metadata, #start_date_in_query
Instance Method Summary
collapse
Methods inherited from Downloader
create, #download_board_configuration, #download_features, #download_github_prs, #download_sprints, #download_statuses, #download_users, #end_progress, #extract_project_keys_from_downloaded_issues, #file_prefix, #find_board_ids, #identify_other_issues_to_be_downloaded, #initialize, #load_metadata, #log, #log_start, #metadata_pathname, #progress_dot, #remove_old_files, #run, #save_metadata, #start_progress, #timezone_offset, #today_in_project_timezone, #update_status_history_file
Constructor Details
This class inherits a constructor from Downloader
Instance Method Details
#download_issues(board:) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/jirametrics/downloader_for_data_center.rb', line 8
def download_issues board:
log " Downloading primary issues for board #{board.id}", both: true
path = File.join(@target_path, "#{file_prefix}_issues/")
unless Dir.exist?(path)
log " Creating path #{path}"
Dir.mkdir(path)
end
filter_id = board_id_to_filter_id[board.id]
jql = make_jql(filter_id: filter_id)
jira_search_by_jql(jql: jql, initial_query: true, board: board, path: path)
log " Downloading linked issues for board #{board.id}", both: true
loop do
@issue_keys_pending_download.reject! { |key| @issue_keys_downloaded_in_current_run.include? key }
break if @issue_keys_pending_download.empty?
keys_to_request = @issue_keys_pending_download[0..99]
@issue_keys_pending_download.reject! { |key| keys_to_request.include? key }
jql = "key in (#{keys_to_request.join(', ')})"
jira_search_by_jql(jql: jql, initial_query: true, board: board, path: path)
end
end
|
#enhance_issue_with_worklogs(issue_key:, issue_path:) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/jirametrics/downloader_for_data_center.rb', line 70
def enhance_issue_with_worklogs issue_key:, issue_path:
all_worklogs = []
start_at = 0
max_results = 100
loop do
url = "/rest/api/2/issue/#{CGI.escape(issue_key)}/worklog?startAt=#{start_at}&maxResults=#{max_results}"
response = @jira_gateway.call_url(relative_url: url)
worklogs = response['worklogs'] || []
all_worklogs.concat(worklogs)
total = response['total'].to_i
break if start_at + worklogs.size >= total
start_at += worklogs.size
end
issue_json = @file_system.load_json(issue_path)
issue_json['worklog'] = {
'startAt' => 0,
'maxResults' => all_worklogs.size,
'total' => all_worklogs.size,
'worklogs' => all_worklogs
}
@file_system.save_json(json: issue_json, filename: issue_path)
log " Enhanced #{issue_key} with #{all_worklogs.size} worklogs" if all_worklogs.any?
end
|
#jira_instance_type ⇒ Object
4
5
6
|
# File 'lib/jirametrics/downloader_for_data_center.rb', line 4
def jira_instance_type
'Jira DataCenter'
end
|
#jira_search_by_jql(jql:, initial_query:, board:, path:) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/jirametrics/downloader_for_data_center.rb', line 32
def jira_search_by_jql jql:, initial_query:, board:, path:
intercept_jql = @download_config.project_config.settings['intercept_jql']
jql = intercept_jql.call jql if intercept_jql
log " JQL: #{jql}"
escaped_jql = CGI.escape jql
max_results = 100
start_at = 0
total = 1
while start_at < total
json = @jira_gateway.call_url relative_url: '/rest/api/2/search' \
"?jql=#{escaped_jql}&maxResults=#{max_results}&startAt=#{start_at}&expand=changelog&fields=*all"
json['issues'].each do |issue_json|
issue_json['exporter'] = {
'in_initial_query' => initial_query
}
identify_other_issues_to_be_downloaded raw_issue: issue_json, board: board
file = "#{issue_json['key']}-#{board.id}.json"
issue_path = File.join(path, file)
@file_system.save_json(json: issue_json, filename: issue_path)
enhance_issue_with_worklogs(issue_key: issue_json['key'], issue_path: issue_path)
end
total = json['total'].to_i
max_results = json['maxResults']
message = " Downloaded #{start_at + 1}-#{[start_at + max_results, total].min} of #{total} issues to #{path} "
log message, both: true
start_at += json['issues'].size
end
end
|
#make_jql(filter_id:, today: nil) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/jirametrics/downloader_for_data_center.rb', line 100
def make_jql filter_id:, today: nil
today ||= today_in_project_timezone
segments = []
segments << "filter=#{filter_id}"
start_date = @download_config.start_date today: today
if start_date
@download_date_range = start_date..today.to_date
@start_date_in_query = metadata['date_end'] || @download_date_range.begin
log " Incremental download only. Pulling from #{@start_date_in_query}", both: true if metadata['date_end']
catch_all = '((status changed OR Sprint is not EMPTY) AND statusCategory != Done)'
start_date_text = @start_date_in_query.strftime '%Y-%m-%d'
find_in_range = %(updated >= "#{start_date_text} 00:00")
segments << "(#{find_in_range} OR #{catch_all})"
end
segments.join ' AND '
end
|