Skip to content

Commit

Permalink
#357: Detect reporter by first change in history in case of automatic…
Browse files Browse the repository at this point in the history
…/system user

Fixed #357
  • Loading branch information
dgroup committed Apr 10, 2021
1 parent 47b3093 commit b688872
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/lazylead/task/accuracy/accuracy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run(sys, postman, opts)
Requires.new(__dir__).load
opts[:rules] = opts.construct("rules")
opts[:total] = opts[:rules].sum(&:score)
opts[:tickets] = sys.issues(opts["jql"], opts.jira_defaults)
opts[:tickets] = sys.issues(opts["jql"], opts.jira_defaults.merge(expand: "changelog"))
.map { |i| Score.new(i, opts) }
.each(&:evaluate)
.each(&:post)
Expand Down Expand Up @@ -83,7 +83,7 @@ def post
# The jira comment in markdown format
def comment
comment = [
"Hi [~#{@issue.reporter.id}],",
"Hi [~#{reporter}],",
"",
"The triage accuracy is '{color:#{color}}#{@score}{color}'" \
" (~{color:#{color}}#{@accuracy}%{color}), here are the reasons why:",
Expand Down Expand Up @@ -133,5 +133,17 @@ def colors
def grade(value)
(value / 10).floor * 10
end

# Detect the ticket reporter.
#
# If ticket created by some automatic/admin user account then reporter is the first non-system
# user account who modified the ticket.
def reporter
return @issue.reporter.id unless @opts.key? "system-users"
sys = @opts.slice("system-users", ",")
return @issue.reporter.id if sys.empty? || sys.none? { |susr| @issue.reporter.id.eql? susr }
@issue.history
.find { |h| sys.none? { |susr| susr.eql? h["author"]["key"] } }["author"]["key"]
end
end
end
11 changes: 11 additions & 0 deletions test/lazylead/task/accuracy/score_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# OR OTHER DEALINGS IN THE SOFTWARE.

require_relative "../../../test"
require_relative "../../../../lib/lazylead/system/jira"
require_relative "../../../../lib/lazylead/task/accuracy/accuracy"
require_relative "../../../../lib/lazylead/task/accuracy/affected_build"

Expand Down Expand Up @@ -69,5 +70,15 @@ def fields
)
).evaluate.comment
end

test "detect non-system reporter" do
assert_equal "grussell",
Score.new(
NoAuthJira.new("https://jira.spring.io")
.issues("key=INT-4116", expand: "changelog")
.first,
Opts.new("system-users" => "abilan")
).reporter
end
end
end

0 comments on commit b688872

Please sign in to comment.