Skip to content

Commit

Permalink
Make it generic and awesome
Browse files Browse the repository at this point in the history
  • Loading branch information
halorgium committed Mar 31, 2009
1 parent ba9222b commit 77fc8b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
6 changes: 5 additions & 1 deletion config.yml
Expand Up @@ -7,4 +7,8 @@ pid_path: tmp/github.pid
herault_jid: herault@localhost/herault
actor_path: lib
actors:
- vertebra_github/actors/server
vertebra_github/actors/server:
- "0.0.0.0"
- 9292
- "test"
- "pass"
47 changes: 32 additions & 15 deletions lib/vertebra_github/actors/server.rb
Expand Up @@ -5,33 +5,50 @@
module VertebraGithub
module Actors
class Server < Vertebra::Actor
include Vertebra::Utils
class Unauthorized < StandardError; end
class BadRequest < StandardError; end

def initialize(*args)
super

host, port, @user, @pass = args.first
Thread.new {
Rack::Handler::Mongrel.run(self, :Port => 9292)
Rack::Handler::Mongrel.run(self, :Host => host, :Port => port)
}
end

provides "/github"

def call(env)
auth = Rack::Auth::Basic::Request.new(env)

return Unauthorized unless auth.provided?
return BadRequest unless auth.basic?
username, password = auth.credentials
raise Unauthorized unless @user == username && @pass == password

request = Rack::Request.new(env)
unless request.path_info == "/1ce3b2ec626b82bea91b2f23d8b9080f3f5b4b72"
return [403, {}, "NO"]
end

data = JSON.parse(request.POST['payload'])
pp data
case request.path_info
when "/"
data = JSON.parse(request.POST['payload'])

owner = data['repository']['owner']['name']
repository = data['repository']['name']
data['commits'].each do |commit|
topic = commit['message'].split("\n").first
ref = commit['id'][0,7]
author = commit['author']['name']
args = {:repository => Vertebra::Utils.resource("/repository/github/#{owner}/#{repository}"), :commit => commit}
@agent.request("/code/commit", :single, args)
end

owner = data['repository']['owner']['name']
repository = data['repository']['name']
data['commits'].each do |commit|
args = {:repository => resource("/repository/github/#{owner}/#{repository}"), :commit => commit}
@agent.request("/code/commit", :single, args)
[200, {"Content-Type" => "text/plain"}, "OK"]
else
[404, {}, ""]
end
[200, {"Content-Type" => "text/plain"}, "OK"]
rescue Unauthorized
[401, {'WWW-Authenticate' => %(Basic realm="IrcCat")}, 'Authorization Required']
rescue BadRequest
[400, {}, 'Bad Request']
rescue Exception => e
puts "Got an error: #{e.class}, #{e.message}"
e.backtrace.each do |b|
Expand Down

0 comments on commit 77fc8b5

Please sign in to comment.