Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display richer status tooltips #2919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/helpers/releases_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like that to avoid duplication here and also having to add another 4 copy-pasty methods that need to stay in sync with this code

[:failed?, :errored?, :pending?, :succeeded?].map do |status|
  found = status.status.select(&status)
  "#{found} #{status.to_s.sub('?', '')}" if found.any?
end.compact

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take repetition over cleverness any day of the week...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use this to make it less clever/more repetitive but still dry, also solves all the 'missing test coverage' errors

[['failed, ':failed?], ['errored', :errored?], ['pending', :pending?], ['succeeded', :succeeded?]].map do |name, status|
  found = status.status.select(&status)
  "#{found} #{name}" if found.any?
end.compact


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
Expand Down
26 changes: 25 additions & 1 deletion app/models/github_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def failure?
state == "failure"
end

def error?
state == "error"
end

def pending?
state == "pending"
end
Expand All @@ -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]

Expand All @@ -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 })
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/releases/_release.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
</td>
<td>
<% 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 %>
</td>
<td>
Expand Down