From d1275f342f0e19f1a8b112bc2f968c8009a78d40 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Mon, 3 Sep 2018 13:58:04 +0200 Subject: [PATCH] Display richer status tooltips --- app/helpers/releases_helper.rb | 20 ++++++++++++++++---- app/models/github_status.rb | 26 +++++++++++++++++++++++++- app/views/releases/_release.html.erb | 4 ++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/helpers/releases_helper.rb b/app/helpers/releases_helper.rb index c6b5cc964b..290654bb88 100644 --- a/app/helpers/releases_helper.rb +++ b/app/helpers/releases_helper.rb @@ -24,10 +24,22 @@ def release_label(project, release) ) end - def github_commit_status_icon(status_state) - icon = GITHUB_STATUS_ICONS.fetch(status_state) - text = GITHUB_STATUS_TEXT_LABELS.fetch(status_state) - title = "Github status: #{status_state}" + def github_commit_status_icon(status) + failed = status.failed + succeeded = status.succeeded + errored = status.errored + pending = status.pending + + status_counts = [] + status_counts << "#{failed.count} failed" if failed.any? + status_counts << "#{succeeded.count} succeeded" if succeeded.any? + status_counts << "#{errored.count} errored" if errored.any? + status_counts << "#{pending.count} pending" if pending.any? + + title = "Github status: #{status_counts.join(', ')}" + + icon = GITHUB_STATUS_ICONS.fetch(status.state) + text = GITHUB_STATUS_TEXT_LABELS.fetch(status.state) icon_tag icon, class: "text-#{text}", 'data-toggle': "tooltip", 'data-placement': "right", title: title end diff --git a/app/models/github_status.rb b/app/models/github_status.rb index 0d4e337025..4c0c94edb6 100644 --- a/app/models/github_status.rb +++ b/app/models/github_status.rb @@ -21,6 +21,10 @@ def failure? state == "failure" end + def error? + state == "error" + end + def pending? state == "pending" end @@ -33,6 +37,10 @@ def initialize(state, statuses) @statuses = statuses end + def self.missing + @missing ||= new("missing", []) + end + def self.fetch(repo, ref) cache_key = [name, repo, ref] @@ -46,7 +54,7 @@ def self.fetch(repo, ref) end # Fall back to a "missing" status. - return new("missing", []) if response.nil? + return missing if response.nil? statuses = response.statuses.group_by(&:context).map do |context, statuses| Status.new(context, statuses.max_by { |status| status.created_at.to_i }) @@ -60,6 +68,22 @@ def self.fetch(repo, ref) new(response.state, statuses) end + def succeeded + statuses.select(&:success?) + end + + def failed + statuses.select(&:failure?) + end + + def errored + statuses.select(&:error?) + end + + def pending + statuses.select(&:pending?) + end + def success? state == "success" end diff --git a/app/views/releases/_release.html.erb b/app/views/releases/_release.html.erb index fbb3869c17..4b0453d02e 100644 --- a/app/views/releases/_release.html.erb +++ b/app/views/releases/_release.html.erb @@ -4,9 +4,9 @@ <% if github_ok? %> - <%= github_commit_status_icon release.github_status.state %> + <%= github_commit_status_icon release.github_status %> <% else %> - <%= github_commit_status_icon "missing" %> + <%= github_commit_status_icon GithubStatus.missing %> <% end %>