Skip to content

Commit

Permalink
#281: onlyll rule violators doesn't consider already existing LL labels
Browse files Browse the repository at this point in the history
Fixed #281
  • Loading branch information
dgroup committed Jan 11, 2021
1 parent 454ff7c commit 2eee4a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/lazylead/task/accuracy/onlyll.rb
Expand Up @@ -121,31 +121,25 @@ def violators
# Ensure that history record has label change related to LL grid labels.
# @return true if LL grid labels added
def grid?(record)
diff(record).any? do |h|
from = []
from = h.first.split(" ") unless h.first.nil?
to = h.last.split(" ")
(to - from).find { |l| grid.any? { |g| l.eql? g } }
end
diff(record).any? { |d| d.find { |l| grid.any? { |g| l.eql? g } } }
end

# Detect label diff in single history record from ticket's history.
def diff(record)
record["items"].select { |f| f["field"].eql? "labels" }
.reject { |f| f["toString"].nil? || f["toString"].blank? }
.map do |f|
[f["fromString"], f["toString"]]
from = []
from = f["fromString"].split(" ") unless f["fromString"].nil?
f["toString"].split(" ") - from
end
end

# Hacked score by violator in ticket's history.
def hacked(record)
record.flat_map { |h| h["items"] }
.select { |h| h["field"].eql? "labels" }
.map { |h| h["toString"] }
.join(" ")
.split(" ")
.find { |l| grid.any? { |g| l.eql? g } }
diff(record.first)
.first
.find { |l| grid.any? { |g| l.eql? g } }
end
end
end
12 changes: 12 additions & 0 deletions test/lazylead/task/accuracy/onlyll_test.rb
Expand Up @@ -122,5 +122,17 @@ def history
Opts.new("grid" => "10%,20%,30%,40%", "author" => "ll")
).violators.first
end

test "violators should consider already existing LL grid labels" do
assert_equal "Aron set 40%",
Labels.new(
Struct.new(:key) do
def history
[{ "author" => { "name" => "ap", "key" => "ap", "displayName" => "Aron" }, "items" => [{ "field" => "labels", "fromString" => "0%", "toString" => "0% abc 40%" }] }]
end
end.new("XD-3725"),
Opts.new("grid" => "10%,20%,30%,40%", "author" => "ll")
).violators.first
end
end
end

0 comments on commit 2eee4a7

Please sign in to comment.