From 17d6ab40465548273a391967f853644747d18cdf Mon Sep 17 00:00:00 2001 From: Randal Maia Date: Fri, 7 Aug 2015 00:30:11 -0300 Subject: [PATCH 1/5] Function to comment issue --- github.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/github.js b/github.js index 6f8dc215..7d96ebf3 100644 --- a/github.js +++ b/github.js @@ -832,6 +832,14 @@ } _requestAllPages(path + '?' + query.join("&"), cb); }; + + this.comment = function(issue, comment, cb) { + _request("POST", issue.comments_url, comment, function(err,res) { + cb(err,res); + }); + }; + + }; // Top Level API From 7bebf3add6cef4e7740a4ad5546408f1a86c03f5 Mon Sep 17 00:00:00 2001 From: Randal Maia Date: Fri, 7 Aug 2015 00:30:29 -0300 Subject: [PATCH 2/5] Tests List issues --- test/test.issue.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test.issue.js b/test/test.issue.js index e69de29b..10e98310 100644 --- a/test/test.issue.js +++ b/test/test.issue.js @@ -0,0 +1,23 @@ +'use strict'; + +var test = require('tape'); //jshint ignore:line +var Github = require("../"); +var test_user = require('./user.json'); + +test("Issues API", function(t) { + var github = new Github({ + username: test_user.USERNAME, + password: test_user.PASSWORD, + auth: "basic" + }); + + var issues = github.getIssues('mikedeboertest', 'TestRepo'); + + t.test('issues.list', function(q) { + issues.list({},function(err, issues) { + t.error(err); + t.equals(issues.length > 0, true, 'Issues not found'); + t.end(); + }); + }); +}); \ No newline at end of file From f3391975b73a921dae5052761fd255a0ec0fcf71 Mon Sep 17 00:00:00 2001 From: Randal Maia Date: Fri, 7 Aug 2015 01:03:55 -0300 Subject: [PATCH 3/5] Fix comment issue function --- github.js | 2 +- test/test.issue.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/github.js b/github.js index 7d96ebf3..ec253d65 100644 --- a/github.js +++ b/github.js @@ -834,7 +834,7 @@ }; this.comment = function(issue, comment, cb) { - _request("POST", issue.comments_url, comment, function(err,res) { + _request("POST", issue.comments_url, {body:comment}, function(err,res) { cb(err,res); }); }; diff --git a/test/test.issue.js b/test/test.issue.js index 10e98310..6a14cb54 100644 --- a/test/test.issue.js +++ b/test/test.issue.js @@ -20,4 +20,16 @@ test("Issues API", function(t) { t.end(); }); }); + + t.test('issues.comment', function(q) { + var issueToComment; + issues.list({},function(err, issues) { + issueToComment = issues[0] + }); + + issues.comment(issueToComment, 'Comment test', function(err,res){ + t.error(err); + console.log(res); + }); + }); }); \ No newline at end of file From 76e40e62644af1c8627bb2882e0dd3bd1dd7caeb Mon Sep 17 00:00:00 2001 From: Randal Maia Date: Fri, 7 Aug 2015 01:04:12 -0300 Subject: [PATCH 4/5] Test issue comment function --- test/test.issue.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/test.issue.js b/test/test.issue.js index 6a14cb54..e28ccb81 100644 --- a/test/test.issue.js +++ b/test/test.issue.js @@ -15,21 +15,22 @@ test("Issues API", function(t) { t.test('issues.list', function(q) { issues.list({},function(err, issues) { - t.error(err); - t.equals(issues.length > 0, true, 'Issues not found'); - t.end(); + q.error(err); + t.equals(issues.length > 0, true, 'Issues!'); + q.end(); }); + t.end(); }); t.test('issues.comment', function(q) { - var issueToComment; - issues.list({},function(err, issues) { - issueToComment = issues[0] - }); - - issues.comment(issueToComment, 'Comment test', function(err,res){ - t.error(err); - console.log(res); + issues.list({},function(err, issuesList) { + issues.comment(issuesList[0], 'Comment test', function(err, res){ + q.error(err); + t.equals(res.body, 'Comment test', 'Comments!'); + q.end(); + }); }); }); + + }); \ No newline at end of file From 8bd2229df1798a44514d24dfe9c7288b5616f00e Mon Sep 17 00:00:00 2001 From: Randal Maia Date: Fri, 7 Aug 2015 01:07:33 -0300 Subject: [PATCH 5/5] Doc new function --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 84d870dc..49b96332 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,12 @@ To read all the issues of a given repository issues.list(options, function(err, issues) {}); ``` +To comment in a issue + +```js +issues.comment(issue, comment,function(err, comment) {}); +``` + ##Setup Github.js has the following dependency: