Permalink
Browse files

add possibility to get all sprints

  • Loading branch information...
1 parent 028b24f commit 1dc624f8d502809a53370c8931cfa9120cbd9242 @Woellchen committed Feb 4, 2014
Showing with 98 additions and 55 deletions.
  1. +75 −50 lib/jira.js
  2. +23 −5 spec/jira.spec.coffee
View
125 lib/jira.js
@@ -350,56 +350,81 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
});
};
- // ## Get a list of Sprints belonging to a Rapid View ##
- // ### Takes ###
- //
- // * rapidViewId: the id for the rapid view
- // * callback: for when it's done
- //
- // ### Returns ###
- //
- // * error: string with the error
- // * sprints: the ?array? of sprints
- /**
- * Returns a list of sprints belonging to a Rapid View.
- *
- * @param rapidView ID
- * @param callback
- */
- this.getLastSprintForRapidView = function(rapidViewId, callback) {
-
- var options = {
- rejectUnauthorized: this.strictSSL,
- uri: this.makeUri('/sprints/' + rapidViewId, 'rest/greenhopper/'),
- method: 'GET',
- json:true
- };
-
- this.request(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 sprints search.');
- return;
- }
-
- if (response.body !== null) {
- var sprints = response.body.sprints;
- callback(null, sprints.pop());
- return;
- }
-
- });
- };
+ // ## Get a list of Sprints belonging to a Rapid View ##
+ // ### Takes ###
+ //
+ // * rapidViewId: the id for the rapid view
+ // * callback: for when it's done
+ //
+ // ### Returns ###
+ //
+ // * error: string with the error
+ // * sprints: the ?array? of sprints
+ /**
+ * Returns a list of sprints belonging to a Rapid View.
+ *
+ * @param rapidView ID
+ * @param callback
+ */
+ this.getAllSprintsForRapidView = function(rapidViewId, callback) {
+
+ var options = {
+ rejectUnauthorized: this.strictSSL,
+ uri: this.makeUri('/sprintquery/' + rapidViewId, 'rest/greenhopper/'),
+ method: 'GET',
+ json: true
+ };
+
+ this.request(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 sprints search.');
+ return;
+ }
+
+ if (response.body !== null) {
+ callback(null, response.body.sprints);
+ }
+
+ });
+ };
+
+ // ## Get the latest sprint belonging to a Rapid View ##
+ // ### Takes ###
+ //
+ // * rapidViewId: the id for the rapid view
+ // * callback: for when it's done
+ //
+ // ### Returns ###
+ //
+ // * error: string with the error
+ // * sprint: the sprint
+ /**
+ * Returns the latest sprint belonging to a Rapid View.
+ *
+ * @param rapidView ID
+ * @param callback
+ */
+ this.getLastSprintForRapidView = function(rapidViewId, callback) {
+ this.getAllSprintsForRapidView(rapidViewId, function(error, response) {
+ if (error) {
+ callback(error);
+ return;
+ }
+
+ callback(null, response.pop());
+ });
+ };
// ## Get the issues for a rapidView / sprint##
// ### Takes ###
View
28 spec/jira.spec.coffee
@@ -127,14 +127,14 @@ describe "Node Jira Tests", ->
expect(@cb).toHaveBeenCalledWith null, name: 'ABC'
- it "Gets the last sprint for a Rapid View", ->
+ it "Gets a list of sprints for a Rapid View", ->
options =
rejectUnauthorized: true
- uri: makeUrl("sprints/1", true)
+ uri: makeUrl("sprintquery/1", true)
method: 'GET'
json: true
- @jira.getLastSprintForRapidView 1, @cb
+ @jira.getAllSprintsForRapidView 1, @cb
expect(@jira.request).toHaveBeenCalledWith options, jasmine.any(Function)
# Invalid URL
@@ -149,9 +149,27 @@ describe "Node Jira Tests", ->
@jira.request.mostRecentCall.args[1] null,
statusCode:200,
body:
- sprints: [name: 'ABC']
+ sprints: [name: 'ABC', name: 'DEF']
- expect(@cb).toHaveBeenCalledWith null, name: 'ABC'
+ expect(@cb).toHaveBeenCalledWith null, [name: 'ABC', name: 'DEF']
+
+ it "Gets the last sprint for a Rapid View", ->
+ options =
+ rejectUnauthorized: true
+ uri: makeUrl("sprintquery/1", true)
+ method: 'GET'
+ json: true
+
+ spyOn @jira, 'getAllSprintsForRapidView'
+
+ @jira.getLastSprintForRapidView 1, @cb
+ expect(@jira.getAllSprintsForRapidView).toHaveBeenCalledWith(1, jasmine.any(Function))
+
+ # Successful Request
+ @jira.getAllSprintsForRapidView.mostRecentCall.args[1] null,
+ [name: 'ABC', name: 'DEF']
+
+ expect(@cb).toHaveBeenCalledWith null, name: 'DEF'
it "Adds an issue to a sprint", ->
options =

0 comments on commit 1dc624f

Please sign in to comment.