Skip to content

Instantly share code, notes, and snippets.

@nashby
Created August 7, 2011 10:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nashby/1130270 to your computer and use it in GitHub Desktop.
Save nashby/1130270 to your computer and use it in GitHub Desktop.
who is to blame?
require 'sinatra'
require 'open-uri'
require 'json'
require 'nokogiri'
class Github
def initialize owner, project, sha
@owner = owner
@project = project
@sha = sha
end
def user_info
@user_info ||= JSON.parse(open("https://api.github.com/users#{username}").read)
end
private
def commit_page
@commit_page ||= Nokogiri::HTML(open("https://github.com/#{@owner}/#{@project}/commit/#{@sha}").read)
end
def username
commit_page.xpath("//div[@class='name']/a/@href").first.value
end
end
class Travis
def initialize owner, project
@owner = owner
@project = project
end
def status
project_info["last_build_status"]
end
def id
project_info["last_build_id"]
end
def last_commit
build_info["commit"]
end
private
def project_info
@project_info ||= JSON.parse(open("http://travis-ci.org/#{@owner}/#{@project}.json").read)
end
def build_info
@build_info ||= JSON.parse(open("http://travis-ci.org/#{@owner}/#{@project}/builds/#{id}.json").read)
end
end
get '/' do
form = "<div style='text-align:center; margin-top:10%'>
<form action='/'>
<label for='user'>Owner:</label>
<input name='user' />
<label for='project'>Project:</label>
<input name='project' />
<input type='submit' value='Blame!' />
</form>
</div>"
if params[:user] && params[:project]
travis = Travis.new(params[:user], params[:project])
if travis.status == 1
github = Github.new(params[:user], params[:project], travis.last_commit)
user = github.user_info
"<html>
<head></head>
<body>
<header style='text-align:center'>
<h2>Who is to blame?</h2>
<h3>Build status of #{params[:project]}: <span style='color:red'>Failed!</span></h3>
</header>
<div style='margin-top:10%;margin-left:40%'>
<span style='margin-left:10%'>
<img src='#{user['avatar_url']}' />
</span>
<p>Name: #{user['name']}</p>
<p>Github: <a href='#{user['html_url']}'>#{user['login']}</a></p>
<p>Email: #{user['email']}</p>
<p>Location: #{user['location']}</p>
</div>
#{form}
</body>
</html>"
else
"<html>
<head></head>
<body>
<header style='text-align:center'>
<h2>Who is to blame?</h2>
<h3>Build status of #{params[:project]}: <span style='color:green'>Passed!</span></h3>
</header>
<div style='margin-top:10%;margin-left:40%'>
<h1>No blame! <3 </h1>
</div>
#{form}
</body>
</html>"
end
else
"<html>
<head></head>
<body>
<header style='text-align:center'>
<h2>Who is to blame?</h2>
</header>
#{form}
</body>
</html>"
end
end
@joshk
Copy link

joshk commented Aug 8, 2011

I love this!

Simple but hits the mark.

Please create a patch for our about.travis-ci.org site and add a link to this app :)

@jeffkreeftmeijer
Copy link

Just thought this was a fun reaction to your entry in #travis on freenode:

[4:43pm] josh-k: http://whoistoblame.heroku.com/?user=travis-ci&project=travis-ci
[4:43pm] josh-k: cesario: ^^
[4:43pm] josh-k: hahahaha
[4:45pm] cesario: josh-k: DAMMIT
[4:45pm] cesario: this app is borked! :)
[4:46pm] josh-k: hahaha
[4:46pm] antares_: josh-k: who's the author? :)
[4:46pm] cesario: i should fix the test now to see that disappear :P
[4:47pm] josh-k: i love the entries to codebrawl
[4:48pm] antares_: ah
[4:48pm] antares_: this is a codebrawl contestant
[4:48pm] josh-k: yep
[4:49pm] antares_: maybe jkreeftmeijer needs to do app reviews or something, this is inappropriate :P
[4:49pm] antares_: I am not to blame for anything but it is only a matter of time ;)
[4:50pm] josh-k: ahahahahahaa
[4:50pm] josh-k: why is it inappropriate?
[4:50pm] josh-k: its great
[4:51pm] antares_: it is greatly inappropriate ;)

Note: @cesario didn't break the build, it was like that when he got there. ;)

@nashby
Copy link
Author

nashby commented Aug 8, 2011

Haha, thanks, guys! :)
@cesario, sorry, bro, but you must fix it! ;)

@franckverrot
Copy link

@nashby eheh, we're cool, i love it!

@nashby
Copy link
Author

nashby commented Aug 8, 2011

@joshk, Ok, I'll create a pull request soon, but I think before it I should rewrite it a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment