Skip to content

Commit

Permalink
Merge pull request #4 from ilbonzo/develop
Browse files Browse the repository at this point in the history
added set estimate for issue method
  • Loading branch information
ilbonzo authored Aug 30, 2017
2 parents e2674f3 + 26af45c commit ba4111a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
45 changes: 43 additions & 2 deletions lib/zenhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = ZenHub;
* @param object parameters additional parameters
* @callback complete
* @memberof ZenHub
* @method get
* @method _get
*/
ZenHub.prototype._get = function(url, parameters, callback) {
parameters = extend(parameters, this.credentials); // Add credentials to parameters
Expand All @@ -52,7 +52,7 @@ ZenHub.prototype._get = function(url, parameters, callback) {
* @param object body request body
* @callback complete
* @memberof ZenHub
* @method get
* @method _post
*/
ZenHub.prototype._post = function(url, parameters, body, callback) {
parameters = extend(parameters, this.credentials); // Add credentials to parameters
Expand All @@ -68,6 +68,31 @@ ZenHub.prototype._post = function(url, parameters, body, callback) {
});
};

/**
* Helper to handle PUT requests to the API with authorization
*
* @private
* @param string url address part after API root
* @param object parameters additional parameters
* @param object body request body
* @callback complete
* @memberof ZenHub
* @method _put
*/
ZenHub.prototype._put = function(url, parameters, body, callback) {
parameters = extend(parameters, this.credentials); // Add credentials to parameters
var putURL = API_URL + '/' + url + '?' + querystring.stringify(parameters); // Construct URL with parameters

request.put({
url: putURL,
strictSSL: true,
json: true,
body: body,
}, function(error, response, body) {
callback(error, body || {});
});
};

/**
* Show All Pipelines in a repo board
* This method returns all pipelines in a repo board
Expand Down Expand Up @@ -172,3 +197,19 @@ ZenHub.prototype.convertIssueToEpic = function (repoId, issueId, payload, callba
callback(error, body);
});
};

/**
* Set estimate in issue
* This method set estimate for an issue on ZenHub.
* @param int repoId github id of repository
* @param int issueId github id of issue to convert
* @param object payload contains estimate to set for the issue, see https://github.com/ZenHubIO/API#set-estimate-for-issue for payload format
* @callback complete
* @memberof ZenHub
* @method setEstimateForIssue
*/
ZenHub.prototype.setEstimateForIssue = function (repoId, issueId, payload, callback) {
this._put('repositories/' + repoId + '/issues/' + issueId + '/estimate', {}, payload, function (error, body) {
callback(error, body);
});
};
15 changes: 15 additions & 0 deletions test/zenhubWriteTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ describe('ZenHub Write API', function() {
api.convertIssueToEpic(repoId, issueId, payload, done);
});
});

describe('Set estimate for issue test', function() {
var issueId = 457;

it('should send payload to the ZenHub API', function(done) {
var payload = {
estimate: 8
};
nock('https://api.zenhub.io/p1')
.put('/repositories/' + repoId + '/issues/' + issueId + '/estimate' + tokenQueryString, payload)
.reply(200, { status: 'OK' });
api.setEstimateForIssue(repoId, issueId, payload, done);
});
});

});

0 comments on commit ba4111a

Please sign in to comment.