Class: DownloaderForCloud
- Inherits:
-
Downloader
- Object
- Downloader
- DownloaderForCloud
- Defined in:
- lib/jirametrics/downloader_for_cloud.rb
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
- #attach_changelog_to_issues(issue_datas:, issue_jsons:) ⇒ Object
- #bulk_fetch_issues(issue_datas:, board:, in_initial_query:) ⇒ Object
- #jira_instance_type ⇒ Object
- #search_for_issues(jql:, board_id:, path:) ⇒ Object
Methods inherited from Downloader
create, #delete_issues_from_cache_that_are_not_in_server, #download_board_configuration, #download_issues, #download_sprints, #download_statuses, #download_users, #file_prefix, #find_board_ids, #identify_other_issues_to_be_downloaded, #initialize, #last_modified, #load_metadata, #log, #make_jql, #metadata_pathname, #remove_old_files, #run, #save_metadata, #update_status_history_file
Constructor Details
This class inherits a constructor from Downloader
Instance Method Details
#attach_changelog_to_issues(issue_datas:, issue_jsons:) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/jirametrics/downloader_for_cloud.rb', line 81 def attach_changelog_to_issues issue_datas:, issue_jsons: payload = { 'issueIdsOrKeys' => issue_datas.collect(&:key), 'maxResults' => 10_000 # The max jira accepts is 10K } loop do puts payload response = @jira_gateway.post_request( relative_url: '/rest/api/3/changelog/bulkfetch', payload: JSON.generate(payload) ) response['issueChangeLogs'].each do |issue_change_log| # puts issue_change_log # puts issue_change_log.keys.inspect issue_id = issue_change_log['issueId'] issue = issue_datas.find { |data| data.issue.raw['id'] == issue_id }.issue # puts "Issue(#{issue.key})" histories = issue_change_log['changeHistories'] issue.raw['changelog'] = { 'startAt' => 0, 'maxResults' => histories.size, 'total' => histories.size, 'histories' => histories } end next_page_token = response['nextPageToken'] payload['nextPageToken'] = next_page_token # puts "next page token=#{next_page_token.inspect}" break if next_page_token.nil? # puts '' end end |
#bulk_fetch_issues(issue_datas:, board:, in_initial_query:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jirametrics/downloader_for_cloud.rb', line 47 def bulk_fetch_issues issue_datas:, board:, in_initial_query: # We used to use the expand option to pull in the changelog directly. Unfortunately # that only returns the "recent" changes, not all of them. So now we get the issue # without changes and then make a second call for that changes. Then we insert it # into the raw issue as if it had been there all along. log " Downloading #{issue_datas.size} issues", both: true payload = { # 'expand' => [ # 'changelog' # ], 'fields' => ['*all'], 'issueIdsOrKeys' => issue_datas.collect(&:key) } response = @jira_gateway.post_request( relative_url: '/rest/api/3/issue/bulkfetch', payload: JSON.generate(payload) ) response['issues'].each do |issue_json| issue_json['exporter'] = { 'in_initial_query' => in_initial_query } issue = Issue.new(raw: issue_json, board: board) data = issue_datas.find { |d| d.key == issue.key } data.up_to_date = true data.last_modified = issue.updated data.issue = issue end attach_changelog_to_issues issue_datas: issue_datas, issue_jsons: response['issues'] issue_datas end |
#jira_instance_type ⇒ Object
4 5 6 |
# File 'lib/jirametrics/downloader_for_cloud.rb', line 4 def jira_instance_type 'Jira Cloud' end |
#search_for_issues(jql:, board_id:, path:) ⇒ Object
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 |
# File 'lib/jirametrics/downloader_for_cloud.rb', line 8 def search_for_issues jql:, board_id:, path: log " JQL: #{jql}" escaped_jql = CGI.escape jql hash = {} max_results = 5_000 # The maximum allowed by Jira next_page_token = nil issue_count = 0 loop do relative_url = +'' relative_url << '/rest/api/3/search/jql' relative_url << "?jql=#{escaped_jql}&maxResults=#{max_results}" relative_url << "&nextPageToken=#{next_page_token}" if next_page_token relative_url << '&fields=updated' json = @jira_gateway.call_url relative_url: relative_url next_page_token = json['nextPageToken'] json['issues'].each do |i| key = i['key'] data = DownloadIssueData.new key: key data.key = key data.last_modified = Time.parse i['fields']['updated'] data.found_in_primary_query = true data.cache_path = File.join(path, "#{key}-#{board_id}.json") data.up_to_date = last_modified(filename: data.cache_path) == data.last_modified hash[key] = data issue_count += 1 end = " Found #{issue_count} issues" log , both: true break unless next_page_token end hash end |