diff --git a/lib/jira.js b/lib/jira.js index e919d9da..0c85b90a 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,102 @@ 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; + } + + if (body === undefined) { + callback('Response body was undefined.'); + return; + } + + callback(null, JSON.parse(body)); + + }); + }; + + // ## 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; } @@ -232,7 +327,57 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor callback('Response body was undefined.'); return; } + callback(null, JSON.parse(body)); + }); + } + + // ## 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; + } callback(null, JSON.parse(body)); }); @@ -878,7 +1023,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 } }; @@ -1475,7 +1621,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'); }); }; 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": [ 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') -