Skip to content
Browse files

Handle private github repo

  • Loading branch information...
1 parent 9f0581d commit 1aa53ec8a3d3bcfaa0beeb9f2c7a7db64cf81d3a @sr committed
Showing with 15 additions and 5 deletions.
  1. +7 −3 lib/bobette/github.rb
  2. +8 −2 test/bobette_github_test.rb
View
10 lib/bobette/github.rb
@@ -11,7 +11,7 @@ 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["uri"] = uri(payload.delete("repository"))
payload["branch"] = payload.delete("ref").split("/").last
if (head = payload.delete("after")) && @head.call
payload["commits"] = [{"id" => head}]
@@ -23,8 +23,12 @@ def call(env)
Rack::Response.new("Unparsable payload", 400).finish
end
- def uri(url)
- URI(url).tap { |u| u.scheme = "git" }
+ def uri(repository)
+ if repository["private"]
+ "git@github.com:#{URI(repository["url"]).path[1..-1]}"
+ else
+ URI(repository["url"]).tap { |u| u.scheme = "git" }.to_s
+ end
end
end
end
View
10 test/bobette_github_test.rb
@@ -19,11 +19,12 @@ def setup
$head = false
end
- def github_payload(repo, commits=[], branch="master")
+ def github_payload(repo, commits=[], is_private=false, branch="master")
{ "ref" => "refs/heads/#{branch}",
"after" => commits.last["id"],
"commits" => commits,
- "repository" => {"url" => "http://github.com/#{repo}"} }
+ "repository" => {"url" => "http://github.com/#{repo}",
+ "private" => is_private } }
end
def test_transform_payload
@@ -38,6 +39,11 @@ def test_transform_payload
"branch" => "master",
"commits" => commits }, JSON.parse(response.body))
}
+
+ post("/", :payload => github_payload("integrity/bob", commits, true).to_json) { |response|
+ assert response.ok?
+ assert_equal "git@github.com:integrity/bob", JSON.parse(response.body)["uri"]
+ }
end
def test_head_commit

0 comments on commit 1aa53ec

Please sign in to comment.
Something went wrong with that request. Please try again.