From ddb64c056109af050e18b88d8c4e335c720ec1e1 Mon Sep 17 00:00:00 2001 From: Ryan Margheriti Date: Mon, 28 Jul 2014 11:39:17 +1000 Subject: [PATCH] Added ability to pull all issues in a project --- README.md | 3 +- lib/jira.js | 227 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 140 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 8b5c1a14..e8f7c40e 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Find the status of an issue. console.log('Status: ' + issue.fields.status.name); }); -Currently there is no explicit login call necessary as each API call uses Basic Authentication to authenticate. +Currently there is no explicit login call necessary as each API call uses Basic Authentication to authenticate. ## Options ## @@ -61,6 +61,7 @@ JiraApi options: * List Components * List Fields * List Priorities + * Pulling all issues in project * Versions * Pulling versions * Adding a new version diff --git a/lib/jira.js b/lib/jira.js index ce90137c..a46672a6 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -65,6 +65,7 @@ // * Versions // * Pulling versions // * Adding a new version +// * Updating a version // * Pulling unresolved issues count for a specific version // * Rapid Views // * Find based on project name @@ -98,6 +99,7 @@ // ## Changelog ## // // +// * _0.10.0 Add Update Version (thanks to [floralvikings](https://github.com/floralvikings))_ // * _0.9.0 Add OAuth Support and New Estimates on addWorklog (thanks to // [nagyv](https://github.com/nagyv))_ // * _0.8.2 Fix URL Format Issues (thanks to @@ -237,6 +239,53 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + + // ## Get all issues in project ## + // ### Takes ### + // + // * project: key for the project + // * callback: for when it's done + // + // ### Returns ### + // + // * error: string of the error + // * project: the json object representing all issues in given project + // + // [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290709) + this.getProjectIssues = function(project, callback) { + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/search?jql=project="' + project + '"'), + 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 findIssueStatus.'); + return; + } + + if (body === undefined) { + callback('Response body was undefined.'); + } + + callback(null, JSON.parse(body)); + + }); + }; + // ## Get the unresolved issue count ## // ### Takes ### // @@ -1741,94 +1790,94 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }; // ## Retrieve the backlog of a certain Rapid View ## - // ### Takes ### - // * rapidViewId: rapid view id - // * callback: for when it's done - // - // ### Returns ### - // * error string - // * backlog object - /* - * Backlog item is in the format: - * { - * "sprintMarkersMigrated": true, - * "issues": [ - * { - * "id": 67890, - * "key": "KEY-1234", - * "summary": "Issue Summary", - * ... - * } - * ], - * "rankCustomFieldId": 12345, - * "sprints": [ - * { - * "id": 123, - * "name": "Sprint Name", - * "state": "FUTURE", - * ... - * } - * ], - * "supportsPages": true, - * "projects": [ - * { - * "id": 567, - * "key": "KEY", - * "name": "Project Name" - * } - * ], - * "epicData": { - * "epics": [ - * { - * "id": 9876, - * "key": "KEY-4554", - * "typeName": "Epic", - * ... - * } - * ], - * "canEditEpics": true, - * "supportsPages": true - * }, - * "canManageSprints": true, - * "maxIssuesExceeded": false, - * "queryResultLimit": 2147483647, - * "versionData": { - * "versionsPerProject": { - * "567": [ - * { - * "id": 8282, - * "name": "Version Name", - * ... - * } - * ] - * }, - * "canCreateVersion": true - * } - * } - */ - this.getBacklogForRapidView = function(rapidViewId, callback) { - var options = { - rejectUnauthorized: this.strictSSL, - uri: this.makeUri('/xboard/plan/backlog/data?rapidViewId=' + rapidViewId, 'rest/greenhopper/'), - method: 'GET', - json: true - }; - - this.doRequest(options, function(error, response) { - if (error) { - callback(error, null); - - return; - } - - if (response.statusCode === 200) { - callback(null, response.body); - - return; - } - - callback(response.statusCode + ': Error while retrieving backlog'); - }); - }; + // ### Takes ### + // * rapidViewId: rapid view id + // * callback: for when it's done + // + // ### Returns ### + // * error string + // * backlog object + /* + * Backlog item is in the format: + * { + * "sprintMarkersMigrated": true, + * "issues": [ + * { + * "id": 67890, + * "key": "KEY-1234", + * "summary": "Issue Summary", + * ... + * } + * ], + * "rankCustomFieldId": 12345, + * "sprints": [ + * { + * "id": 123, + * "name": "Sprint Name", + * "state": "FUTURE", + * ... + * } + * ], + * "supportsPages": true, + * "projects": [ + * { + * "id": 567, + * "key": "KEY", + * "name": "Project Name" + * } + * ], + * "epicData": { + * "epics": [ + * { + * "id": 9876, + * "key": "KEY-4554", + * "typeName": "Epic", + * ... + * } + * ], + * "canEditEpics": true, + * "supportsPages": true + * }, + * "canManageSprints": true, + * "maxIssuesExceeded": false, + * "queryResultLimit": 2147483647, + * "versionData": { + * "versionsPerProject": { + * "567": [ + * { + * "id": 8282, + * "name": "Version Name", + * ... + * } + * ] + * }, + * "canCreateVersion": true + * } + * } + */ + this.getBacklogForRapidView = function(rapidViewId, callback) { + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/xboard/plan/backlog/data?rapidViewId=' + rapidViewId, 'rest/greenhopper/'), + method: 'GET', + json: true + }; + + this.doRequest(options, function(error, response) { + if (error) { + callback(error, null); + + return; + } + + if (response.statusCode === 200) { + callback(null, response.body); + + return; + } + + callback(response.statusCode + ': Error while retrieving backlog'); + }); + }; }).call(JiraApi.prototype);