Skip to content

Commit ba54db7

Browse files
author
Keith Morris
committed
Implement addWatcher method to add a watcher to an issue
Add supporting unit test Update README.md list of what is implemented
1 parent efc81d4 commit ba54db7

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ JiraApi options:
107107
* Issues
108108
* Add a new issue
109109
* Update an issue
110+
* Add watcher to an issue
110111
* Transition an issue
111112
* Pulling an issue
112113
* Issue linking

lib/jira.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,53 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
10291029
});
10301030
};
10311031

1032+
// ## Add a user as a watcher on an issue ##
1033+
// ### Takes ###
1034+
//
1035+
// * issueKey: the key of the existing issue
1036+
// * username: the jira username to add as a watcher to the issue
1037+
// * callback: for when it's done
1038+
//
1039+
// ### Returns ###
1040+
//
1041+
// * error: string of the error
1042+
//
1043+
//
1044+
// Empty callback on success
1045+
/**
1046+
* Adds a given user as a watcher to the given issue
1047+
*
1048+
* @param issueKey
1049+
* @param username
1050+
* @param callback
1051+
*/
1052+
this.addWatcher = function (issueKey, username, callback) {
1053+
1054+
var options = {
1055+
rejectUnauthorized: this.strictSSL,
1056+
uri: this.makeUri('/issue/' + issueKey + '/watchers'),
1057+
method: 'POST',
1058+
followAllRedirects: true,
1059+
json: true,
1060+
body: JSON.stringify(username)
1061+
};
1062+
1063+
this.doRequest(options, function (error, response) {
1064+
if (error) {
1065+
return callback(error, null);
1066+
}
1067+
1068+
if (response.statusCode === 404) {
1069+
return callback('Invalid URL');
1070+
}
1071+
1072+
if (response.statusCode !== 204) {
1073+
return callback(response.statusCode + ': Unable to connect to JIRA to add user as watcher.');
1074+
}
1075+
callback();
1076+
});
1077+
};
1078+
10321079
// ## Delete issue to Jira ##
10331080
// ### Takes ###
10341081
//

spec/jira.spec.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,28 @@ describe "Node Jira Tests", ->
538538
@jira.request.mostRecentCall.args[1] null, statusCode:201
539539
expect(@cb).toHaveBeenCalledWith null, "Success"
540540

541+
it "Adds a watcher to an issue", ->
542+
options =
543+
rejectUnauthorized: true
544+
uri: makeUrl "issue/1/watchers"
545+
body: JSON.stringify "testuser"
546+
method: 'POST'
547+
followAllRedirects: true
548+
json: true
549+
auth:
550+
user: 'test'
551+
pass: 'test'
552+
553+
@jira.addWatcher 1, "testuser", @cb
554+
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
555+
556+
@jira.request.mostRecentCall.args[1] null, statusCode: 400
557+
expect(@cb).toHaveBeenCalledWith '400: Unable to connect to JIRA to add user as watcher.'
558+
559+
# Successful Request
560+
@jira.request.mostRecentCall.args[1] null, statusCode: 204
561+
expect(@cb).toHaveBeenCalledWith
562+
541563
it "Adds a worklog to a project", ->
542564
options =
543565
rejectUnauthorized: true

0 commit comments

Comments
 (0)