lib/dri/report.rb in dri-0.10.2 vs lib/dri/report.rb in dri-0.11.0

- old
+ new

@@ -61,70 +61,21 @@ stack_trace = ":link:[`#{stack_blob}...`](#{link}#stack-trace)" failure_type = filter_failure_type_labels(labels) assigned_status = assigned?(failure["assignees"]) - pipelines = filter_pipeline_labels(labels) + pipelines = format_pipelines(labels) - linked_pipelines = link_pipelines(project_id, iid, pipelines, description) - actions_status = actions_status_template(failure_type, assigned_status, actions_opts) actions_fixes = actions_fixes_template(related_mrs) - @failures << [title, emojified_link, linked_pipelines, stack_trace, "#{actions_status}#{actions_fixes}"] + @failures << [title, emojified_link, pipelines, stack_trace, "#{actions_status}#{actions_fixes}"] end private - def link_pipelines(project_id, iid, pipelines, description) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength - linked = [] - label_pipeline_map = { - 'gitlab.com' => '/quality/production', - 'canary.gitlab.com' => '/quality/canary', - 'canary.staging.gitlab.com' => '/quality/staging-canary', - 'main' => '/gitlab-org/gitlab-qa-mirror', - 'master' => '/gitlab-org/gitlab-qa-mirror', - 'pre.gitlab.com' => '/quality/preprod', - 'staging-ref' => '/quality/staging-ref', - 'staging.gitlab.com' => '/quality/staging', - 'release' => '/quality/release' - } - - failure_notes = @api_client.fetch_failure_notes(project_id, iid) - - return if pipelines.empty? - - pipelines.each do |pipeline| - next unless label_pipeline_map.has_key?(pipeline) - - pipeline_in_notes_found = false - pipeline_link = '' - pipeline_markdown = pipeline.gsub(/.gitlab.com/, '') - - failure_notes.each do |note| - next unless note.body.include?(label_pipeline_map.fetch(pipeline)) - - pipeline_in_notes_found = true - pipeline_link = URI.extract(note.body, %w[https]) - end - - unless pipeline_in_notes_found - links_description = URI.extract(description, %w[https]) - pipeline_link = links_description.select { |link| link.include? label_pipeline_map.fetch(pipeline) } - end - - unless pipeline_link.empty? - pipeline_link_sanitized = pipeline_link.join.strip - pipeline_markdown = "[#{pipeline_markdown}](#{pipeline_link_sanitized})" - end - - linked << pipeline_markdown - end - linked.join(', ') - end - - def actions_status_template(failure_type, assigned_status, actions_opts) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity/MethodLength + def actions_status_template(failure_type, assigned_status, actions_opts) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity/ quarantined = '' reproduced = '' transient = '' active_investigation = '' blocking_pipelines = '' @@ -180,9 +131,18 @@ pipeline = label.gsub(/#{FOUND}/o) { |match| matchers[match] } pipelines << pipeline.strip end end pipelines + end + + def format_pipelines(labels) + labels.filter_map do |label| + next unless label.include?(FOUND) + + sanitized_label = label.gsub(FOUND, ' ').strip + sanitized_label.gsub(/.gitlab.com/, '') + end.join(', ') end def filter_failure_type_labels(labels) labels.each do |label| @type = label.gsub!(FAILURE, ' ').to_s if label.include? FAILURE