11

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
Cœur
  • 32,421
  • 21
  • 173
  • 232
Rafael K.
  • 1,779
  • 2
  • 14
  • 29

1 Answers1

12

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.

Rafael K.
  • 1,779
  • 2
  • 14
  • 29
  • 1
    I am not sure if this changed in meantime, today require 'jira-ruby' works for me. It's a newer gem, the rest of syntax from your answer is equal. – jing Feb 15 '17 at 14:17
  • Well, it's three years now, so I wouldn't be surprised, thanks for pointing it out. – Rafael K. Aug 07 '17 at 10:37