Class: Dri::Report

Inherits:
Object
  • Object
show all
Includes:
Utils::Constants::Triage::Labels
Defined in:
lib/dri/report.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary

Constants included from Utils::Constants::Triage::Labels

Utils::Constants::Triage::Labels::FAILURE, Utils::Constants::Triage::Labels::FAILURE_NEW, Utils::Constants::Triage::Labels::FOUND, Utils::Constants::Triage::Labels::INCIDENT, Utils::Constants::Triage::Labels::QA, Utils::Constants::Triage::Labels::QUALITY, Utils::Constants::Triage::Labels::QUARANTINE, Utils::Constants::Triage::Labels::SERVICE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Report

Returns a new instance of Report.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dri/report.rb', line 12

def initialize(config)
  @labels = ['Title', 'Issue', 'Pipelines', 'Stack Trace', 'Actions']
  @labels_incidents = %w[Incident Service Status URL]
  @failures = []
  @incidents = []
  @date = Date.today
  @today = Date.today.strftime("%Y-%m-%d")
  @weekday = Date.today.strftime("%A")
  @header = nil

  @api_client = ApiClient.new(config)
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures.



10
11
12
# File 'lib/dri/report.rb', line 10

def failures
  @failures
end

#headerObject (readonly)

Returns the value of attribute header.



10
11
12
# File 'lib/dri/report.rb', line 10

def header
  @header
end

#incidentsObject (readonly)

Returns the value of attribute incidents.



10
11
12
# File 'lib/dri/report.rb', line 10

def incidents
  @incidents
end

#labelsObject (readonly)

Returns the value of attribute labels.



10
11
12
# File 'lib/dri/report.rb', line 10

def labels
  @labels
end

#labels_incidentsObject (readonly)

Returns the value of attribute labels_incidents.



10
11
12
# File 'lib/dri/report.rb', line 10

def labels_incidents
  @labels_incidents
end

Instance Method Details

#add_failure(failure, actions_opts = []) ⇒ Object



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
69
70
71
72
73
74
# File 'lib/dri/report.rb', line 44

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"]
  description = failure["description"]

  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
                 description.split("### Stack trace").last.gsub(/\n|`|!|\[|\]/, '').squeeze(" ")[0...250]
               end

  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)

  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

#add_incident(incident) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dri/report.rb', line 29

def add_incident(incident)
  title = incident["title"]
  url = incident["web_url"]
  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
  end

  @incidents << [title, service, status, url]
end

#set_header(timezone, username) ⇒ Object



25
26
27
# File 'lib/dri/report.rb', line 25

def set_header(timezone, username)
  @header = "# #{timezone}, #{@weekday} - #{@date}\n posted by: @#{username}"
end