Skip to content

Instantly share code, notes, and snippets.

@tka
Created August 26, 2013 07:20
Show Gist options
  • Save tka/6338785 to your computer and use it in GitHub Desktop.
Save tka/6338785 to your computer and use it in GitHub Desktop.
app = lambda do |env|
request = Rack::Request.new(env)
puts request.inspect
if request.params["t"] == REQUEST_TOKEN
d = JSON.parse(request.body.read)
x=IO.popen([HIPCHAT_SCRIPT, '-t', HIPCHAT_TOKEN, '-f', HIPCHAT_FROM, '-r', HIPCHAT_ROOM],'w+')
if d["event_name"] # system event
x.write("#{d["project_name"]}: #{d["event_name"]} - #{d["user_name"]}")
else
x.write("#{d["repository"]["name"]} / #{d["ref"][11..-1]} : ")
x.write("\n") if d["commits"].length > 1
d["commits"].each do |commit|
x.write("<a href=\"#{commit["url"]}\">#{commit["id"][0,10]}</a> - #{commit["author"]["name"]} - #{commit["message"]}\n")
end
end
x.close
[200, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["done"]]
else
[200, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["fail"]]
end
end
run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment