Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add hooks endpoints for Repo #79

Merged
merged 1 commit into from

2 participants

Jacob Gable Pavan Kumar Sunkara
Jacob Gable
  • Add hooks for listing hooks
  • Add createHook for creating a hook
Jacob Gable

Wasn't sure whether to include the built js file or not. Let me know if you don't want that to happen in the future.

Here is how I tested this:

var octo = require('./lib/octonode');

var token = require('./github-token');

var client = octo.client(token);

var repo = client.repo('jgable/octonode');

repo.hooks(function (err, body, headers) {
    if (err) { throw err; }

    console.log('hooks', body);
    console.log('headers', headers);
});

/*
repo.hook({
        name: 'web',
        active: true,
        events: [
            'push',
            'pull_request',
            'issues'
        ],
        config: {
            url: 'http://requestb.in/v3ifpkv3',
            content_type: 'json'
        }
    }, function (err, body, headers) {
        if (err) { throw err; }

        console.log('hooks', body);
        console.log('headers', headers);
    });
*/

You can view the response over at the response bin I had set up.

I created a personal token to test with and just stored it in github-token.js.

src/octonode/repo.coffee
@@ -202,6 +202,24 @@ class Repo
return cb(err) if err
if s isnt 201 then cb(new Error("Repo createPr error")) else cb null, b, h
+ # List hooks
+ # '/repos/pksunkara/hub/hooks' GET
+ hooks: (cb) ->
+ @client.get "/repos/#{@name}/hooks", (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
+ # - name - params[0]
+ # - config hash; key/value settings for this hook - params[1]
+ # - events array of strings, optional - params[2]
+ # - active, optional - params[3]
Pavan Kumar Sunkara Owner

They are not taken as args by the below function. So, could you remove the above 4 lines?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Pavan Kumar Sunkara
Owner

Check comment on diff.

You need to compile coffeescript using cake lib and also include it in the commit.

Thanks

Jacob Gable jgable Add hooks endpoints for Repo
- Add hooks for listing hooks
- Add createHook for creating a hook
- Add description to README
0c3c203
Jacob Gable

Updated

Removed argument comment, rebuilt with cake lib and added description of the functions in the README.

Pavan Kumar Sunkara pksunkara merged commit b1fdb8f into from
Jacob Gable jgable deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 15, 2013
  1. Jacob Gable

    Add hooks endpoints for Repo

    jgable authored
    - Add hooks for listing hooks
    - Add createHook for creating a hook
    - Add description to README
This page is out of date. Refresh to see the latest.
Showing with 61 additions and 0 deletions.
  1. +21 −0 README.md
  2. +26 −0 lib/octonode/repo.js
  3. +14 −0 src/octonode/repo.coffee
21 README.md
View
@@ -500,6 +500,27 @@ ghrepo.pr({
}, callback); //pull request
```
+#### Get the hooks for a repository (GET /repos/pksunkara/hub/hooks)
+
+This query supports [pagination](#pagination).
+
+```js
+ghrepo.hooks(callback); //array of hooks
+```
+
+#### Create a hook (POST /repos/pksunkara/hub/hooks)
+
+```js
+ghrepo.hook({
+ "name": "web",
+ "active": true,
+ "events": ["push", "pull_request"],
+ "config": {
+ "url": "http://myawesomesite.com/github/events"
+ }
+}, callback); // hook
+```
+
#### Get the README for a repository (GET /repos/pksunkara/hub/readme)
```js
26 lib/octonode/repo.js
View
@@ -340,6 +340,32 @@
});
};
+ Repo.prototype.hooks = function(cb) {
+ return this.client.get("/repos/" + this.name + "/hooks", function(err, s, b, h) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 200) {
+ return cb(new Error("Repo hooks error"));
+ } 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) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 201) {
+ return cb(new Error("Repo createHook error"));
+ } else {
+ return cb(null, b, h);
+ }
+ });
+ };
+
Repo.prototype.statuses = function(ref, cb) {
return this.client.get("/repos/" + this.name + "/statuses/" + ref, function(err, s, b, h) {
if (err) {
14 src/octonode/repo.coffee
View
@@ -202,6 +202,20 @@ class Repo
return cb(err) if err
if s isnt 201 then cb(new Error("Repo createPr error")) else cb null, b, h
+ # List hooks
+ # '/repos/pksunkara/hub/hooks' GET
+ hooks: (cb) ->
+ @client.get "/repos/#{@name}/hooks", (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) ->
+ return cb(err) if err
+ if s isnt 201 then cb(new Error("Repo createHook error")) else cb null, b, h
+
# List statuses for a specific ref
# '/repos/pksunkara/hub/statuses/master' GET
statuses: (ref, cb) ->
Something went wrong with that request. Please try again.