module Dri class Report attr_reader :header, :failures, :labels 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 def set_header(timezone, username) @header = "# #{timezone}, #{@weekday} - #{@date}\n posted by: @#{username}" end 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 private def link_pipelines(iid, pipelines) failure_notes = @api_client.fetch_failure_notes(issue_iid: iid) linked = "" 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 end linked << pipeline end linked end def actions_status_template(failure_type, assigned_status) "Status:" end def actions_fixes_template(related_mrs) actions_fixes_template = '' actions_fixes_template end def assigned?(assignees) assignees.empty? ? 'Assigned :x:' : 'Assigned :white_check_mark:' end def filter_pipeline_labels(labels) pipelines = [] labels.each do |label| matchers = { 'found:' => ' ', '.gitlab.com' => ' ' } if label.include? "found:" pipeline = label.gsub(/found:|.gitlab.com/) { |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::" end @type end def classify_failure_emoji(created_at) new_failure_emoji = ':boom:' known_failure_emoji = ':fire_engine:' if created_at.include? @today new_failure_emoji else known_failure_emoji end end end end