require_relative '../../command' require_relative '../../utils/markdown_lists' require_relative "../../report" require 'markdown-tables' require 'fileutils' require "uri" module Dri module Commands class Publish class Report < Dri::Command def initialize(options) @options = options @date = Date.today @time = Time.now.to_i end def execute(input: $stdin, output: $stdout) verify_config_exists report = Dri::Report.new(config) logger.info "Fetching triaged failures with award emoji #{emoji}..." spinner.start issues = api_client.fetch_triaged_failures(emoji: emoji, state: 'opened') spinner.stop if issues.empty? logger.warn "Found no issues associated with \"#{emoji}\" emoji. Will exit. Bye 👋" exit 1 end logger.info "Assembling the report... " # sets each failure on the table action_options = ["pinged SET", "reproduced", "transient", "quarantined"] spinner.start issues.each do |issue| actions = [] if @options[:actions] actions = prompt.multi_select("Please mark the actions on #{add_color(issue['title'], :yellow)}: ", action_options) end report.add_failure(issue, actions) end if @options[:format] == 'list' # generates markdown list with failures format_style = Utils::MarkdownLists.make_list(report.labels, report.failures) unless report.failures.empty? else # generates markdown table with rows as failures format_style = MarkdownTables.make_table(report.labels, report.failures, is_rows: true, align: %w[c l c l l]) unless report.failures.empty? end report.set_header(timezone, username) note = "#{report.header}\n\n#{format_style}" spinner.stop # creates an .md file with the report locally in /handover_reports if @options[:dry_run] logger.info "Downloading the report... " spinner.start FileUtils.mkdir_p("#{Dir.pwd}/handover_reports") report_path = "handover_reports/report-#{@date}-#{@time}.md" File.open(report_path, 'a') do |out_file| out_file.puts note end spinner.stop output.puts "Done! ✅\n" logger.success "Report is ready at: #{report_path}" exit 0 end # sends note to the weekly triage report issues = api_client.fetch_current_triage_issue current_issue_iid = issues[0]["iid"] response = api_client.post_triage_report_note(iid: current_issue_iid, body: note) output.puts "Done! ✅\n" logger.success "Thanks @#{username}, your report was posted at https://gitlab.com/gitlab-org/quality/pipeline-triage/-/issues/#{current_issue_iid} 🎉" end end end end end