-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class Gitlab::Client | ||
# Defines methods related to system hooks. | ||
module SystemHook | ||
# Gets a list of system hooks. | ||
# | ||
# @example | ||
# Gitlab.hooks | ||
# Gitlab.system_hooks | ||
# | ||
# @return [Array<Gitlab::ObjectifiedHash>] | ||
def hooks | ||
get("/hooks") | ||
end | ||
alias_method :system_hooks, :hooks | ||
|
||
# Adds a new system hook. | ||
# | ||
# @example | ||
# Gitlab.add_hook('http://example.com/hook') | ||
# Gitlab.add_system_hook('https://api.example.net/v1/hook') | ||
# | ||
# @param [String] url The hook URL. | ||
# @return [Gitlab::ObjectifiedHash] | ||
def add_hook(url) | ||
post("/hooks", :body => {:url => url}) | ||
end | ||
alias_method :add_system_hook, :add_hook | ||
|
||
# Tests a system hook. | ||
# | ||
# @example | ||
# Gitlab.hook(3) | ||
# Gitlab.system_hook(12) | ||
# | ||
# @param [Integer] id The ID of a system hook. | ||
# @return [Array<Gitlab::ObjectifiedHash>] | ||
def hook(id) | ||
get("/hooks/#{id}") | ||
end | ||
alias_method :system_hook, :hook | ||
|
||
# Deletes a new system hook. | ||
# | ||
# @example | ||
# Gitlab.delete_hook(3) | ||
# Gitlab.delete_system_hook(12) | ||
# | ||
# @param [Integer] id The ID of a system hook. | ||
# @return [Gitlab::ObjectifiedHash] | ||
def delete_hook(id) | ||
delete("/hooks/#{id}") | ||
end | ||
alias_method :delete_system_hook, :delete_hook | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"id": 3, "url": "http://example.com/hook", "created_at": "2013-10-02T10:15:31Z"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "event_name": "project_create", "name": "Ruby", "path": "ruby", "project_id": 1, "owner_name": "Someone", "owner_email": "example@gitlabhq.com" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"id": 3, "url": "http://example.com/hook", "created_at": "2013-10-02T10:15:31Z"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'spec_helper' | ||
|
||
describe Gitlab::Client do | ||
it { should respond_to :system_hooks } | ||
it { should respond_to :add_system_hook } | ||
it { should respond_to :system_hook } | ||
it { should respond_to :delete_system_hook } | ||
|
||
describe ".hooks" do | ||
before do | ||
stub_get("/hooks", "system_hooks") | ||
@hooks = Gitlab.hooks | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_get("/hooks").should have_been_made | ||
end | ||
|
||
it "should return an array of system hooks" do | ||
@hooks.should be_an Array | ||
@hooks.first.url.should == "http://example.com/hook" | ||
end | ||
end | ||
|
||
describe ".add_hook" do | ||
before do | ||
stub_post("/hooks", "system_hook") | ||
@hook = Gitlab.add_hook("http://example.com/hook") | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_post("/hooks").should have_been_made | ||
end | ||
|
||
it "should return information about a added system hook" do | ||
@hook.url.should == "http://example.com/hook" | ||
end | ||
end | ||
|
||
describe ".hook" do | ||
before do | ||
stub_get("/hooks/3", "system_hook_test") | ||
@hook = Gitlab.hook(3) | ||
end | ||
it "should get the correct resource" do | ||
a_get("/hooks/3").should have_been_made | ||
end | ||
|
||
it "should return information about a added system hook" do | ||
@hook.event_name.should == "project_create" | ||
@hook.project_id.should == 1 | ||
end | ||
end | ||
|
||
describe ".delete_hook" do | ||
before do | ||
stub_delete("/hooks/3", "system_hook") | ||
@hook = Gitlab.delete_hook(3) | ||
end | ||
|
||
it "should get the correct resource" do | ||
a_delete("/hooks/3").should have_been_made | ||
end | ||
|
||
it "should return information about a deleted system hook" do | ||
@hook.url.should == "http://example.com/hook" | ||
end | ||
end | ||
end |