Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
Handle private github repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Jul 1, 2009
1 parent 9f0581d commit 1aa53ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/bobette/github.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def call(env)
payload = Rack::Request.new(env).POST["payload"] || "" payload = Rack::Request.new(env).POST["payload"] || ""
payload = JSON.parse(payload) payload = JSON.parse(payload)
payload["kind"] = "git" 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 payload["branch"] = payload.delete("ref").split("/").last
if (head = payload.delete("after")) && @head.call if (head = payload.delete("after")) && @head.call
payload["commits"] = [{"id" => head}] payload["commits"] = [{"id" => head}]
Expand All @@ -23,8 +23,12 @@ def call(env)
Rack::Response.new("Unparsable payload", 400).finish Rack::Response.new("Unparsable payload", 400).finish
end end


def uri(url) def uri(repository)
URI(url).tap { |u| u.scheme = "git" } 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 end
end end
10 changes: 8 additions & 2 deletions test/bobette_github_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def setup
$head = false $head = false
end end


def github_payload(repo, commits=[], branch="master") def github_payload(repo, commits=[], is_private=false, branch="master")
{ "ref" => "refs/heads/#{branch}", { "ref" => "refs/heads/#{branch}",
"after" => commits.last["id"], "after" => commits.last["id"],
"commits" => commits, "commits" => commits,
"repository" => {"url" => "http://github.com/#{repo}"} } "repository" => {"url" => "http://github.com/#{repo}",
"private" => is_private } }
end end


def test_transform_payload def test_transform_payload
Expand All @@ -38,6 +39,11 @@ def test_transform_payload
"branch" => "master", "branch" => "master",
"commits" => commits }, JSON.parse(response.body)) "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 end


def test_head_commit def test_head_commit
Expand Down

0 comments on commit 1aa53ec

Please sign in to comment.