lib/dri/report.rb in dri-0.1.0 vs lib/dri/report.rb in dri-0.1.1

- old
+ new

@@ -15,11 +15,11 @@ def set_header(timezone, username) @header = "# #{timezone}, #{@weekday} - #{@date}\n posted by: @#{username}" end - def add_failure(failure) + def add_failure(failure, actions_opts = []) iid = failure["iid"] title = failure["title"] link = failure["web_url"] labels = failure["labels"] created_at = failure["created_at"] @@ -36,43 +36,90 @@ failure_type = filter_failure_type_labels(labels) assigned_status = assigned?(assignees) pipelines = filter_pipeline_labels(labels) - linked_pipelines = link_pipelines(iid, pipelines) + linked_pipelines = link_pipelines(iid, pipelines, description) actions = "" - actions.concat actions_status_template(failure_type, assigned_status) + actions.concat actions_status_template(failure_type, assigned_status, actions_opts) actions.concat actions_fixes_template(related_mrs) @failures << [title, emojified_link, linked_pipelines, stack_trace, actions] end private - def link_pipelines(iid, pipelines) + def link_pipelines(iid, pipelines, description) + linked = [] + label_pipeline_map = { + 'gitlab.com' => '/quality/production', + 'canary.gitlab.com' => '/quality/canary', + # 'canary.staging.gitlab.com' => '', + 'main' => '/gitlab-org/gitlab-qa-mirror', + 'master' => '/gitlab-org/gitlab-qa-mirror', + 'nightly' => '/quality/nightly', + '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(issue_iid: iid) - linked = "" + return if pipelines.empty? pipelines.each do |pipeline| - failure_notes.each do |note| - if note["body"].include? pipeline - pipeline_link = URI.extract(note["body"], %w(https)) - pipeline_link_sanitized = pipeline_link.join.strip - pipeline = "[#{pipeline}](#{pipeline_link_sanitized})" - break - end + next if !label_pipeline_map.has_key? pipeline + + pipeline_in_notes_found = false + pipeline_link = '' + pipeline_link_sanitized = '' + pipeline_markdown = '' + + failure_notes.each do |note| + if note["body"].include? label_pipeline_map.fetch(pipeline) + pipeline_in_notes_found = true + pipeline_link = URI.extract(note["body"], %w(https)) + break end + 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 - linked << pipeline + if !pipeline_link.empty? + pipeline_link_sanitized = pipeline_link.join.strip.chop + pipeline_markdown = "[#{pipeline.gsub(/.gitlab.com/, '')}](#{pipeline_link_sanitized})" + linked << pipeline_markdown + end end - linked + linked.join(', ') end - def actions_status_template(failure_type, assigned_status) - "<i>Status:</i><ul><li>#{failure_type}</li><li>#{assigned_status}</li><li>[ ] notified SET</li><li>[ ] quarantined</li></ul>" + def actions_status_template(failure_type, assigned_status, actions_opts) + notified_set = '' + quarantined = '' + reproduced = '' + transient = '' + + notified_set = '<li>[x] notified SET</li>' if actions_opts.include? 'pinged SET' + quarantined = '<li>[x] quarantined</li>' if actions_opts.include? 'quarantined' + reproduced = '<li>[x] reproduced</li>' if actions_opts.include? 'reproduced' + transient = '<li>[x] transient</li>' if actions_opts.include? 'transient' + + action_status = "<i>Status:</i><ul>" + action_status << "<li>#{failure_type}</li>" + action_status << "</li><li>#{assigned_status}</li>" + action_status << notified_set + action_status << quarantined + action_status << reproduced + action_status << transient + + action_status end def actions_fixes_template(related_mrs) actions_fixes_template = '<ul><i>Potential fixes:</i><br>' related_mrs.each do |mr| @@ -88,13 +135,13 @@ def filter_pipeline_labels(labels) pipelines = [] labels.each do |label| - matchers = { 'found:' => ' ', '.gitlab.com' => ' ' } + matchers = { 'found:' => ' '} if label.include? "found:" - pipeline = label.gsub(/found:|.gitlab.com/) { |match| matchers[match] } + pipeline = label.gsub(/found:/) { |match| matchers[match] } pipelines << pipeline.strip end end pipelines end \ No newline at end of file