 
     request.get options, (error, response, body) ->
       try
-        console.log "API returned:", body
-        deferred.resolve transformResponse(body)
+        console.log "_get got", url, body
+        deferred.resolve body
       catch error
         deferred.reject error
 
     return deferred.promise
 
+  invokeTillHasNext: (url, transformFunction) ->
+    deferred = q.defer()
+    location= "#{url}?pagelen=#{PAGE_SIZE}"
+
+    #First invocation to know how many items we have
+    @_get(location).then (body) =>
+      firstPage = transformFunction(body)
+      if !body.next
+        deferred.resolve firstPage
+      else
+        pages = Math.ceil(body.size / PAGE_SIZE)
+        promises = []
+        promises.push(@_get(location + "&page=#{i}")) for i in [2 .. pages]
+
+        q.all(promises).then (resultBodies) ->
+          results = resultBodies.map (x) -> transformFunction(x)
+          toMerge = firstPage.concat(results)
+          deferred.resolve [].concat.apply([], toMerge)
+
+      return deferred.promise
+
+  # /maprtech/mapr.com-content/pullrequests
+  getPullRequests: (repoOwner, repoName) ->
+    deferred = q.defer()
+    url = "#{API_URL}#{repoOwner}/#{repoName}/pullrequests"
+
+    @invokeTillHasNext(url, transformResponse).then (result) ->
+      deferred.resolve result
+
+    return deferred.promise
+    
   createPullRequest: (title, description, repoOwner, repoName, fromBranch, toBranch) ->
     deferred = q.defer()
     url = "#{API_URL}#{repoOwner}/#{repoName}/pullrequests"


request = require 'request'
q = require 'q'

transformResponse = (body) ->
  if !body


  getBranches: (repoOwner, repoName) ->
    deferred = q.defer()
    url = "#{API_URL}#{repoOwner}/#{repoName}/refs/branches"

    @invokeTillHasNext(url, transformBranchResponse).then (result) ->
      deferred.resolve result

    return deferred.promise

