Skip to content

Commit

Permalink
Added pirate badge #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Henri Symoneaux committed Oct 24, 2017
1 parent cdb90da commit 1d527e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/leaderboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
require 'open-uri'

include Concurrent

ORG_URL = 'https://api.github.com/repos/ourtigarage'.freeze
SNAKE_URL = "#{ORG_URL}/web-snake".freeze
LEADERBOARD_URL = "#{ORG_URL}/hacktoberfest-leaderboard".freeze
BASE_API_URL = 'https://api.github.com'.freeze
BASE_REPOS_URL = "#{BASE_API_URL}/repos".freeze
ORG_REPOS_URL = "#{BASE_REPOS_URL}/ourtigarage".freeze
SNAKE_URL = "#{ORG_REPOS_URL}/web-snake".freeze
LEADERBOARD_URL = "#{ORG_REPOS_URL}/hacktoberfest-leaderboard".freeze

# Class reprensenting a badge a player can earn
class Badge
Expand All @@ -31,9 +32,10 @@ def earned_by?(player)
Badge.new('snake', 'The snake charmer', 'Submitted 1 Pull Request to the <a href="https://ourtigarage.github.io/web-snake/">snake game</a>\'s code repository', &:contributed_to_snake?),
Badge.new('leaderboard', 'The leaderboard contributor', 'Submitted 1 Pull Request to this leaderboard\'s code repository', &:contributed_to_leaderboard?),
Badge.new('10-contributions', 'The Pull Request champion', 'Submitted more than 10 Pull requests', &:ten_contributions?),
Badge.new('adventure', 'The adventurer', 'Submitted 1 Pull Request to a repository out of <a href="https://github.com/ourtigarage">ourtigarage</a> organisation', &:contributed_out_of_org?),
Badge.new('adventure', 'The adventurer', 'Submitted 1 Pull Request to a repository he does not own, out of <a href="https://github.com/ourtigarage">ourtigarage</a> organisation', &:contributed_out_of_org?),
Badge.new('novelist', 'The novelist', 'Wrote more than 100 words in a Pull Request\'s description', &:contribution_with_100_words?),
Badge.new('taciturn', 'The taciturn', 'Submitted a Pull Request with no description', &:contribution_with_no_word?)
Badge.new('taciturn', 'The taciturn', 'Submitted a Pull Request with no description', &:contribution_with_no_word?),
Badge.new('pirate', 'The pirate', 'A lawless pirate who submitted Pull Requests to his own repositories. Cheater...', &:contribution_to_own_repos?)
].freeze

# The leaderboard root class, where the magic happens
Expand Down Expand Up @@ -119,6 +121,7 @@ def initialize(github_user, contributions)
@username = github_user.login
@avatar = github_user.avatar_url
@profile = github_user.html_url
@repos_base_url
@contributions = contributions
end

Expand Down Expand Up @@ -150,7 +153,7 @@ def ten_contributions?
end

def contributed_out_of_org?
contributions.any? { |c| !c.repository_url.start_with? ORG_URL }
contributions.any? { |c| !c.repository_url.start_with?(ORG_REPOS_URL) && !c.repository_url.start_with?("#{BASE_REPOS_URL}/#{@username}") }
end

def contribution_with_100_words?
Expand All @@ -161,6 +164,10 @@ def contribution_with_no_word?
contributions.any? { |c| c.body.strip.empty? }
end

def contribution_to_own_repos?
contributions.any? { |c| c.repository_url.start_with? "#{BASE_REPOS_URL}/#{@username}" }
end

def badges
BADGES.select { |b| b.earned_by?(self) }
end
Expand Down
Binary file added static/img/badges/pirate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1d527e4

Please sign in to comment.