From 10c998b2a8eded49fe17b80f3ce350ce041f3a78 Mon Sep 17 00:00:00 2001 From: "yonatan.k" Date: Sun, 24 Dec 2017 17:32:15 +0200 Subject: [PATCH] adding the ability to fetch a filter by Id --- lib/jira.js | 35 +++++++++++++++++++++++++++++++++++ spec/jira.spec.coffee | 16 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/jira.js b/lib/jira.js index 190e2661..217df653 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -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 ### diff --git a/spec/jira.spec.coffee b/spec/jira.spec.coffee index 90638c1f..0c2c5198 100644 --- a/spec/jira.spec.coffee +++ b/spec/jira.spec.coffee @@ -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' \ No newline at end of file