lib/dri/commands/fetch/failures.rb in dri-0.1.2 vs lib/dri/commands/fetch/failures.rb in dri-0.1.3

- old
+ new

@@ -6,10 +6,12 @@ module Dri module Commands class Fetch class Failures < Dri::Command + using Refinements + def initialize(options) @options = options @today_iso_format = Time.now.strftime('%Y-%m-%dT00:00:00Z') end @@ -24,39 +26,42 @@ failures = [] urgent = [] labels = [ title, triaged, author, url ] triaged_counter = 0 - logger.info "Fetching today\'s failures..." - - spinner.run do + logger.info "Fetching today's failures..." + spinner.run do + response = api_client.fetch_failures(date: @today_iso_format, state: 'opened') if response.nil? - logger.info "Life is great, there are no new failures today!" + logger.info 'Life is great, there are no new failures today!' exit 0 end response.each do |failure| - title = truncate(failure["title"], 60) - author = failure["author"]["username"] - url = failure["web_url"] - award_emoji_url = failure["_links"]["award_emoji"] + title = failure['title'].truncate(60) + author = failure['author']['username'] + url = failure['web_url'] + award_emoji_url = failure['_links']['award_emoji'] triaged = add_color('x', :red) - emoji_awards = api_client.fetch_awarded_emojis(award_emoji_url) + emoji_awards = api_client.fetch_awarded_emojis(award_emoji_url).find do |e| + e['name'] == emoji && e['user']['username'] == username + end - triaged = add_color('✓', :green) && triaged_counter += 1 if emoji_awards.find do |e| - e['name'] == emoji && e['user']['username'] == @username + if emoji_awards + triaged = add_color('✓', :green) + triaged_counter += 1 end if @options[:urgent] - labels = failure["labels"] + labels = failure['labels'] labels.each do |label| - if label.include? ("found:canary.gitlab.com" && "found:canary.staging.gitlab.com") + if label.include? ('found:canary.gitlab.com' && 'found:canary.staging.gitlab.com') urgent << [title, triaged, author, url] end end end @@ -65,21 +70,15 @@ end if @options[:urgent] table = TTY::Table.new(labels, urgent) puts table.render(:ascii, resize: true, alignments: [:center, :center, :center, :center]) - output.puts "\nFound: #{urgent.size} urgent failures, ocurring in both canary.gitlab.com and canary.staging.gitlab.com." + output.puts "\nFound: #{urgent.size} urgent failures, occurring in both canary.gitlab.com and canary.staging.gitlab.com." else table = TTY::Table.new(labels, failures) puts table.render(:ascii, resize: true, alignments: [:center, :center, :center, :center]) output.puts "\nFound: #{failures.size} failures, of these #{triaged_counter} have been triaged with a #{emoji}." end - end - - private - - def truncate(string, max) - string.length > max ? "#{string[0...max]}..." : string end end end end end