Skip to content

Commit

Permalink
Merge branch 'master' into authorizations
Browse files Browse the repository at this point in the history
* master:
  docs
  added received_events api
  Version bump to 1.2.0
  test a hook
  create, edit and remove a hook
  add hook and hooks methods
  Version bump
  Add alias for conceal_membership
  • Loading branch information
catsby committed May 18, 2012
2 parents fae2966 + 8cfad62 commit 5139fd5
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CHANGELOG

* [1.2.0 - May 17, 2012](https://github.com/pengwynn/octokit/compare/v1.1.1...v1.2.0)
* [1.1.1 - May 15, 2012](https://github.com/pengwynn/octokit/compare/v1.1.0...v1.1.1)
* [1.1.0 - May 13, 2012](https://github.com/pengwynn/octokit/compare/v1.0.7...v1.1.0)
* [1.0.7 - May 11, 2012](https://github.com/pengwynn/octokit/compare/v1.0.6...v1.0.7)
* [1.0.6 - May 11, 2012](https://github.com/pengwynn/octokit/compare/v1.0.5...v1.0.6)
Expand Down
10 changes: 10 additions & 0 deletions lib/octokit/client/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def user_events(user, options={})
get("/users/#{user}/events", options, 3)
end

# List events that a user has received
#
# @return [Array] A list of all user received events
# @see http://developer.github.com/v3/received_events
# @example List all user received events
# Octokit.received_events("sferik")
def received_events(user, options={})
get("/users/#{user}/received_events", options, 3)
end

# List events for a repository
#
# @param repo [String, Repository, Hash] A GitHub repository
Expand Down
1 change: 1 addition & 0 deletions lib/octokit/client/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def publicize_membership(org, user, options={})
def unpublicize_membership(org, user, options={})
delete("orgs/#{org}/public_members/#{user}", options, 3, true, raw=true).status == 204
end
alias :conceal_membership :unpublicize_membership

end
end
Expand Down
26 changes: 26 additions & 0 deletions lib/octokit/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ def branches(repo, options={})
get "/repos/#{Repository.new repo}/branches", options, 3
end

def hooks(repo, options={})
get "/repos/#{Repository.new repo}/hooks", options, 3
end

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

def test_hook(repo, id, options={})
post "/repos/#{Repository.new repo}/hooks/#{id}/test", options, 3
end

# Get all Issue Events for a given Repository
#
# @param repo [String, Repository, Hash] A GitHub repository
Expand Down
2 changes: 1 addition & 1 deletion lib/octokit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Octokit
VERSION = "1.1.0".freeze unless defined?(Octokit::VERSION)
VERSION = "1.2.0".freeze unless defined?(Octokit::VERSION)
end
18 changes: 18 additions & 0 deletions spec/fixtures/v3/hook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"active": true,
"config": {
"railsbp_url": "http://railsbp.com",
"token": "xAAQZtJhYHGagsed1kYR"
},
"created_at": "2012-01-23T14:11:50Z",
"events": ["push"],
"id": 154284,
"last_response": {
"code": 200,
"message": "OK",
"status": "ok"
},
"name": "railsbp",
"updated_at": "2012-05-13T13:09:51Z",
"url": "https://api.github.com/repos/railsbp/railsbp.com/hooks/154284"
}
70 changes: 70 additions & 0 deletions spec/fixtures/v3/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[{
"active": true,
"config": {
"token": "f2a00b0bb2e270afcfeb6659d67c0561",
"user": "flyerhzm"
},
"created_at": "2011-11-28T05:00:58Z",
"events": ["push"],
"id": 121594,
"last_response": {
"code": 200,
"message": "OK",
"status": "ok"
},
"name": "gemnasium",
"updated_at": "2012-05-13T13:09:51Z",
"url": "https://api.github.com/repos/railsbp/railsbp.com/hooks/121594"
}, {
"active": true,
"config": {
"railsbp_url": "http://railsbp.com",
"token": "xAAQZtJhYHGagsed1kYR"
},
"created_at": "2012-01-23T14:11:50Z",
"events": ["push"],
"id": 154284,
"last_response": {
"code": 200,
"message": "OK",
"status": "ok"
},
"name": "railsbp",
"updated_at": "2012-05-13T13:09:51Z",
"url": "https://api.github.com/repos/railsbp/railsbp.com/hooks/154284"
}, {
"active": true,
"config": {
"token": "BCxleMW8q0IOCeuBABKAkpcRwMdH7TlNxb3f7R6Tjwk5E4gIDL0nW156xIcz",
"user": "flyerhzm"
},
"created_at": "2012-02-20T06:07:24Z",
"events": ["push"],
"id": 175702,
"last_response": {
"code": 200,
"message": "OK",
"status": "ok"
},
"name": "travis",
"updated_at": "2012-05-13T13:09:52Z",
"url": "https://api.github.com/repos/railsbp/railsbp.com/hooks/175702"
}, {
"active": true,
"config": {
"content_type": "form",
"insecure_ssl": "1",
"url": "http://rails-brakeman.com/"
},
"created_at": "2012-05-14T00:05:41Z",
"events": ["push"],
"id": 249928,
"last_response": {
"code": 200,
"message": "OK",
"status": "ok"
},
"name": "web",
"updated_at": "2012-05-14T00:05:47Z",
"url": "https://api.github.com/repos/railsbp/railsbp.com/hooks/249928"
}]
11 changes: 10 additions & 1 deletion spec/octokit/client/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public_events.first.id.should == '1513284759'
end
end

describe ".user_events" do
it "should return all user events" do
stub_get("/users/sferik/events").
Expand All @@ -24,6 +24,15 @@
end
end

describe ".received_events" do
it "should return all user received events" do
stub_get("/users/sferik/received_events").
to_return(:body => fixture("v3/user_events.json"))
received_events = @client.received_events('sferik')
received_events.first.type.should == 'PushEvent'
end
end

describe ".repository_events" do
it "should return events for a repository" do
stub_get("/repos/sferik/rails_admin/events").
Expand Down
68 changes: 68 additions & 0 deletions spec/octokit/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,74 @@

end

describe ".hooks" do

it "should return a repository's hooks" do
stub_get("/repos/railsbp/railsbp.com/hooks").
to_return(:body => fixture("v3/hooks.json"))
hooks = @client.hooks("railsbp/railsbp.com")
hook = hooks.find { |hook| hook.name == "railsbp" }
hook.config.token.should == "xAAQZtJhYHGagsed1kYR"
end

end

describe ".hook" 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)
hook.config.token.should == "xAAQZtJhYHGagsed1kYR"
end

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 ".test_hook" do

it "should test a hook" do
stub_post("/repos/railsbp/railsbp.com/hooks/154284/test").
to_return(:status => 204)
@client.test_hook("railsbp/railsbp.com", 154284).should be_nil
end

end

describe ".events" do

it "should list event for all issues in a repository" do
Expand Down

0 comments on commit 5139fd5

Please sign in to comment.