Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from rubytoolbox/co-project-health
Project health checks and display
- Loading branch information
Showing
15 changed files
with
421 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.project-health-tags | ||
@extend .field, .is-grouped, .is-grouped-multiline | ||
|
||
.project-health-tag | ||
@extend .control | ||
&.level-green | ||
.tag | ||
@extend .is-success | ||
&.level-yellow | ||
.tag | ||
@extend .is-warning | ||
&.level-red | ||
.tag | ||
@extend .is-danger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
# | ||
# Creates a health assessment for given project instance based on health checks defined | ||
# in Project::Health::Checks | ||
# | ||
class Project::Health | ||
class Status | ||
attr_accessor :key, :level, :icon, :check_block | ||
def initialize(key, level, icon, &check_block) | ||
self.key = key | ||
self.level = level | ||
self.icon = icon | ||
self.check_block = check_block | ||
|
||
raise ArgumentError, "Unknown level #{level}" unless %i[red yellow green].include? level | ||
raise I18n::MissingTranslation.new(I18n.locale, i18n_key) unless I18n.exists? i18n_key | ||
end | ||
|
||
def label | ||
I18n.t i18n_key | ||
end | ||
|
||
def applies?(project) | ||
!!check_block.call(project) | ||
end | ||
|
||
private | ||
|
||
def i18n_key | ||
"project_health.#{key}" | ||
end | ||
end | ||
|
||
HEALTHY_STATUS = Project::Health::Status.new(:healthy, :green, :heartbeat, &:present?) | ||
|
||
attr_accessor :project, :checks | ||
private :project=, :checks= | ||
|
||
def initialize(project) | ||
self.project = project | ||
self.checks = Checks::ALL | ||
end | ||
|
||
def status | ||
@status ||= checks.select { |check| check.applies? project }.presence || [HEALTHY_STATUS] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module Project::Health::Checks | ||
GITHUB_REPO_ARCHIVED = Project::Health::Status.new(:github_repo_archived, :red, :github, &:github_repo_archived?) | ||
|
||
GITHUB_REPO_GONE = Project::Health::Status.new(:github_repo_gone, :red, :github) do |project| | ||
project.github_repo_path? && | ||
project.github_repo.nil? | ||
end | ||
|
||
GITHUB_REPO_NO_COMMIT_ACTIVITY = Project::Health::Status.new(:no_commit_activity, :red, :github) do |project| | ||
project.github_repo_repo_pushed_at && | ||
project.github_repo_repo_pushed_at < 3.years.ago | ||
end | ||
|
||
GITHUB_REPO_LOW_COMMIT_ACTIVITY = Project::Health::Status.new(:low_commit_activity, :yellow, :github) do |project| | ||
!GITHUB_REPO_NO_COMMIT_ACTIVITY.applies?(project) && | ||
project.github_repo_average_recent_committed_at && | ||
project.github_repo_average_recent_committed_at < 3.years.ago | ||
end | ||
|
||
GITHUB_REPO_OPEN_ISSUES = Project::Health::Status.new(:github_repo_open_issues, :yellow, :github) do |project| | ||
project.github_repo_total_issues_count && | ||
project.github_repo_total_issues_count > 5 && | ||
project.github_repo_issue_closure_rate < 75 | ||
end | ||
|
||
RUBYGEM_ABANDONED = Project::Health::Status.new(:rubygem_abandoned, :red, :diamond) do |project| | ||
project.rubygem_latest_release_on && | ||
project.rubygem_latest_release_on < 3.years.ago | ||
end | ||
|
||
RUBYGEM_STALE = Project::Health::Status.new(:rubygem_stale, :yellow, :diamond) do |project| | ||
!RUBYGEM_ABANDONED.applies?(project) && | ||
project.rubygem_latest_release_on && | ||
project.rubygem_latest_release_on < 1.year.ago | ||
end | ||
|
||
RUBYGEM_LONG_RUNNING = Project::Health::Status.new(:rubygem_long_running, :green, :diamond) do |project| | ||
project.rubygem_latest_release_on && | ||
project.rubygem_first_release_on && | ||
project.rubygem_first_release_on < 5.years.ago && | ||
project.rubygem_latest_release_on > 1.year.ago | ||
end | ||
|
||
ALL = [ | ||
GITHUB_REPO_ARCHIVED, | ||
GITHUB_REPO_GONE, | ||
GITHUB_REPO_NO_COMMIT_ACTIVITY, | ||
RUBYGEM_ABANDONED, | ||
GITHUB_REPO_LOW_COMMIT_ACTIVITY, | ||
GITHUB_REPO_OPEN_ISSUES, | ||
RUBYGEM_STALE, | ||
RUBYGEM_LONG_RUNNING, | ||
].freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.project-health-tag class="level-#{status.level}" | ||
.tags.has-addons | ||
span.tag | ||
span.icon: i.fa class="fa-#{status.icon}" | ||
strong.tag= status.label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.hero | ||
section.section: .container | ||
p.heading= link_to "Ruby Toolbox UI Components Styleguide", "/pages/components" | ||
h2= current_page.split("/").last.humanize | ||
|
||
= component_example "Project Health tags" do | ||
.project-health-tags | ||
= project_health_tag Project::Health::HEALTHY_STATUS | ||
- Project::Health::Checks::ALL.each do |status| | ||
= project_health_tag status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.