diff --git a/lib/jira.js b/lib/jira.js index e919d9da..c77f4549 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -159,7 +159,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor var apiVersion = this.apiVersion; if (altApiVersion != null) { - apiVersion = altApiVersion; + apiVersion = altApiVersion; } var uri = url.format({ @@ -173,17 +173,17 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor this.doRequest = function(options, callback) { if(oauth && oauth.consumer_key && oauth.consumer_secret) { - options.oauth = { - consumer_key: oauth.consumer_key, - consumer_secret: oauth.consumer_secret, - token: oauth.access_token, - token_secret: oauth.access_token_secret - }; + options.oauth = { + consumer_key: oauth.consumer_key, + consumer_secret: oauth.consumer_secret, + token: oauth.access_token, + token_secret: oauth.access_token_secret + }; } else { - options.auth = { - 'user': this.username, - 'pass': this.password - }; + options.auth = { + 'user': this.username, + 'pass': this.password + }; } this.request(options, callback); }; @@ -340,42 +340,85 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor this.findRapidView = function(projectName, callback) { var options = { - rejectUnauthorized: this.strictSSL, - uri: this.makeUri('/rapidviews/list', 'rest/greenhopper/'), - method: 'GET', - json: true + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/rapidviews/list', 'rest/greenhopper/'), + method: 'GET', + json: true }; this.doRequest(options, function(error, response) { - if (error) { - callback(error, null); - return; - } - - if (response.statusCode === 404) { - callback('Invalid URL'); - return; - } + if (error) { + callback(error, null); + return; + } - if (response.statusCode !== 200) { - callback(response.statusCode + ': Unable to connect to JIRA during rapidView search.'); - return; - } + if (response.statusCode === 404) { + callback('Invalid URL'); + return; + } - if (response.body !== null) { - var rapidViews = response.body.views; - for (var i = 0; i < rapidViews.length; i++) { - if(rapidViews[i].name.toLowerCase() === projectName.toLowerCase()) { - callback(null, rapidViews[i]); + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during rapidView search.'); return; - } } - } - }); + if (response.body !== null) { + var rapidViews = response.body.views; + for (var i = 0; i < rapidViews.length; i++) { + if(rapidViews[i].name.toLowerCase() === projectName.toLowerCase()) { + callback(null, rapidViews[i]); + return; + } + } + } + + }); }; + + + // ## Get an array containing every rapid board within JIRA ## + // ### Takes ### + // * callback: for when it's done + // + // ### Returns ### + // * error: string of the error + // * rapidViews: array with all the rapid boards + this.getRapidBoards = function(callback) { + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/rapidviews/list', 'rest/greenhopper/'), + method: 'GET', + json: true + }; + + this.doRequest(options, function (error, response) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 404) { + callback('Invalid URL'); + return; + } + + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during rapidView search.'); + return; + } + + if (response.body !== null) { + var rapidViews = response.body.views; + callback(null, rapidViews); + return; + } + }); + + }; // ## Get a list of Sprints belonging to a Rapid View ## // ### Takes ### // @@ -395,35 +438,35 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor this.getLastSprintForRapidView = function(rapidViewId, callback) { var options = { - rejectUnauthorized: this.strictSSL, - uri: this.makeUri('/sprintquery/' + rapidViewId, 'rest/greenhopper/'), - method: 'GET', - json:true + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/sprintquery/' + rapidViewId, 'rest/greenhopper/'), + method: 'GET', + json:true }; this.doRequest(options, function(error, response) { - if (error) { - callback(error, null); - return; - } - - if (response.statusCode === 404) { - callback('Invalid URL'); - return; - } + if (error) { + callback(error, null); + return; + } - if (response.statusCode !== 200) { - callback(response.statusCode + ': Unable to connect to JIRA during sprints search.'); - return; - } + if (response.statusCode === 404) { + callback('Invalid URL'); + return; + } - if (response.body !== null) { + if (response.statusCode !== 200) { + callback(response.statusCode + ': Unable to connect to JIRA during sprints search.'); + return; + } + if(response.body === null || response.body === undefined) { + callback("Response from Sprint Request ist either null or undefined"); + return; + } var sprints = response.body.sprints; callback(null, sprints.pop()); return; - } - }); }; @@ -447,37 +490,37 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor */ this.getSprintIssues = function getSprintIssues(rapidViewId, sprintId, callback) { - var options = { - rejectUnauthorized: this.strictSSL, - uri: this.makeUri('/rapid/charts/sprintreport?rapidViewId=' + rapidViewId + '&sprintId=' + sprintId, 'rest/greenhopper/'), - method: 'GET', - json: true - }; + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/rapid/charts/sprintreport?rapidViewId=' + rapidViewId + '&sprintId=' + sprintId, 'rest/greenhopper/'), + method: 'GET', + json: true + }; - this.doRequest(options, function(error, response) { + this.doRequest(options, function(error, response) { - if (error) { - callback(error, null); - return; - } + if (error) { + callback(error, null); + return; + } - if( response.statusCode === 404 ) { - callback('Invalid URL'); - return; - } + if( response.statusCode === 404 ) { + callback('Invalid URL'); + return; + } - if( response.statusCode !== 200 ) { - callback(response.statusCode + ': Unable to connect to JIRA during sprints search'); - return; - } + if( response.statusCode !== 200 ) { + callback(response.statusCode + ': Unable to connect to JIRA during sprints search'); + return; + } - if(response.body !== null) { - callback(null, response.body); - } else { - callback('No body'); - } + if(response.body !== null) { + callback(null, response.body); + } else { + callback('No body'); + } - }); + }); }; @@ -504,34 +547,34 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor this.addIssueToSprint = function(issueId, sprintId, callback) { var options = { - rejectUnauthorized: this.strictSSL, - uri: this.makeUri('/sprint/' + sprintId + '/issues/add', 'rest/greenhopper/'), - method: 'PUT', - followAllRedirects: true, - json:true, - body: { - issueKeys: [issueId] - } + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/sprint/' + sprintId + '/issues/add', 'rest/greenhopper/'), + method: 'PUT', + followAllRedirects: true, + json:true, + body: { + issueKeys: [issueId] + } }; logger.log(options.uri); this.doRequest(options, function(error, response) { - if (error) { - callback(error, null); - return; - } + if (error) { + callback(error, null); + return; + } - if (response.statusCode === 404) { - callback('Invalid URL'); - return; - } + if (response.statusCode === 404) { + callback('Invalid URL'); + return; + } - if (response.statusCode !== 204) { - callback(response.statusCode + ': Unable to connect to JIRA to add to sprint.'); - return; - } + if (response.statusCode !== 204) { + callback(response.statusCode + ': Unable to connect to JIRA to add to sprint.'); + return; + } }); }; @@ -1453,7 +1496,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor rejectUnauthorized: this.strictSSL, uri: this.makeUri('/issue/' + issueId + '/comment'), body: { - "body": comment + "body": comment }, method: 'POST', followAllRedirects: true, @@ -1475,7 +1518,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'); }); };