diff --git a/README.md b/README.md index 37e910d..6a44619 100644 --- a/README.md +++ b/README.md @@ -881,6 +881,33 @@ ghorg.createTeam({ }, callback); ``` +#### Get the hooks for a Organization (GET /orgs/flatiron/hooks) + +This query supports [pagination](#pagination). + +```js +ghorg.hooks(callback); //array of hooks +``` + +#### Create a hook (POST /orgs/flatiron/hooks) + +```js +ghorg.hook({ + "name": "web", + "active": true, + "events": ["push", "pull_request"], + "config": { + "url": "http://myawesomesite.com/github/events" + } +}, callback); // hook +``` + +#### Delete a hook (DELETE /orgs/flatiron/hooks/37) + +```js +ghorg.deleteHook(37, callback); +``` + ## Github issues api #### Get a single issue (GET /repos/pksunkara/hub/issues/37) diff --git a/lib/octonode/org.js b/lib/octonode/org.js index 3e8c382..d63eedf 100644 --- a/lib/octonode/org.js +++ b/lib/octonode/org.js @@ -228,6 +228,47 @@ }); }; + Org.prototype.hooks = function() { + var cb, i, params, ref; + params = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), cb = arguments[i++]; + return (ref = this.client).get.apply(ref, ["/orgs/" + this.name + "/hooks"].concat(slice.call(params), [function(err, s, b, h) { + if (err) { + return cb(err); + } + if (s !== 200) { + return cb(new Error("Org hooks error")); + } else { + return cb(null, b, h); + } + }])); + }; + + Org.prototype.hook = function(hook, cb) { + return this.client.post("/orgs/" + this.name + "/hooks", hook, function(err, s, b, h) { + if (err) { + return cb(err); + } + if (s !== 201) { + return cb(new Error("Org createHook error")); + } else { + return cb(null, b, h); + } + }); + }; + + Org.prototype.deleteHook = function(id, cb) { + return this.client.del("/orgs/" + this.name + "/hooks/" + id, {}, function(err, s, b, h) { + if (err) { + return cb(err); + } + if (s !== 204) { + return cb(new Error("Org deleteHook error")); + } else { + return cb(null, b, h); + } + }); + }; + return Org; })(); diff --git a/lib/octonode/repo.js b/lib/octonode/repo.js index e74a164..297001b 100644 --- a/lib/octonode/repo.js +++ b/lib/octonode/repo.js @@ -745,8 +745,10 @@ }); }; - Repo.prototype.hooks = function(cb) { - return this.client.get("/repos/" + this.name + "/hooks", function(err, s, b, h) { + Repo.prototype.hooks = function() { + var cb, i, params, ref1; + params = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), cb = arguments[i++]; + return (ref1 = this.client).get.apply(ref1, ["/repos/" + this.name + "/hooks"].concat(slice.call(params), [function(err, s, b, h) { if (err) { return cb(err); } @@ -755,11 +757,11 @@ } else { return cb(null, b, h); } - }); + }])); }; - Repo.prototype.hook = function(hookInfo, cb) { - return this.client.post("/repos/" + this.name + "/hooks", hookInfo, function(err, s, b, h) { + Repo.prototype.hook = function(hook, cb) { + return this.client.post("/repos/" + this.name + "/hooks", hook, function(err, s, b, h) { if (err) { return cb(err); } diff --git a/src/octonode/org.coffee b/src/octonode/org.coffee index 03d8676..cb15af2 100644 --- a/src/octonode/org.coffee +++ b/src/octonode/org.coffee @@ -139,5 +139,26 @@ class Org return cb(err) if err if s isnt 204 then cb(new Error('Org addTeamRepo error')) else cb null, b, h + # List hooks + # '/orgs/flatiron/hub/hooks' GET + hooks: (params..., cb) -> + @client.get "/orgs/#{@name}/hooks", params..., (err, s, b, h) -> + return cb(err) if (err) + if s isnt 200 then cb(new Error("Org hooks error")) else cb null, b, h + + # Create a hook + # '/orgs/flatiron/hub/hooks' POST + hook: (hook, cb) -> + @client.post "/orgs/#{@name}/hooks", hook, (err, s, b, h) -> + return cb(err) if err + if s isnt 201 then cb(new Error("Org createHook error")) else cb null, b, h + + # Delete a hook + # '/orgs/flatiron/hub/hooks/37' DELETE + deleteHook: (id, cb) -> + @client.del "/orgs/#{@name}/hooks/#{id}", {}, (err, s, b, h) -> + return cb(err) if err + if s isnt 204 then cb(new Error("Org deleteHook error")) else cb null, b, h + # Export module module.exports = Org diff --git a/src/octonode/repo.coffee b/src/octonode/repo.coffee index d201c19..e574116 100644 --- a/src/octonode/repo.coffee +++ b/src/octonode/repo.coffee @@ -432,15 +432,15 @@ class Repo # List hooks # '/repos/pksunkara/hub/hooks' GET - hooks: (cb) -> - @client.get "/repos/#{@name}/hooks", (err, s, b, h) -> + hooks: (params..., cb) -> + @client.get "/repos/#{@name}/hooks",params..., (err, s, b, h) -> return cb(err) if (err) if s isnt 200 then cb(new Error("Repo hooks error")) else cb null, b, h # Create a hook # '/repos/pksunkara/hub/hooks' POST - hook: (hookInfo, cb) -> - @client.post "/repos/#{@name}/hooks", hookInfo, (err, s, b, h) -> + hook: (hook, cb) -> + @client.post "/repos/#{@name}/hooks", hook, (err, s, b, h) -> return cb(err) if err if s isnt 201 then cb(new Error("Repo createHook error")) else cb null, b, h