This repository has been archived by the owner on May 28, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8246c79
commit 6413dd3
Showing
18 changed files
with
279 additions
and
109 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,29 @@ | ||
# A repository model with the Github Api so it can fetch data | ||
# | ||
class GithubRepo < SimpleDelegator | ||
def initialize(repo, api_client) | ||
@api_client = api_client | ||
|
||
super post_initialize(repo, api_client) | ||
end | ||
|
||
private | ||
|
||
attr_reader :api_client | ||
|
||
def post_initialize(repo, api_client) | ||
repo.commits = latest_commits(repo.path) | ||
repo | ||
end | ||
|
||
def latest_commits(repo_path, branch = 'master') | ||
api_client.list_commits(repo_path, branch).map do |api_response| | ||
Commit.build( | ||
api_response.sha, | ||
api_response.commit.author.name, | ||
api_response.commit.author.date, | ||
api_response.commit.message | ||
) | ||
end | ||
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
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 |
---|---|---|
@@ -1,8 +1,71 @@ | ||
class RepoRater | ||
class << self | ||
def build(repo, rating_klasses = default) | ||
raters = Array(rating_klasses).map { |klass| klass.new(repo) } | ||
new(repo).rate_with(raters) | ||
end | ||
|
||
def default | ||
TimeBasedRepoRater | ||
end | ||
|
||
def rating_klass | ||
RepoRater::Rater | ||
end | ||
end | ||
|
||
MIN = 0 | ||
MAX = 10 | ||
|
||
def rate(github_repo) | ||
fail NotImplementedError, 'This method should be implemented' | ||
def initialize(repo) | ||
@repo = repo | ||
@raters = [] | ||
end | ||
|
||
def rate_with(rating_instances) | ||
@raters = Array(rating_instances) | ||
self | ||
end | ||
|
||
def rate | ||
total = raters_or_default.sum(&:rate) | ||
|
||
mean_avg(total) | ||
end | ||
|
||
class Rater | ||
def initialize(repo) | ||
@repo = repo | ||
end | ||
|
||
def rate | ||
Rails.logger.warn 'This is the default method and should be implemented in subclass' | ||
|
||
min | ||
end | ||
|
||
protected | ||
|
||
attr_reader :repo | ||
|
||
def min | ||
MIN | ||
end | ||
|
||
def max | ||
MAX | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :repo, :raters | ||
|
||
def raters_or_default | ||
@raters_or_default ||= raters.empty? ? Array(Rater.new(repo)) : raters | ||
end | ||
|
||
def mean_avg(total) | ||
total / raters_or_default.size | ||
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
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,17 @@ | ||
class LetterRatingPresenter | ||
def initialize(rating) | ||
@rating = rating | ||
end | ||
|
||
def letter | ||
case @rating | ||
when 1 then "F" | ||
when 2..3 then "E" | ||
when 4..5 then "D" | ||
when 6..7 then "C" | ||
when 8..9 then "B" | ||
when 10 then "A" | ||
else "None" | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
module AppConfig | ||
class << self | ||
attr_accessor :configuration | ||
|
||
delegate :badge_version, to: :configuration | ||
|
||
def configuration | ||
@configuration ||= Configuration.new | ||
end | ||
|
||
def configure | ||
@configuration ||= Configuration.new | ||
yield(configuration) | ||
end | ||
|
||
def reset | ||
@configuration = Configuration.new | ||
end | ||
end | ||
|
||
class Configuration | ||
attr_accessor :badge_version | ||
|
||
def initialize | ||
@badge_version = "VERSION_001" | ||
end | ||
end | ||
end |
Oops, something went wrong.