Skip to content

Commit

Permalink
Merge pull request #5 from gorenje/master
Browse files Browse the repository at this point in the history
Hi Gerrit,

Thanks for the pull request and great job on the refactoring! I'm going to pass on the iCal support unfortunately - mostly for bandwidth reasons.

Cheers,
  Lee 🍺
  • Loading branch information
leereilly committed Oct 20, 2011
2 parents 2b63e85 + 80194e1 commit a6259e1
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
db/my.db
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -7,7 +7,7 @@ source "http://gemcutter.org"

gem "addressable", "2.2.5"
gem "bcrypt-ruby", "2.1.4"
gem "bundler", "1.0.7"
gem "bundler", ">= 1.0.7"
gem "configuration", "1.2.0"
gem "data_mapper", "1.1.0"
gem "data_objects", "0.10.5"
Expand Down
127 changes: 127 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,127 @@
GEM
remote: http://rubygems.org/
remote: http://rubygems.org/
remote: http://gems.rubyforge.org/
remote: http://gems.rubyonrails.org/
remote: http://gems.github.com/
remote: http://gemcutter.org/
specs:
addressable (2.2.5)
bcrypt-ruby (2.1.4)
configuration (1.2.0)
data_mapper (1.1.0)
dm-aggregates (= 1.1.0)
dm-constraints (= 1.1.0)
dm-core (= 1.1.0)
dm-migrations (= 1.1.0)
dm-serializer (= 1.1.0)
dm-timestamps (= 1.1.0)
dm-transactions (= 1.1.0)
dm-types (= 1.1.0)
dm-validations (= 1.1.0)
data_objects (0.10.5)
addressable (~> 2.1)
dm-aggregates (1.1.0)
dm-core (~> 1.1.0)
dm-constraints (1.1.0)
dm-core (~> 1.1.0)
dm-core (1.1.0)
addressable (~> 2.2.4)
dm-do-adapter (1.1.0)
data_objects (~> 0.10.2)
dm-core (~> 1.1.0)
dm-migrations (1.1.0)
dm-core (~> 1.1.0)
dm-mysql-adapter (1.1.0)
dm-do-adapter (~> 1.1.0)
do_mysql (~> 0.10.2)
dm-serializer (1.1.0)
dm-core (~> 1.1.0)
fastercsv (~> 1.5.4)
json (~> 1.4.6)
dm-sqlite-adapter (1.1.0)
dm-do-adapter (~> 1.1.0)
do_sqlite3 (~> 0.10.2)
dm-timestamps (1.1.0)
dm-core (~> 1.1.0)
dm-transactions (1.1.0)
dm-core (~> 1.1.0)
dm-types (1.1.0)
bcrypt-ruby (~> 2.1.4)
dm-core (~> 1.1.0)
fastercsv (~> 1.5.4)
json (~> 1.4.6)
stringex (~> 1.2.0)
uuidtools (~> 2.1.2)
dm-validations (1.1.0)
dm-core (~> 1.1.0)
do_mysql (0.10.5)
data_objects (= 0.10.5)
do_sqlite3 (0.10.5)
data_objects (= 0.10.5)
fastercsv (1.5.4)
heroku (2.1.4)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
term-ansicolor (~> 1.0.5)
json (1.4.6)
launchy (0.4.0)
configuration (>= 0.0.5)
rake (>= 0.8.1)
mime-types (1.16)
mysql (2.8.1)
rack (1.2.2)
rake (0.8.7)
rest-client (1.6.1)
mime-types (>= 1.16)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
stringex (1.2.1)
term-ansicolor (1.0.5)
tilt (1.3)
uuidtools (2.1.2)

PLATFORMS
ruby

DEPENDENCIES
addressable (= 2.2.5)
bcrypt-ruby (= 2.1.4)
bundler (>= 1.0.7)
configuration (= 1.2.0)
data_mapper (= 1.1.0)
data_objects (= 0.10.5)
dm-aggregates (= 1.1.0)
dm-constraints (= 1.1.0)
dm-core (= 1.1.0)
dm-do-adapter (= 1.1.0)
dm-migrations (= 1.1.0)
dm-mysql-adapter (= 1.1.0)
dm-serializer (= 1.1.0)
dm-sqlite-adapter (= 1.1.0)
dm-timestamps (= 1.1.0)
dm-transactions (= 1.1.0)
dm-types (= 1.1.0)
dm-validations (= 1.1.0)
do_mysql (= 0.10.5)
do_sqlite3 (= 0.10.5)
fastercsv (= 1.5.4)
heroku (= 2.1.4)
json (= 1.4.6)
launchy (= 0.4.0)
mime-types (= 1.16)
mysql (= 2.8.1)
rack (= 1.2.2)
rake (= 0.8.7)
rest-client (= 1.6.1)
sinatra (= 1.2.6)
sqlite3 (= 1.3.3)
sqlite3-ruby (= 1.3.3)
stringex (= 1.2.1)
term-ansicolor (= 1.0.5)
tilt (= 1.3)
uuidtools (= 2.1.2)
42 changes: 38 additions & 4 deletions README.md
Expand Up @@ -2,24 +2,58 @@

Github High Scores is a fun way to rank Github repository contributors in a 8-bit, 80's-tastic viewing environment.

## iCalendar

This is an extension to convert the most recent commit log of a repo into [iCalendar](http://tools.ietf.org/html/rfc5545) format, to be included into iCal.

This will generate events which are 30 minutes in duration -- there is no really easy way to specify a duration for a commit.

To use:
http://example.com/<user>/<repo>.ics
http://example.com/<user>/<repo>/<branch>.ics

branch defaults to master, if not provided.

## Installation

git clone git://github.com/leereilly/github-high-scores.git
rvm install ruby-1.8.7-p334 ## didn't have correct version
cd github-high-scores
ruby app.rb
gem install bundler
bundle
db_use=sqlite_default ruby app.rb

## Configuration

You'll need to set environment variables on your box. Locally, you can set them in your .bash_profile...
You can either use mysql, sqlite or sqlite with default setting

For mysql:

You'll need to set environment variables on your box. Locally, you can
set them in your .bash_profile...

export db_use=mysql
export db_user=some_username
export db_pass=some_password
export db_host=some_host
export db_data=some_database

On Heroku, you can do something like this...

heroku config:add db_user=XXX db_pass=XXX db_host=XXX db_data=XXX
heroku config:add db_user=XXX db_pass=XXX db_host=XXX db_data=XXX db_use=mysql

For sqlite:

export db_use=sqlite
export db_path=/some/absolute/path/to/my.db

For sqlite + default:

export db_use=sqlite_default

This then creates a my.db database file in db/

See app.rb for details.

## Contribute

Expand All @@ -42,4 +76,4 @@ Fork + pull.
* The GitHub API only allows 60 requests per minute per IP address.
* The site looks like some sort of 80s-tastic arcade theme.

![Bugs](http://i.imgur.com/K8vsw.gif "Bugs")
![Bugs](http://i.imgur.com/K8vsw.gif "Bugs")
67 changes: 48 additions & 19 deletions app.rb
Expand Up @@ -6,20 +6,34 @@
require 'json'
require 'erb'
require 'uri'

require 'data_mapper'
require 'dm-migrations'

DataMapper::Logger.new($stdout, :debug)
dburl = case ENV['db_use']
when 'mysql' then ("mysql://#{ENV['db_user']}:#{ENV['db_pass']}@"+
"#{ENV['db_host']}/#{ENV['db_data']}")
when 'sqlite' then "sqlite3://#{ENV['db_path']}"
when 'sqlite_default' then "sqlite3://#{Dir.pwd}/db/my.db"
else
puts "REQUIRED: please provide a value for db_use -- see README.md"
exit
end
DataMapper.setup(:default, dburl)

require 'helpers'
require 'User'
require 'Repo'

DataMapper::Logger.new(STDOUT, :debug)
require 'Commit'

disable :show_exceptions
set :environment, :production

error do
@title = "404"
@text = "Sorry, but this cat is in another castle!"
@display_small_search = false
erb :not_found
erb :not_found
end

get '/' do
Expand All @@ -30,7 +44,7 @@
@user = get_user_from_github_url(@github_url)
@repo = get_repo_from_github_url(@github_url)
@high_scores = get_high_scores(@user, @repo)
@display_small_search = true
@display_small_search = true
redirect "/#{@user}/#{@repo}/high_scores/"
else
@title = 'High Scores'
Expand All @@ -47,27 +61,42 @@
end

get '/recent_searches/?' do
@repos = Repo.all(:limit => 5, :order => [ :updated_at.desc ])
@repos = Repo.all(:limit => 5, :order => [ :updated_at.desc ])
puts @repos.inspect
@display_small_search = true
erb :recent_searches
end


get '/credits/?' do
erb :credits
end

get '/help/?' do
@display_small_search = true
@display_small_search = true
erb :help
end

get '/about/?' do
@display_small_search = true
@display_small_search = true
erb :about
end

get '/:user/:repo/:branch.ics' do
@branch = params[:branch]
@user = User::create_from_username(params[:user])
@repo = Repo::create_from_username_and_repo(params[:user], params[:repo])
@commits = Commit::find_for(@repo, @branch)
[200, { "Content-Type"=> "text/calendar; charset=UTF-8" }, erb(:ical)]
end

get '/:user/:repo.ics' do
@branch = "master"
@user = User::create_from_username(params[:user])
@repo = Repo::create_from_username_and_repo(params[:user], params[:repo])
@commits = Commit::find_for(@repo, @branch)
[200, { "Content-Type"=> "text/calendar; charset=UTF-8" }, erb(:ical)]
end

get '/:user/:repo/?' do
@user = User::create_from_username(params[:user])
@repo = Repo::create_from_username_and_repo(params[:user], params[:repo])
Expand All @@ -87,33 +116,33 @@
erb :not_found
end

def sanitize_input(url)
def sanitize_input(url)
url = url.downcase

# Special rules for Github URLs starting with 'github.com'
if url[0..9] == 'github.com'
url = 'https://www.github.com' + url[9..url.size]

# Special rules for Github URLs starting with 'www.github.com'
elsif url[0..13] == 'www.github.com'
url = 'https://www.github.com' + url[13..url.size]
end

# Special rules for Github URLs ending in 'git'
if url[-4,4] == '.git'
url = url[0..-5]
end

url = url.gsub("http://", "https://")
url = url.gsub("git@github.com:", "https://www.github.com/")
url = url.gsub("git://", "https://www.")

# If someone just passes in user/repo e.g. leereilly/leereilly.net
tokens = url.split('/')
if tokens.size == 2
url = "https://www.github.com/#{tokens[0]}/#{tokens[1]}"
end

return url
end

Expand All @@ -132,7 +161,7 @@ def get_high_scores(user, repo)
puts "Storing user: #{stored_user}"
stored_repo = Repo::create_from_username_and_repo(user, repo)
puts "Storing repo: #{stored_repo}"

contributors_url = "http://github.com/api/v2/json/repos/show/#{user}/#{repo}/contributors"

contributors_feed = Net::HTTP.get_response(URI.parse(contributors_url))
Expand All @@ -149,7 +178,7 @@ def get_high_scores(user, repo)
user_hash[:location] = repository_contributor['location']
user_hash[:contributions] = repository_contributor['contributions'].to_i
contributors_array << user_hash
end
end
return contributors_array
rescue
raise "Sorry, this GitHub repository doesn't seem to exist or is private"
Expand Down

0 comments on commit a6259e1

Please sign in to comment.