Permalink
Browse files

Implemented create_issue and update_issue

  • Loading branch information...
1 parent e3327d2 commit a1c6a418e9ebf8cb5a16f1663e3758ee981b37c1 @choonkeat choonkeat committed with Dec 4, 2013
Showing with 134 additions and 58 deletions.
  1. +26 −0 lib/octonode/issue.js
  2. +21 −19 lib/octonode/me.js
  3. +37 −18 lib/octonode/repo.js
  4. +14 −0 src/octonode/issue.coffee
  5. +11 −10 src/octonode/me.coffee
  6. +25 −11 src/octonode/repo.coffee
View
@@ -9,6 +9,32 @@
this.client = client;
}
+ Issue.prototype.info = function(cb) {
+ return this.client.get("/repos/" + this.repo + "/issues/" + this.number, function(err, s, b) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 200) {
+ return cb(new Error("Issue info error"));
+ } else {
+ return cb(null, b);
+ }
+ });
+ };
+
+ Issue.prototype.update = function(obj, cb) {
+ return this.client.post("/repos/" + this.repo + "/issues/" + this.number, obj, function(err, s, b) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 200) {
+ return cb(new Error("Issue update error"));
+ } else {
+ return cb(null, b);
+ }
+ });
+ };
+
Issue.prototype.comments = function(cb) {
return this.client.get("/repos/" + this.repo + "/issues/" + this.number + "/comments", function(err, s, b) {
if (err) {
View
@@ -1,6 +1,7 @@
// Generated by CoffeeScript 1.6.3
(function() {
- var Me;
+ var Me,
+ __slice = [].slice;
Me = (function() {
function Me(client) {
@@ -287,28 +288,29 @@
});
};
- Me.prototype.repo = function(name) {
- return this.client.repo(name);
- };
-
- Me.prototype.repos = function(cbOrRepo, cb) {
- if (typeof cb === 'function' && typeof cbOrRepo === 'object') {
- return this.createRepo(cbOrRepo, cb);
+ Me.prototype.repo = function(name, cb) {
+ if (typeof cb === 'function' && typeof nameOrRepo === 'object') {
+ return this.createRepo(nameOrRepo, cb);
} else {
- cb = cbOrRepo;
- return this.client.get("/user/repos", function(err, s, b) {
- if (err) {
- return cb(err);
- }
- if (s !== 200) {
- return cb(new Error('User repos error'));
- } else {
- return cb(null, b);
- }
- });
+ return this.client.repo(name);
}
};
+ Me.prototype.repos = function() {
+ var cb, params, _i, _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, ["/user/repos"].concat(__slice.call(params), [function(err, s, b) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 200) {
+ return cb(new Error('User repos error'));
+ } else {
+ return cb(null, b);
+ }
+ }]));
+ };
+
Me.prototype.createRepo = function(repo, cb) {
return this.client.post("/user/repos", repo, function(err, s, b) {
if (err) {
View
@@ -144,6 +144,14 @@
});
};
+ Repo.prototype.issue = function(numberOrIssue, cb) {
+ if (typeof cb === 'function' && typeof numberOrIssue === 'object') {
+ return this.createIssue(numberOrIssue, cb);
+ } else {
+ return this.client.issue(this.name, numberOrIssue);
+ }
+ };
+
Repo.prototype.issues = function() {
var cb, params, _i, _ref;
params = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++];
@@ -159,6 +167,16 @@
}]));
};
+ Repo.prototype.createIssue = function(issue, cb) {
+ return this.client.post("/repos/" + this.name + "/issues", issue, function(err, s, b) {
+ if (s !== 201) {
+ return cb(new Error("Repo createIssue error"));
+ } else {
+ return cb(null, b);
+ }
+ });
+ };
+
Repo.prototype.readme = function(cbOrRef, cb) {
if ((cb == null) && cbOrRef) {
cb = cbOrRef;
@@ -269,28 +287,29 @@
});
};
- Repo.prototype.pr = function(number) {
- return this.client.pr(this.name, number);
- };
-
- Repo.prototype.prs = function(cbOrPr, cb) {
- if (typeof cb === 'function' && typeof cbOrPr === 'object') {
- return this.createPr(cbOrPr, cb);
+ Repo.prototype.pr = function(numberOrPr, cb) {
+ if (typeof cb === 'function' && typeof numberOrPr === 'object') {
+ return this.createPr(numberOrPr, cb);
} else {
- cb = cbOrPr;
- return this.client.get("/repos/" + this.name + "/pulls", function(err, s, b) {
- if (err) {
- return cb(err);
- }
- if (s !== 200) {
- return cb(new Error("Repo prs error"));
- } else {
- return cb(null, b);
- }
- });
+ return this.client.pr(this.name, numberOrPr);
}
};
+ Repo.prototype.prs = function() {
+ var cb, params, _i, _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, ["/repos/" + this.name + "/pulls"].concat(__slice.call(params), [function(err, s, b) {
+ if (err) {
+ return cb(err);
+ }
+ if (s !== 200) {
+ return cb(new Error("Repo prs error"));
+ } else {
+ return cb(null, b);
+ }
+ }]));
+ };
+
Repo.prototype.createPr = function(pr, cb) {
return this.client.post("/repos/" + this.name + "/pulls", pr, function(err, s, b) {
if (err) {
@@ -9,6 +9,20 @@ class Issue
constructor: (@repo, @number, @client) ->
+ # Get a single issue
+ # '/repos/pksunkara/hub/issues/37' GET
+ info: (cb) ->
+ @client.get "/repos/#{@repo}/issues/#{@number}", (err, s, b) ->
+ return cb(err) if err
+ if s isnt 200 then cb(new Error("Issue info error")) else cb null, b
+
+ # Edit an issue for a repository
+ # '/repos/pksunkara/hub/issues/37' PATCH
+ update: (obj, cb) ->
+ @client.post "/repos/#{@repo}/issues/#{@number}", obj, (err, s, b) ->
+ return cb(err) if err
+ if s isnt 200 then cb(new Error("Issue update error")) else cb null, b
+
# List comments on an issue
# '/repos/pksunkara/hub/issues/37/comments' GET
comments: (cb) ->
@@ -187,19 +187,20 @@ class Me
if s isnt 200 then cb(new Error('User orgs error')) else cb null, b
# Get repository instance for client
- repo: (name) ->
- @client.repo name
+ repo: (name, cb) ->
+ if typeof cb is 'function' and typeof nameOrRepo is 'object'
+ @createRepo nameOrRepo, cb
+ else
+ @client.repo name
# List your repositories
# '/user/repos' GET
- repos: (cbOrRepo, cb) ->
- if typeof cb is 'function' and typeof cbOrRepo is 'object'
- @createRepo cbOrRepo, cb
- else
- cb = cbOrRepo
- @client.get "/user/repos", (err, s, b) ->
- return cb(err) if err
- if s isnt 200 then cb(new Error('User repos error')) else cb null, b
+ # - page or query object, optional - params[0]
+ # - per_page, optional - params[1]
+ repos: (params..., cb) ->
+ @client.get "/user/repos", params..., (err, s, b) ->
+ return cb(err) if err
+ if s isnt 200 then cb(new Error('User repos error')) else cb null, b
# Create a repository
# '/user/repos' POST
@@ -85,7 +85,14 @@ class Repo
return cb(err) if err
if s isnt 200 then cb(new Error("Repo branches error")) else cb null, b
- # Get the issues for a repository
+ # Get issue instance for a repo
+ issue: (numberOrIssue, cb) ->
+ if typeof cb is 'function' and typeof numberOrIssue is 'object'
+ @createIssue numberOrIssue, cb
+ else
+ @client.issue @name, numberOrIssue
+
+ # List issues for a repository
# '/repos/pksunkara/hub/issues' GET
# - page or query object, optional - params[0]
# - per_page, optional - params[1]
@@ -94,6 +101,12 @@ class Repo
return cb(err) if err
if s isnt 200 then cb(new Error("Repo issues error")) else cb null, b, headers
+ # Create an issue for a repository
+ # '/repos/pksunkara/hub/issues' POST
+ createIssue: (issue, cb) ->
+ @client.post "/repos/#{@name}/issues", issue, (err, s, b) ->
+ if s isnt 201 then cb(new Error("Repo createIssue error")) else cb null, b
+
# Get the README for a repository
# '/repos/pksunkara/hub/readme' GET
readme: (cbOrRef, cb) ->
@@ -160,19 +173,20 @@ class Repo
@destroy() if err? or s isnt 204
# Get pull-request instance for repo
- pr: (number) ->
- @client.pr @name, number
+ pr: (numberOrPr, cb) ->
+ if typeof cb is 'function' and typeof numberOrPr is 'object'
+ @createPr numberOrPr, cb
+ else
+ @client.pr @name, numberOrPr
# List pull requests
# '/repos/pksunkara/hub/pulls' GET
- prs: (cbOrPr, cb) ->
- if typeof cb is 'function' and typeof cbOrPr is 'object'
- @createPr cbOrPr, cb
- else
- cb = cbOrPr
- @client.get "/repos/#{@name}/pulls", (err, s, b) ->
- return cb(err) if (err)
- if s isnt 200 then cb(new Error("Repo prs error")) else cb null, b
+ # - page or query object, optional - params[0]
+ # - per_page, optional - params[1]
+ prs: (params..., cb) ->
+ @client.get "/repos/#{@name}/pulls", params..., (err, s, b) ->
+ return cb(err) if (err)
+ if s isnt 200 then cb(new Error("Repo prs error")) else cb null, b
# Create a pull request
# '/repos/pksunkara/hub/pulls' POST

0 comments on commit a1c6a41

Please sign in to comment.