Skip to content

Commit

Permalink
#390: due date changes for particular period
Browse files Browse the repository at this point in the history
Fixed #390
  • Loading branch information
dgroup committed May 4, 2021
1 parent 28890bc commit aa9aa62
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
30 changes: 27 additions & 3 deletions lib/lazylead/task/micromanager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,39 @@ def initialize(log = Log.new)
def run(sys, postman, opts)
allowed = opts.slice "allowed", ","
dues = sys.issues(opts["jql"], opts.jira_defaults.merge(expand: "changelog"))
.map { |i| Due.new(i, allowed) }
.map { |i| Due.new(i, allowed, since(opts)) }
.select(&:illegal?)
.reject(&:obsolete?)
return if dues.empty?
postman.send opts.merge(dues: dues)
end

# Detect history period where search should start.
#
# opts["period"] The default period for past is 1 day (86400 seconds).
# So, if now 2017-04-06 15:50:58.674+0000
# it returns 2017-04-05 15:50:58 +0000
#
# opts["now"] The current time for unit tests.
# If absent the "Time.now" is used.
#
def since(opts)
@since ||= if opts.key? "now"
Time.parse(opts["now"])
else
Time.now - opts.fetch("period", "86400").to_i
end
end
end

# Instance of "Due" history item for the particular ticket.
class Due
attr_reader :issue, :when

def initialize(issue, allowed)
def initialize(issue, allowed, since)
@issue = issue
@allowed = allowed
@since = since
end

# Gives true when last change of "Due Date" field was done
Expand All @@ -66,6 +85,11 @@ def illegal?
@allowed.none? { |a| a.eql? last.id }
end

# Give true when "Due Date" changes happens in past and its alert already sent.
def obsolete?
@when < @since
end

# Detect details about last change of "Due Date" to non-null value
def last
@last ||= begin
Expand All @@ -76,7 +100,7 @@ def last
@when = @issue["created"]
dd = @issue.reporter
else
@when = dd["created"].to_date
@when = dd["created"]
dd = Lazylead::User.new(dd["author"])
end
dd
Expand Down
2 changes: 1 addition & 1 deletion lib/messages/illegal_duedate_change.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<tr>
<td><a href='<%= d.issue.url %>'><%= d.issue.key %></a></td>
<td><%= d.issue.priority %></td>
<td><%= d.when %></td>
<td><%= d.when.to_date %></td>
<td><span style='color: red'><%= d.last.name %></span> (<%= d.last.id %>)</td>
<td><span style='color: red'><%= d.issue.duedate %></span></td>
<td><%= d.issue.assignee.name %></td>
Expand Down
7 changes: 7 additions & 0 deletions test/lazylead/task/micromanager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ class MicromanagerTest < Lazylead::Test
"jql" => "key in ('STS-3599','SPR-6541') and duedate is not empty",
"fields" => "assignee,duedate,priority,created,summary,reporter",
"allowed" => "tom,mike,bob",
"period" => "86400",
"now" => "2009-12-10T00:04:00.000+0000",
"subject" => "DD: How dare you?",
"template" => "lib/messages/illegal_duedate_change.erb"
)
)
assert_email "DD: How dare you?",
%w[SPR-6541 Major (kdonald) 2009-12-10 Spring's\ Maven\ Central tom,mike,bob]
end

test "since for past 1 min" do
greater_or_eq Task::Micromanager.new.since("period" => 60).to_i,
(Time.now - 60).to_i
end
end
end

0 comments on commit aa9aa62

Please sign in to comment.