Permalink
Browse files

create, edit and remove a hook

  • Loading branch information...
1 parent 543421f commit cbf8367d46abdcd656644a0d91aee355349c64cc @flyerhzm flyerhzm committed May 17, 2012
Showing with 50 additions and 1 deletion.
  1. +14 −0 lib/octokit/client/repositories.rb
  2. +36 −1 spec/octokit/client/repositories_spec.rb
@@ -135,6 +135,20 @@ def hook(repo, id, options={})
get "/repos/#{Repository.new repo}/hooks/#{id}", options, 3
end
+ def create_hook(repo, name, config, options={})
+ options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
+ post "/repos/#{Repository.new repo}/hooks", options, 3
+ end
+
+ def edit_hook(repo, id, name, config, options={})
+ options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
+ patch "/repos/#{Repository.new repo}/hooks/#{id}", options, 3
+ end
+
+ def remove_hook(repo, id, options={})
+ delete "/repos/#{Repository.new repo}/hooks/#{id}", options, 3
+ end
+
# Get all Issue Events for a given Repository
#
# @param repo [String, Repository, Hash] A GitHub repository
@@ -330,7 +330,7 @@
describe ".hook" do
- it "should return a repository's hooks" do
+ it "should return a repository's single hook" do
stub_get("/repos/railsbp/railsbp.com/hooks/154284").
to_return(:body => fixture("v3/hook.json"))
hook = @client.hook("railsbp/railsbp.com", 154284)
@@ -339,6 +339,41 @@
end
+ describe ".create_hook" do
+
+ it "should create a hook" do
+ stub_post("/repos/railsbp/railsbp.com/hooks").
+ with(:body => {:name => "railsbp", :config => {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"}, :events => ["push"], :active => true}).
+ to_return(:body => fixture("v3/hook.json"))
+ hook = @client.create_hook("railsbp/railsbp.com", "railsbp", {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"})
+ hook.id.should == 154284
+ end
+
+ end
+
+ describe ".edit_hook" do
+
+ it "should edit a hook" do
+ stub_patch("/repos/railsbp/railsbp.com/hooks/154284").
+ with(:body => {:name => "railsbp", :config => {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"}, :events => ["push"], :active => true}).
+ to_return(:body => fixture("v3/hook.json"))
+ hook = @client.edit_hook("railsbp/railsbp.com", 154284, "railsbp", {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"})
+ hook.id.should == 154284
+ hook.config.token.should == "xAAQZtJhYHGagsed1kYR"
+ end
+
+ end
+
+ describe ".remove_hook" do
+
+ it "should remove a hook" do
+ stub_delete("/repos/railsbp/railsbp.com/hooks/154284").
+ to_return(:status => 204)
+ @client.remove_hook("railsbp/railsbp.com", 154284).should be_nil
+ end
+
+ end
+
describe ".events" do
it "should list event for all issues in a repository" do

0 comments on commit cbf8367

Please sign in to comment.