Skip to content

Commit

Permalink
add project_hook and edit_project_hook methods
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Oct 19, 2012
1 parent e7eccd2 commit 6c5637e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/gitlab/client/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ def project_hooks(project, options={})
get("/projects/#{project}/hooks", :query => options)
end

# Gets a project hook.
#
# @example
# Gitlab.project_hook(42, 5)
# Gitlab.project_hook('gitlab', 5)
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of a hook.
# @return [Gitlab::ObjectifiedHash]
def project_hook(project, id)
get("/projects/#{project}/hooks/#{id}")
end

# Adds a new hook to the project.
#
# @example
Expand All @@ -140,6 +153,19 @@ def add_project_hook(project, url)
post("/projects/#{project}/hooks", :body => {:url => url})
end

# Updates a project hook URL.
#
# @example
# Gitlab.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci')
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of the hook.
# @param [String] url The hook URL.
# @return [Gitlab::ObjectifiedHash] Information about updated hook.
def edit_project_hook(project, id, url)
put("/projects/#{project}/hooks/#{id}", :body => {:url => url})
end

# Deletes a hook from project.
#
# @example
Expand Down
31 changes: 31 additions & 0 deletions spec/gitlab/client/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@
end
end

describe ".project_hook" do
before do
stub_get("/projects/1/hooks/1", "project_hook")
@hook = Gitlab.project_hook(1, 1)
end

it "should get the correct resource" do
a_get("/projects/1/hooks/1").should have_been_made
end

it "should return information about a hook" do
@hook.url.should == "https://api.example.net/v1/webhooks/ci"
end
end

describe ".add_project_hook" do
before do
stub_post("/projects/1/hooks", "project_hook")
Expand All @@ -160,6 +175,22 @@
end
end

describe ".edit_project_hook" do
before do
stub_put("/projects/1/hooks/1", "project_hook")
@hook = Gitlab.edit_project_hook(1, 1, "https://api.example.net/v1/webhooks/ci")
end

it "should get the correct resource" do
body = {:url => "https://api.example.net/v1/webhooks/ci"}
a_put("/projects/1/hooks/1").with(:body => body).should have_been_made
end

it "should return information about an edited hook" do
@hook.url.should == "https://api.example.net/v1/webhooks/ci"
end
end

describe ".delete_project_hook" do
before do
stub_delete("/projects/1/hooks/1", "project_hook")
Expand Down

0 comments on commit 6c5637e

Please sign in to comment.