Class: Dri::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/dri/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Report

Returns a new instance of Report.



5
6
7
8
9
10
11
12
13
14
# File 'lib/dri/report.rb', line 5

def initialize(config)
  @labels = ['Title', 'Issue', 'Pipelines', 'Stack Trace', 'Actions']
  @failures = []
  @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.



3
4
5
# File 'lib/dri/report.rb', line 3

def failures
  @failures
end

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/dri/report.rb', line 3

def header
  @header
end

#labelsObject (readonly)

Returns the value of attribute labels.



3
4
5
# File 'lib/dri/report.rb', line 3

def labels
  @labels
end

Instance Method Details

#add_failure(failure) ⇒ Object



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
46
47
48
# File 'lib/dri/report.rb', line 20

def add_failure(failure)
  iid = failure["iid"]
  title = failure["title"]
  link = failure["web_url"]
  labels = failure["labels"]
  created_at = failure["created_at"]
  assignees = failure["assignees"]
  award_emoji_url = failure["_links"]["award_emoji"]
  description = failure["description"]

  related_mrs = @api_client.fetch_related_mrs(issue_iid: iid)
  emoji = classify_failure_emoji(created_at)
  emojified_link = "#{emoji} #{link}"
   
  stack_blob = description.empty? ? "No stack trace found" : description.split("### Stack trace").last.gsub(/\n|`|!|\[|\]/, '').squeeze(" ")[0...250]
  stack_trace = ":link:[`#{stack_blob}...`](#{link + '#stack-trace'})"

  failure_type = filter_failure_type_labels(labels)
  assigned_status = assigned?(assignees)
  pipelines = filter_pipeline_labels(labels)

  linked_pipelines = link_pipelines(iid, pipelines)

  actions = ""
  actions.concat actions_status_template(failure_type, assigned_status)
  actions.concat actions_fixes_template(related_mrs)

  @failures << [title, emojified_link, linked_pipelines, stack_trace, actions]
end

#set_header(timezone, username) ⇒ Object



16
17
18
# File 'lib/dri/report.rb', line 16

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