Class: Bobette::GitHub
- Inherits:
-
Object
- Object
- Bobette::GitHub
- Defined in:
- lib/bobette/github.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, &block) ⇒ GitHub
constructor
A new instance of GitHub.
- #uri(url) ⇒ Object
Constructor Details
#initialize(app, &block) ⇒ GitHub
Returns a new instance of GitHub.
5 6 7 8 |
# File 'lib/bobette/github.rb', line 5 def initialize(app, &block) @app = app @head = block || Proc.new { false } end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bobette/github.rb', line 10 def call(env) payload = Rack::Request.new(env).POST["payload"] || "" payload = JSON.parse(payload) payload["kind"] = "git" payload["uri"] = uri(payload.delete("repository")["url"]).to_s payload["branch"] = payload.delete("ref").split("/").last if (head = payload.delete("after")) && @head.call payload["commits"] = [{"id" => head}] end env["bobette.payload"] = payload @app.call(env) rescue JSON::JSONError Rack::Response.new("Unparsable payload", 400).finish end |
#uri(url) ⇒ Object
26 27 28 |
# File 'lib/bobette/github.rb', line 26 def uri(url) URI(url).tap { |u| u.scheme = "git" } end |