Skip to content

Commit 3a3ad56

Browse files
committed
Merge pull request #32 from eduardolundgren/master
Add search users - Fix #31
2 parents fab6ef3 + da10764 commit 3a3ad56

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

lib/jira.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,64 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
731731
});
732732
};
733733

734+
// ## Search user on Jira ##
735+
// ### Takes ###
736+
//
737+
// username: A query string used to search username, name or e-mail address
738+
// startAt: The index of the first user to return (0-based)
739+
// maxResults: The maximum number of users to return (defaults to 50).
740+
// includeActive: If true, then active users are included in the results (default true)
741+
// includeInactive: If true, then inactive users are included in the results (default false)
742+
// * callback: for when it's done
743+
//
744+
// ### Returns ###
745+
//
746+
// * error: string if there's an error
747+
// * users: array of users for the user
748+
//
749+
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e3756)
750+
//
751+
this.searchUsers = function(username, startAt, maxResults, includeActive, includeInactive, callback) {
752+
startAt = (startAt !== undefined) ? startAt : 0;
753+
maxResults = (maxResults !== undefined) ? maxResults : 50;
754+
includeActive = (includeActive !== undefined) ? includeActive : true;
755+
includeInactive = (includeInactive !== undefined) ? includeInactive : false;
756+
757+
var options = {
758+
rejectUnauthorized: this.strictSSL,
759+
uri: this.makeUri(
760+
'/user/search?username=' + username +
761+
'&startAt=' + startAt +
762+
'&maxResults=' + maxResults +
763+
'&includeActive=' + includeActive +
764+
'&includeInactive=' + includeInactive),
765+
method: 'GET',
766+
json: true,
767+
followAllRedirects: true
768+
};
769+
770+
this.request(options, function(error, response, body) {
771+
772+
if (error) {
773+
callback(error, null);
774+
return;
775+
}
776+
777+
if (response.statusCode === 400) {
778+
callback('Unable to search');
779+
return;
780+
}
781+
782+
if (response.statusCode !== 200) {
783+
callback(response.statusCode + ': Unable to connect to JIRA during search.');
784+
return;
785+
}
786+
787+
callback(null, body);
788+
789+
});
790+
};
791+
734792
// ## Get issues related to a user ##
735793
// ### Takes ###
736794
//

0 commit comments

Comments
 (0)