Skip to content

Commit a8e537d

Browse files
StevenMcDSteven McDonald
authored andcommitted
New Feature, Added the addComment functionality
1 parent a74933e commit a8e537d

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

lib/jira.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,46 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
10191019

10201020
});
10211021
};
1022+
// ## Add a comment to an issue ##
1023+
// ### Takes ###
1024+
// * issueId: Issue to add a comment to
1025+
// * comment: string containing comment
1026+
// * callback: for when it's done
1027+
//
1028+
// ### Returns ###
1029+
// * error string
1030+
// * success string
1031+
//
1032+
// [Jira Doc](https://docs.atlassian.com/jira/REST/latest/#id108798)
1033+
this.addComment = function(issueId, comment, callback){
1034+
var options = {
1035+
rejectUnauthorized: this.strictSSL,
1036+
uri: this.makeUri('/issue/' + issueId + '/comment'),
1037+
body: {
1038+
"body": comment
1039+
},
1040+
method: 'POST',
1041+
followAllRedirects: true,
1042+
json: true
1043+
};
1044+
1045+
this.request(options, function(error, response, body) {
1046+
if (error) {
1047+
callback(error, null);
1048+
return;
1049+
};
1050+
1051+
if (response.statusCode === 201) {
1052+
callback(null, "Success");
1053+
return;
1054+
};
1055+
1056+
if (response.statusCode === 400) {
1057+
callback("Invalid Fields: " + JSON.stringify(body));
1058+
return;
1059+
};
1060+
});
1061+
};
10221062
// ## Add a worklog to a project ##
10231063
// ### Takes ###
10241064
// * issueId: Issue to add a worklog to

spec/jira.spec.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,28 @@ describe "Node Jira Tests", ->
424424
@jira.request.mostRecentCall.args[1] null, statusCode:200, "body"
425425
expect(@cb).toHaveBeenCalledWith null, "body"
426426

427+
it "Adds a comment to an issue", ->
428+
options =
429+
rejectUnauthorized: true
430+
uri: makeUrl "issue/1/comment"
431+
body: {
432+
'body': 'aComment'
433+
}
434+
method: 'POST'
435+
followAllRedirects: true
436+
json: true
437+
438+
@jira.addComment 1, 'aComment', @cb
439+
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
440+
441+
@jira.request.mostRecentCall.args[1] null, statusCode:400,
442+
'{"body:"none"}'
443+
expect(@cb).toHaveBeenCalledWith 'Invalid Fields: "{\\"body:\\"none\\"}"'
444+
445+
# Successful Request
446+
@jira.request.mostRecentCall.args[1] null, statusCode:201
447+
expect(@cb).toHaveBeenCalledWith null, "Success"
448+
427449
it "Adds a worklog to a project", ->
428450
options =
429451
rejectUnauthorized: true

0 commit comments

Comments
 (0)