我正在尝试使用名为jira-ruby的gem从JIRA获取issuses。问题是,结果包含70个问题,但我只能看到前50个。当直接使用JIRA REST API时,我可以将maxResults参数(在JQL之外)设置为更高的数字。但我无法在红宝石中发现这种可能性。
有没有可能直接使用这个ruby gem或任何其他同样简单的解决方案设置maxResults标志?
代码如下:
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
好的,终于找到了问题所在。我使用的是0.1.10版本的gem(默认情况下由gem install命令下载的版本),这个版本(可能)有这个问题 - 至少它不支持jql方法中的maxResults参数。解决方案是通过将以下行添加到Gemfile来从git下载gem:
gem 'jira-ruby', :git => 'git://github.com/sumoheavy/jira-ruby.git'
然后我在代码中发现jql方法接受了一个可以指定此参数的哈希,所以现在代码如下,它正在工作:
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
我还必须将rails gem更新到版本4.1.4。