Skip to content

Commit bbae5ff

Browse files
author
Andrea Rossi
committed
assign method added, includes test
1 parent 1935cfb commit bbae5ff

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/jira.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,45 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
857857

858858
});
859859
};
860+
861+
// ## Assign issue in Jira ##
862+
// ### Takes ###
863+
//
864+
// * issueId: the Id of the issue to delete
865+
// * issueUpdate: username of the assignee
866+
// * callback: for when it's done
867+
//
868+
// ### Returns ###
869+
// * error string
870+
// * success string
871+
//
872+
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#idp1342720)
873+
this.assign = function(issueNum, assignee, callback) {
874+
var options = {
875+
rejectUnauthorized: this.strictSSL,
876+
uri: this.makeUri('/issue/' + issueNum + '/assignee'),
877+
json: {name: assignee},
878+
method: 'PUT',
879+
followAllRedirects: true
880+
};
881+
882+
this.request(options, function(error, response) {
883+
884+
if (error) {
885+
callback(error, null);
886+
return;
887+
}
888+
889+
if (response.statusCode === 204) {
890+
callback(null, "Success");
891+
return;
892+
}
893+
894+
callback(response.statusCode + ': Error while assigning');
895+
896+
});
897+
};
898+
860899
// ## List Transitions ##
861900
// ### Takes ###
862901
//

spec/jira.spec.coffee

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,24 @@ describe "Node Jira Tests", ->
364364
@jira.request.mostRecentCall.args[1] null, statusCode:200
365365
expect(@cb).toHaveBeenCalledWith null, 'Success'
366366

367+
it "Assigns an Issue", ->
368+
options =
369+
rejectUnauthorized: true
370+
uri: makeUrl "issue/1/assignee"
371+
json: {name: 'newAssignee'}
372+
method: 'PUT'
373+
followAllRedirects: true
374+
375+
@jira.assign 1, 'newAssignee', @cb
376+
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
377+
378+
@jira.request.mostRecentCall.args[1] null, statusCode:400
379+
expect(@cb).toHaveBeenCalledWith '400: Error while assigning'
380+
381+
# Successful Request
382+
@jira.request.mostRecentCall.args[1] null, statusCode:204
383+
expect(@cb).toHaveBeenCalledWith null, 'Success'
384+
367385
it "Lists Transitions", ->
368386
options =
369387
rejectUnauthorized: true

0 commit comments

Comments
 (0)