Skip to content

Commit

Permalink
#485: Accuracy rule not using search limit
Browse files Browse the repository at this point in the history
Fixed #485
  • Loading branch information
dgroup committed Sep 13, 2021
1 parent a9f838e commit 2d2938c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/lazylead/opts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def to_h
def jira_defaults
{
max_results: fetch("max_results", 50),
fields: jira_fields
fields: jira_fields,
limit: to_h["limit"]
}
end

Expand Down
26 changes: 23 additions & 3 deletions lib/lazylead/system/jira.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def issues(jql, opts = { max_results: 50, fields: nil, expand: nil })
total = jira.Issue.jql(jql, max_results: 0)
@log.debug "Found #{total} ticket(s) in '#{jql}'"
loop do
tickets.concat(jira.Issue.jql(jql, opts.merge(start_at: start))
tickets.concat(jira.Issue.jql(jql, range(start, opts))
.map { |i| Lazylead::Issue.new(i, jira) })
@log.debug "Fetched #{tickets.size}"
start += opts.find(:max_results, 50)
break if (start > total) || (start >= opts.find(:limit, total))
start += opts.find(:max_results, 50).to_i
break if (start > total) || (start >= opts.find(:limit, total).to_i)
end
tickets
end
Expand All @@ -83,6 +83,26 @@ def raw

private

# Detect tickets range in remote search result.
#
# In jira you may navigate through the search result using following parameters:
# https://docs.atlassian.com/jira-software/REST/7.3.1/#agile/1.0/epic-getIssuesForEpic
# :start_at
# The starting index of the returned issues. Base index: 0. See the 'Pagination' section at
# the top of this page for more details.
# :max_results
# The maximum number of issues to return per page. Default: 50. See the 'Pagination' section
# at the top of this page for more details. Note, the total number of issues returned is
# limited by the property 'jira.search.views.default.max' in your JIRA instance. If you
# exceed this limit, your results will be truncated.
def range(start, opts)
limit = opts.find(:limit, 0).to_i
max_results = opts.find(:max_results, 50).to_i
opts[:start_at] = start
opts[:max_results] = [limit, max_results].min if limit.positive?
opts
end

def client
return @client if defined? @client
@opts[:auth_type] = :basic if @opts[:auth_type].nil?
Expand Down
1 change: 1 addition & 0 deletions lib/lazylead/task/accuracy/accuracy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def run(sys, postman, opts)
.each(&:evaluate)
.each(&:post)
postman.send(opts) unless opts[:tickets].empty?
opts
end

# Initialize accuracy rules and configuration for tickets verification.
Expand Down
23 changes: 23 additions & 0 deletions test/lazylead/task/accuracy/accuracy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,28 @@ class AccuracyTest < Lazylead::Test
assert_kind_of Lazylead::Task::Accuracy,
ORM::Task.find(195).action.constantize.new
end

test "one ticket found" do
Lazylead::Smtp.new.enable
assert_equal 1,
Task::Accuracy.new.run(
NoAuthJira.new("https://jira.spring.io"),
Postman.new,
Opts.new(
"from" => "ll@fake.com",
"to" => "lead@fake.com",
"rules" => "Lazylead::AffectedBuild",
"silent" => "true",
"colors" => {
"0" => "#FF4F33",
"57" => "#19DD1E"
}.to_json.to_s,
"jql" => "key > DATAJDBC-490",
"limit" => "1",
"subject" => "[LL] Raised tickets",
"template" => "lib/messages/accuracy.erb"
)
)[:tickets].size
end
end
end

0 comments on commit 2d2938c

Please sign in to comment.