Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jira-ruby gem limiting number of returned issues?

I'm trying to fetch issuses from JIRA using gem called jira-ruby. The problem is, that the result contains 70 issues, but I can see only the first 50. When using directly the JIRA REST API, I can set maxResults parameter (outside the JQL) to a higher number. But I can't find that possibility in the ruby gem.

Is there any possibility to set the maxResults flag directly using this ruby gem, or any other equally simple solution?

The code is the following:

require 'jira'

class PagesController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  def home

    options = {
        :username => 'xxx',
        :password => 'xxx',
        :site     => "https://xxx.atlassian.net",
        :context_path => '',
        :auth_type => :basic
    }

    client = JIRA::Client.new(options)
    @issues = 0
    client.Issue.jql("project = AA AND fixVersion = it11").each do |issue|
      @issues += 1 #  "#{@issues} <br> #{issue.id} - #{issue}"
    end

  end
end
like image 684
Rafael K. Avatar asked Aug 05 '14 09:08

Rafael K.


1 Answers

Ok, finally found where was the problem. I was using the 0.1.10 version of the gem (the one downloaded by default by gem install command) and this version (probably) had this problem - at least it did not support the maxResults parameter in the jql method for Issues. The solution was downloading the gem from git by adding the following line to the Gemfile:

gem 'jira-ruby', :git => 'git://github.com/sumoheavy/jira-ruby.git'

Then I found in the code that the jql method accepts a hash where this parameter can be specified, so now the code is the following and it's working:

require 'jira'

class PagesController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  def home

    p "processing..."
    options = {
        :username => 'xxx',
        :password => 'xxx',
        :site     => "https://xxx.atlassian.net",
        :context_path => '',
        :auth_type => :basic
    }

    client = JIRA::Client.new(options)


    query_options = {
        :fields => [],
        :start_at => 0,
        :max_results => 100000
    }

    @issues = ''

    client.Issue.jql('project = AA AND fixVersion = it11', query_options).each do |issue|
      @issues = "#{@issues} <br> #{issue}"
      #@issues.push(issue.id)
    end
    #@issues = @issues.length
  end
end

And I had to update the rails gem to version 4.1.4 also.

like image 59
Rafael K. Avatar answered Oct 17 '22 18:10

Rafael K.