lib/dri/report.rb in dri-0.7.0 vs lib/dri/report.rb in dri-0.8.0
- old
+ new
@@ -1,9 +1,12 @@
# frozen_string_literal: true
+require_relative './utils/constants'
+
module Dri
class Report # rubocop:disable Metrics/ClassLength
+ include Dri::Utils::Constants::Triage::Labels
using Refinements
attr_reader :header, :failures, :labels, :labels_incidents, :incidents
def initialize(config)
@@ -29,28 +32,27 @@
labels = incident["labels"]
status = 'N/A'
service = 'N/A'
labels.each do |label|
- status = label.gsub!('Incident::', ' ').to_s if label.include? "Incident::"
- service = label.gsub!('Service::', ' ').to_s if label.include? "Service::"
+ status = label.gsub!(INCIDENT, ' ').to_s if label.include? INCIDENT
+ service = label.gsub!(SERVICE, ' ').to_s if label.include? SERVICE
end
@incidents << [title, service, status, url]
end
def add_failure(failure, actions_opts = [])
+ project_id = failure["project_id"]
iid = failure["iid"]
title = format_title(failure["title"])
link = failure["web_url"]
labels = failure["labels"]
- created_at = failure["created_at"]
- assignees = failure["assignees"]
description = failure["description"]
- related_mrs = @api_client.fetch_related_mrs(iid)
- emoji = classify_failure_emoji(created_at)
+ related_mrs = @api_client.fetch_related_mrs(project_id, iid)
+ emoji = classify_failure_emoji(failure["created_at"])
emojified_link = "#{emoji} #{link}"
stack_blob = if description.empty?
"No stack trace found"
else
@@ -58,24 +60,24 @@
end
stack_trace = ":link:[`#{stack_blob}...`](#{link}#stack-trace)"
failure_type = filter_failure_type_labels(labels)
- assigned_status = assigned?(assignees)
+ assigned_status = assigned?(failure["assignees"])
pipelines = filter_pipeline_labels(labels)
- linked_pipelines = link_pipelines(iid, pipelines, description)
+ 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}"]
end
private
- def link_pipelines(iid, pipelines, description) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
+ 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',
@@ -86,11 +88,11 @@
'staging-ref' => '/quality/staging-ref',
'staging.gitlab.com' => '/quality/staging',
'release' => '/quality/release'
}
- failure_notes = @api_client.fetch_failure_notes(iid)
+ 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)
@@ -171,22 +173,22 @@
def filter_pipeline_labels(labels)
pipelines = []
labels.each do |label|
- matchers = { 'found:' => ' ' }
+ matchers = { FOUND => ' ' }
- if label.include? "found:"
- pipeline = label.gsub(/found:/) { |match| matchers[match] }
+ if label.include? FOUND
+ pipeline = label.gsub(/#{FOUND}/o) { |match| matchers[match] }
pipelines << pipeline.strip
end
end
pipelines
end
def filter_failure_type_labels(labels)
labels.each do |label|
- @type = label.gsub!('failure::', ' ').to_s if label.include? "failure::"
+ @type = label.gsub!(FAILURE, ' ').to_s if label.include? FAILURE
end
@type
end
def classify_failure_emoji(created_at)