Skip to content

adding the ability to fetch a filter by Id #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,41 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
});
};

/**
* Retrieves the filter object by id.
*
* @param filterId - The filter id as it appears in Jira
* @param callback
*/
this.getFilter = function getFilter(filterId, callback) {
var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/filter/' + filterId),
method: 'GET',
json: true
};

this.doRequest(options, function(error, response) {

if (error) {
callback(error, null);
return;
}

if (response.statusCode === 404 || response.statusCode === 400) {
callback('Cannot find the requested filter');
return;
}

if (response.statusCode !== 200) {
callback(response.statusCode + ': Unable to connect to JIRA during request.');
return;
}

callback(null, response.body);
});
};


// ## Get Versions for a project ##
// ### Takes ###
Expand Down
16 changes: 16 additions & 0 deletions spec/jira.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,19 @@ describe "Node Jira Tests", ->
expect(@cb).toHaveBeenCalledWith(
'Cannot create remote link. test')

it "Get Filter by Id", ->
options =
rejectUnauthorized: true
uri: makeUrl "filter/1"
method: 'GET'
json: true
auth:
user: 'test'
pass: 'test'

@jira.getFilter 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)

# Invalid Filter
@jira.request.mostRecentCall.args[1] null, statusCode:404, null
expect(@cb).toHaveBeenCalledWith 'Cannot find the requested filter'