From af0c184be31f47712bc56fe845ed5ff4229e4847 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 24 Oct 2014 15:12:32 -0400 Subject: [PATCH 1/5] Allow 'expand' in search requests --- lib/jira.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jira.js b/lib/jira.js index e919d9da..c2201827 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -878,7 +878,8 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor jql: searchString, startAt: optional.startAt || 0, maxResults: optional.maxResults || 50, - fields: optional.fields || ["summary", "status", "assignee", "description"] + fields: optional.fields || ["summary", "status", "assignee", "description"], + expand: optional.expand } }; From 10c05c6665b3257c3cb006617a084abee17802bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=ADmur=20J=C3=B3nsson?= Date: Wed, 14 Jan 2015 13:31:51 +0000 Subject: [PATCH 2/5] Adding expand renderedFields to findIssue. Implemented createMeta function --- lib/jira.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/jira.js b/lib/jira.js index e919d9da..7db1f87f 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -207,7 +207,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor var options = { rejectUnauthorized: this.strictSSL, - uri: this.makeUri('/issue/' + issueNumber), + uri: this.makeUri('/issue/' + issueNumber + '?expand=renderedFields'), method: 'GET' }; @@ -224,7 +224,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor } if (response.statusCode !== 200) { - callback(response.statusCode + ': Unable to connect to JIRA during findIssueStatus.'); + callback(response.statusCode + ': Unable to connect to JIRA during findIssue.'); return; } @@ -238,6 +238,59 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + // ## Get Meta data for creating an issue ## + // ### Takes ### + // + // * projectKey: the key for the desired project + // * callback: for when it's done + // + // ### Returns ### + // + // * error: string of the error + // * meta: an object of the meta data for creating issues. + // + // [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e4547) + this.createMeta = function(projectKey, callback) { + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri( + '/issue/createmeta' + + '?projectKeys=' + projectKey + + '&expand=projects.issuetypes.fields'), + method: 'GET' + // Node, the API support filtering by projectIds, issuetypeIds, issuetypeNames + // I'm only using the projectKeys filter (and only ONE projectKey) + }; + + this.doRequest(options, function(error, response, body) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 404) { + callback('Invalid issue number.'); + return; + } + + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during createMeta.'); + return; + } + + if (body === undefined) { + callback('Response body was undefined.'); + return; + } + jsonbody = JSON.parse(body); + jsonbody['uri'] = options.uri; + callback(null, jsonbody); + + }); + }; + // ## Get the unresolved issue count ## // ### Takes ### // From 83a954f8fc2040426602d4b36315f6731e533f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=ADmur=20J=C3=B3nsson?= Date: Fri, 16 Jan 2015 14:38:14 +0000 Subject: [PATCH 3/5] Adding getCommentPropertyKeys and getCommentPropertyValue --- lib/jira.js | 100 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 4 deletions(-) diff --git a/lib/jira.js b/lib/jira.js index 7db1f87f..3deb2398 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -238,6 +238,100 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + // ## Find the keys of all properties for the comment ## + // ### Takes ### + // + // * commentId: the comment from which keys will be returned. + // * callback: for when it's done + // + // ### Returns ### + // + // * error: string of the error + // * issue: an object of the issue + // + // [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e5287) + this.getCommentPropertyKeys = function(commentId, callback) { + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri( + '/comment/' + commentId + '/properties'), + method: 'GET' + }; + + this.doRequest(options, function(error, response, body) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 404) { + callback('Invalid issue number.'); + return; + } + + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during getCommentPropertyKeys.'); + return; + } + + if (body === undefined) { + callback('Response body was undefined.'); + return; + } + callback(null, JSON.parse(body)); + + }); + } + + // ## Finds the value of the property with a given + // key from the comment identified by the key or by the id ## + // ### Takes ### + // + // * commentId: the comment from which keys will be returned. + // * propertyKey: the key of the property. + // * callback: for when it's done + // + // ### Returns ### + // + // * error: string of the error + // * issue: an object of the issue + // + // [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e5317) + this.getCommentPropertyValue = function(commentId, propertyKey, callback) { + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri( + '/comment/' + commentId + '/properties/' + propertyKey), + method: 'GET' + }; + + this.doRequest(options, function(error, response, body) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 404) { + callback('Invalid issue number.'); + return; + } + + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during getCommentPropertyValue.'); + return; + } + + if (body === undefined) { + callback('Response body was undefined.'); + return; + } + callback(null, JSON.parse(body)); + + }); + } + // ## Get Meta data for creating an issue ## // ### Takes ### // @@ -284,9 +378,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor callback('Response body was undefined.'); return; } - jsonbody = JSON.parse(body); - jsonbody['uri'] = options.uri; - callback(null, jsonbody); + callback(null, JSON.parse(body)); }); }; @@ -1528,7 +1620,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor callback("Invalid Fields: " + JSON.stringify(body)); return; }; - + callback(response.statusCode + ': Error while adding comment'); }); }; From 8ad757ba5e29a58c2684fa7d5f14a75f2497402b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=ADmur=20J=C3=B3nsson?= Date: Fri, 16 Jan 2015 14:59:04 +0000 Subject: [PATCH 4/5] Updating tests --- spec/jira.spec.coffee | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/spec/jira.spec.coffee b/spec/jira.spec.coffee index 716d0c9d..b292ebc6 100644 --- a/spec/jira.spec.coffee +++ b/spec/jira.spec.coffee @@ -34,8 +34,8 @@ describe "Node Jira Tests", -> .toHaveBeenCalledWith(options, jasmine.any(Function)) it "Sets OAuth oauth for the requests if oauth is passed in", -> - options = - oauth = + options = + oauth = consumer_key: 'ck' consumer_secret: 'cs' access_token: 'ac' @@ -65,7 +65,7 @@ describe "Node Jira Tests", -> it "Finds an issue", -> options = rejectUnauthorized: true - uri: makeUrl "issue/1" + uri: makeUrl "issue/1?expand=renderedFields" method: 'GET' auth: user: 'test' @@ -81,7 +81,7 @@ describe "Node Jira Tests", -> # Unable to find issue @jira.request.mostRecentCall.args[1] null, statusCode:401, null expect(@cb).toHaveBeenCalledWith( - '401: Unable to connect to JIRA during findIssueStatus.') + '401: Unable to connect to JIRA during findIssue.') # Successful Request @jira.request.mostRecentCall.args[1] null, @@ -109,7 +109,7 @@ describe "Node Jira Tests", -> @jira.request.mostRecentCall.args[1] null, statusCode:401, null expect(@cb).toHaveBeenCalledWith( '401: Unable to connect to JIRA during findIssueStatus.') - + # Successful Request @jira.request.mostRecentCall.args[1] null, statusCode:200, '{"issuesUnresolvedCount":1}' @@ -151,7 +151,7 @@ describe "Node Jira Tests", -> expect(@jira.request) .toHaveBeenCalledWith options, jasmine.any(Function) - # Invalid URL + # Invalid URL @jira.request.mostRecentCall.args[1] null, statusCode:404, null expect(@cb).toHaveBeenCalledWith 'Invalid URL' @@ -180,7 +180,7 @@ describe "Node Jira Tests", -> @jira.getLastSprintForRapidView 1, @cb expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function) - # Invalid URL + # Invalid URL @jira.request.mostRecentCall.args[1] null, statusCode:404, null expect(@cb).toHaveBeenCalledWith 'Invalid URL' @@ -195,7 +195,7 @@ describe "Node Jira Tests", -> sprints: [name: 'ABC'] expect(@cb).toHaveBeenCalledWith null, name: 'ABC' - + it "Adds an issue to a sprint", -> options = rejectUnauthorized: true @@ -212,7 +212,7 @@ describe "Node Jira Tests", -> @jira.addIssueToSprint 2, 1, @cb expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function) - # Invalid URL + # Invalid URL @jira.request.mostRecentCall.args[1] null, statusCode:404, null expect(@cb).toHaveBeenCalledWith 'Invalid URL' @@ -363,7 +363,7 @@ describe "Node Jira Tests", -> spyOn @jira, 'searchJira' expected = "assignee = test AND status in (Open, \"In Progress\", Reopened)" - + @jira.getUsersIssues 'test', true, @cb expect(@jira.searchJira).toHaveBeenCalledWith expected, {}, jasmine.any(Function) @@ -396,7 +396,7 @@ describe "Node Jira Tests", -> it "Gets ALL a specified User's Issues", -> spyOn @jira, 'searchJira' expected = "assignee = test" - + @jira.getUsersIssues 'test', false, @cb expect(@jira.searchJira).toHaveBeenCalledWith expected, {}, jasmine.any(Function) @@ -689,4 +689,3 @@ describe "Node Jira Tests", -> @jira.request.mostRecentCall.args[1] null, response expect(@cb).toHaveBeenCalledWith( 'Cannot create remote link. test') - From d2cdcb44e30e3a470061972f168efa1e887c4574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=ADmur=20J=C3=B3nsson?= Date: Tue, 20 Jan 2015 15:38:30 +0000 Subject: [PATCH 5/5] new version number --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7e56d2b2..e73162f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "jira", - "version": "0.9.2", + "name": "jira-greenqloud", + "version": "0.9.3", "description": "Wrapper for the JIRA API", "author": "Steven Surowiec ", "contributors": [