lazylead 0.6.2 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +7 -2
  3. data/.docker/Dockerfile +17 -6
  4. data/.docs/duedate_expired.md +1 -1
  5. data/.rubocop.yml +119 -3
  6. data/.simplecov +1 -1
  7. data/Gemfile +1 -1
  8. data/Guardfile +2 -2
  9. data/Rakefile +7 -4
  10. data/bin/lazylead +4 -2
  11. data/lazylead.gemspec +33 -29
  12. data/lib/lazylead.rb +2 -2
  13. data/lib/lazylead/allocated.rb +1 -1
  14. data/lib/lazylead/cc.rb +22 -21
  15. data/lib/lazylead/cli/app.rb +3 -3
  16. data/lib/lazylead/confluence.rb +10 -3
  17. data/lib/lazylead/email.rb +1 -1
  18. data/lib/lazylead/exchange.rb +1 -1
  19. data/lib/lazylead/home.rb +1 -1
  20. data/lib/lazylead/log.rb +1 -1
  21. data/lib/lazylead/model.rb +25 -17
  22. data/lib/lazylead/opts.rb +22 -4
  23. data/lib/lazylead/postman.rb +1 -1
  24. data/lib/lazylead/requires.rb +38 -0
  25. data/lib/lazylead/salt.rb +2 -1
  26. data/lib/lazylead/schedule.rb +1 -1
  27. data/lib/lazylead/smtp.rb +1 -1
  28. data/lib/lazylead/system/empty.rb +1 -1
  29. data/lib/lazylead/system/fake.rb +1 -1
  30. data/lib/lazylead/system/jira.rb +28 -20
  31. data/lib/lazylead/system/synced.rb +1 -1
  32. data/lib/lazylead/task/accuracy/accuracy.rb +26 -32
  33. data/lib/lazylead/task/accuracy/affected_build.rb +1 -1
  34. data/lib/lazylead/task/accuracy/attachment.rb +3 -7
  35. data/lib/lazylead/task/accuracy/environment.rb +1 -1
  36. data/lib/lazylead/task/accuracy/logs.rb +9 -6
  37. data/lib/lazylead/task/accuracy/onlyll.rb +147 -0
  38. data/lib/lazylead/task/accuracy/records.rb +2 -2
  39. data/lib/lazylead/task/accuracy/requirement.rb +1 -1
  40. data/lib/lazylead/task/accuracy/servers.rb +17 -8
  41. data/lib/lazylead/task/accuracy/stacktrace.rb +2 -2
  42. data/lib/lazylead/task/accuracy/testcase.rb +3 -3
  43. data/lib/lazylead/task/accuracy/wiki.rb +1 -1
  44. data/lib/lazylead/task/{alert.rb → alert/alert.rb} +6 -6
  45. data/lib/lazylead/task/alert/alertif.rb +75 -0
  46. data/lib/lazylead/task/alert/changed_to.rb +58 -0
  47. data/lib/lazylead/task/assignment.rb +1 -1
  48. data/lib/lazylead/task/confluence_ref.rb +1 -1
  49. data/lib/lazylead/task/echo.rb +1 -1
  50. data/lib/lazylead/task/fix_version.rb +1 -1
  51. data/lib/lazylead/task/loading.rb +94 -0
  52. data/lib/lazylead/task/missing_comment.rb +1 -1
  53. data/lib/lazylead/task/propagate_down.rb +4 -4
  54. data/lib/lazylead/task/savepoint.rb +1 -1
  55. data/lib/lazylead/task/svn/diff.rb +2 -2
  56. data/lib/lazylead/task/svn/grep.rb +27 -20
  57. data/lib/lazylead/task/svn/touch.rb +3 -5
  58. data/lib/lazylead/version.rb +2 -2
  59. data/lib/messages/accuracy.erb +1 -1
  60. data/lib/messages/alertif.erb +134 -0
  61. data/lib/messages/created_recently.erb +110 -0
  62. data/lib/messages/loading.erb +117 -0
  63. data/lib/messages/only_ll.erb +107 -0
  64. data/readme.md +26 -18
  65. data/test/lazylead/allocated_test.rb +1 -1
  66. data/test/lazylead/cc_test.rb +2 -1
  67. data/test/lazylead/cli/app_test.rb +2 -2
  68. data/test/lazylead/confluence_test.rb +1 -1
  69. data/test/lazylead/exchange_test.rb +1 -1
  70. data/test/lazylead/model_test.rb +11 -1
  71. data/test/lazylead/opts_test.rb +13 -1
  72. data/test/lazylead/postman_test.rb +1 -1
  73. data/test/lazylead/salt_test.rb +1 -1
  74. data/test/lazylead/smoke_test.rb +14 -1
  75. data/test/lazylead/smtp_test.rb +2 -5
  76. data/test/lazylead/system/jira_test.rb +10 -1
  77. data/test/lazylead/task/accuracy/accuracy_test.rb +1 -1
  78. data/test/lazylead/task/accuracy/affected_build_test.rb +1 -1
  79. data/test/lazylead/task/accuracy/attachment_test.rb +2 -2
  80. data/test/lazylead/task/accuracy/environment_test.rb +1 -1
  81. data/test/lazylead/task/accuracy/logs_test.rb +13 -1
  82. data/test/lazylead/task/accuracy/onlyll_test.rb +138 -0
  83. data/test/lazylead/task/accuracy/records_test.rb +1 -1
  84. data/test/lazylead/task/accuracy/score_test.rb +29 -2
  85. data/test/lazylead/task/accuracy/servers_test.rb +3 -3
  86. data/test/lazylead/task/accuracy/stacktrace_test.rb +1 -1
  87. data/test/lazylead/task/accuracy/testcase_test.rb +28 -1
  88. data/test/lazylead/task/accuracy/wiki_test.rb +1 -1
  89. data/test/lazylead/task/alert/alertif_test.rb +54 -0
  90. data/test/lazylead/task/{assignee_alert_test.rb → alert/assignee_alert_test.rb} +10 -10
  91. data/test/lazylead/task/alert/changed_to_test.rb +42 -0
  92. data/test/lazylead/task/assignment_test.rb +1 -1
  93. data/test/lazylead/task/confluence_ref_test.rb +1 -1
  94. data/test/lazylead/task/created_recently_test.rb +53 -0
  95. data/test/lazylead/task/duedate_test.rb +5 -12
  96. data/test/lazylead/task/echo_test.rb +1 -1
  97. data/test/lazylead/task/fix_version_test.rb +1 -1
  98. data/test/lazylead/task/loading_test.rb +54 -0
  99. data/test/lazylead/task/missing_comment_test.rb +1 -1
  100. data/test/lazylead/task/propagate_down_test.rb +5 -4
  101. data/test/lazylead/task/savepoint_test.rb +3 -3
  102. data/test/lazylead/task/svn/diff_test.rb +1 -1
  103. data/test/lazylead/task/svn/grep_test.rb +1 -1
  104. data/test/lazylead/task/svn/touch_test.rb +1 -1
  105. data/test/lazylead/version_test.rb +1 -1
  106. data/test/sqlite_test.rb +1 -1
  107. data/test/test.rb +8 -9
  108. data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -1
  109. data/upgrades/sqlite/999.testdata.sql +3 -2
  110. metadata +133 -58
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -38,7 +38,7 @@ module Lazylead
38
38
  return false if issue.description.nil?
39
39
  @tc = @ar = @er = -1
40
40
  issue.description.split("\n").reject(&:blank?).each_with_index do |l, i|
41
- line = escape l.downcase.gsub(/(\s+|\*)/, "")
41
+ line = escape l.downcase.gsub(/(\s+|\*|\+)/, "")
42
42
  detect_tc line, i
43
43
  detect_ar line, i
44
44
  detect_er line, i
@@ -66,7 +66,7 @@ module Lazylead
66
66
  def detect_tc(line, index)
67
67
  return unless @tc.negative?
68
68
  @tc = index if eql? line,
69
- %w[testcase: tc: teststeps: teststeps steps: tcsteps:]
69
+ %w[testcase: tc: teststeps: teststeps steps: tcsteps: tc testcases steps]
70
70
  end
71
71
 
72
72
  # Detect index of line with actual result
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -22,11 +22,11 @@
22
22
  # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
23
23
  # OR OTHER DEALINGS IN THE SOFTWARE.
24
24
 
25
- require_relative "../log"
26
- require_relative "../opts"
27
- require_relative "../email"
28
- require_relative "../version"
29
- require_relative "../postman"
25
+ require_relative "../../log"
26
+ require_relative "../../opts"
27
+ require_relative "../../email"
28
+ require_relative "../../version"
29
+ require_relative "../../postman"
30
30
 
31
31
  module Lazylead
32
32
  #
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"),
9
+ # to deal in the Software without restriction, including without limitation
10
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
+ # and/or sell copies of the Software, and to permit persons to whom
12
+ # the Software is furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included
15
+ # in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
23
+ # OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require_relative "../../log"
26
+ require_relative "../../opts"
27
+ require_relative "../../email"
28
+ require_relative "../../postman"
29
+ require_relative "../../requires"
30
+
31
+ module Lazylead
32
+ module Task
33
+ #
34
+ # Send an alert if expected conditions are met.
35
+ #
36
+ # The task supports the following features:
37
+ # - fetch issues from remote ticketing system by query
38
+ # - evaluate set of rules for each ticket
39
+ # - send an email
40
+ # @todo #334:DEV AlertIf should support rules for bulk issues. For now each rule works per issue
41
+ class AlertIf
42
+ def run(sys, postman, opts)
43
+ Requires.new(__dir__).load
44
+ opts[:rules] = opts.construct("rules")
45
+ sys.issues(opts["jql"], opts.jira_defaults.merge(expand: "changelog"))
46
+ .map { |i| When.new(i, opts) }
47
+ .select(&:matches)
48
+ .group_by(&:assignee)
49
+ .each { |a, t| postman.send opts.merge(to: a.email, addressee: a.name, tickets: t) }
50
+ end
51
+ end
52
+
53
+ # The conditions for the issue inspection.
54
+ class When
55
+ extend Forwardable
56
+ def_delegators :@issue, :key, :url, :fields, :status, :duedate, :priority, :reporter,
57
+ :assignee, :summary, :comments
58
+
59
+ def initialize(issue, opts)
60
+ @issue = issue
61
+ @opts = opts
62
+ end
63
+
64
+ def matches
65
+ return false if @opts[:rules].nil?
66
+ @opts[:rules].all? { |r| r.passed(@issue, @opts) }
67
+ end
68
+
69
+ # The last comment in ticket
70
+ def last
71
+ @last ||= @issue.comments.last
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"),
9
+ # to deal in the Software without restriction, including without limitation
10
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
+ # and/or sell copies of the Software, and to permit persons to whom
12
+ # the Software is furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included
15
+ # in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
23
+ # OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require_relative "../../opts"
26
+
27
+ module Lazylead
28
+ #
29
+ # Gives true when ticket status changed to expected status(es).
30
+ #
31
+ class ChangedTo
32
+ def initialize(field, expected)
33
+ @field = field
34
+ @expected = expected
35
+ end
36
+
37
+ def passed(issue, opts)
38
+ return false if issue.nil? || opts.nil? || opts[@expected].nil? || @field.nil?
39
+ last = last_change(issue)
40
+ opts.slice(@expected, ",").any? { |s| s.eql? last }
41
+ end
42
+
43
+ # Detect the last change of expected field in issue history
44
+ def last_change(issue)
45
+ issue.history
46
+ .reverse
47
+ .find { |h| h["items"].any? { |i| i["field"] == @field } }["items"]
48
+ .find { |h| h["field"] == @field }["toString"]
49
+ end
50
+ end
51
+
52
+ # Check that last status change has expected value.
53
+ class ToStatus < Lazylead::ChangedTo
54
+ def initialize
55
+ super "status", "to_status"
56
+ end
57
+ end
58
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"),
9
+ # to deal in the Software without restriction, including without limitation
10
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
+ # and/or sell copies of the Software, and to permit persons to whom
12
+ # the Software is furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included
15
+ # in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
23
+ # OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require "date"
26
+ require_relative "../log"
27
+ require_relative "../opts"
28
+ require_relative "../system/jira"
29
+
30
+ module Lazylead
31
+ module Task
32
+ # Notification about team loading
33
+ class Loading
34
+ def initialize(log = Log.new)
35
+ @log = log
36
+ end
37
+
38
+ def run(sys, postman, opts)
39
+ assignments = sys.issues(opts["jql"])
40
+ .group_by(&:assignee)
41
+ .map { |user, tasks| [user.id, Teammate.new(user, tasks)] }
42
+ .to_h
43
+ opts.slice("team", ",")
44
+ .map { |m| m.split(":") }
45
+ .each { |id, name| assignments[id] = Free.new(id, name) unless assignments.key? id }
46
+ return if assignments.empty?
47
+ postman.send opts.merge(assignments: assignments)
48
+ end
49
+ end
50
+
51
+ # The teammate's tickets.
52
+ class Teammate
53
+ extend Forwardable
54
+ def_delegators :@user, :id, :name
55
+ def_delegators :@tasks, :size
56
+
57
+ def initialize(user, tasks = [])
58
+ @user = user
59
+ @tasks = tasks
60
+ end
61
+
62
+ def free?
63
+ return true if @tasks.nil?
64
+ @tasks.empty?
65
+ end
66
+
67
+ def next
68
+ @tasks.reject { |t| t.duedate.nil? }.map { |t| t.duedate.to_date }.min
69
+ end
70
+
71
+ def to_s
72
+ "#{id} has #{total} tasks"
73
+ end
74
+ end
75
+
76
+ # The teammate without tasks.
77
+ class Free
78
+ attr_reader :id, :name
79
+
80
+ def initialize(id, name)
81
+ @id = id
82
+ @name = name
83
+ end
84
+
85
+ def free?
86
+ true
87
+ end
88
+
89
+ def next
90
+ ""
91
+ end
92
+ end
93
+ end
94
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -87,9 +87,9 @@ module Lazylead
87
87
  # Fill pre-defined fields for sub-tasks from parent ticket
88
88
  # and post comment to ticket with clarification.
89
89
  def propagate
90
- expected = Hash[@fields.collect { |f| [f, @issue.fields[f]] }]
90
+ expected = @fields.collect { |f| [f, @issue.fields[f]] }.to_h
91
91
  @subtasks.each do |subtask|
92
- actual = Hash[@fields.collect { |f| [f, subtask.fields[f]] }]
92
+ actual = @fields.collect { |f| [f, subtask.fields[f]] }.to_h
93
93
  diff = diff(expected, actual)
94
94
  next if diff.empty?
95
95
  subtask.save(fields: diff)
@@ -106,7 +106,7 @@ module Lazylead
106
106
  v = a.last
107
107
  d[k] = expected[k] if v.nil? || v.blank?
108
108
  next if v.nil?
109
- d[k] = v + "," + expected[k] unless v.to_s.include? expected[k]
109
+ d[k] = "#{v},#{expected[k]}" unless v.to_s.include? expected[k]
110
110
  end
111
111
  end
112
112
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -67,7 +67,7 @@ module Lazylead
67
67
  File.delete(f)
68
68
  end
69
69
  rescue StandardError => e
70
- @log.error "ll-010: Can't send an email for #{opts} due to " \
70
+ @log.error "ll-010: Can't send an email '#{opts['subject']}' to #{opts['to']} due to " \
71
71
  "#{Backtrace.new(e)}'"
72
72
  end
73
73
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The MIT License
4
4
  #
5
- # Copyright (c) 2019-2020 Yurii Dubinka
5
+ # Copyright (c) 2019-2021 Yurii Dubinka
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"),
@@ -47,21 +47,28 @@ module Lazylead
47
47
 
48
48
  # Return all svn commits for particular date range in repo
49
49
  def svn_log(opts)
50
- now = if opts.key? "now"
51
- DateTime.parse(opts["now"])
52
- else
53
- DateTime.now
54
- end
55
- start = (now.to_time - opts["period"].to_i).to_datetime
56
50
  cmd = [
57
51
  "svn log --diff --no-auth-cache",
58
52
  "--username #{opts.decrypt('svn_user', 'svn_salt')}",
59
53
  "--password #{opts.decrypt('svn_password', 'svn_salt')}",
60
- "-r {#{start}}:{#{now}} #{opts['svn_url']}"
54
+ "-r {#{from(opts)}}:{#{now(opts)}} #{opts['svn_url']}"
61
55
  ]
62
56
  stdout = `#{cmd.join(" ")}`
63
- stdout.split("-" * 72).reject(&:blank?).reverse
64
- .map { |e| Entry.new(e) }
57
+ stdout.split("-" * 72).reject(&:blank?).reverse.map { |e| Entry.new(e) }
58
+ end
59
+
60
+ # The start date & time for search range
61
+ def from(opts)
62
+ (now(opts).to_time - opts["period"].to_i).to_datetime
63
+ end
64
+
65
+ # The current date & time for search range
66
+ def now(opts)
67
+ if opts.key? "now"
68
+ DateTime.parse(opts["now"])
69
+ else
70
+ DateTime.now
71
+ end
65
72
  end
66
73
  end
67
74
  end
@@ -78,7 +85,7 @@ module Lazylead
78
85
  end
79
86
 
80
87
  def rev
81
- header.first
88
+ header.first[1..]
82
89
  end
83
90
 
84
91
  def author
@@ -96,8 +103,8 @@ module Lazylead
96
103
  # The modified lines contains expected text
97
104
  def includes?(text)
98
105
  text = [text] unless text.respond_to? :each
99
- lines[4..-1].select { |l| l.start_with? "+" }
100
- .any? { |l| text.any? { |t| l.include? t } }
106
+ lines[4..].select { |l| l.start_with? "+" }
107
+ .any? { |l| text.any? { |t| l.include? t } }
101
108
  end
102
109
 
103
110
  def lines
@@ -111,12 +118,12 @@ module Lazylead
111
118
  # Detect SVN diff lines with particular text
112
119
  def diff(text)
113
120
  @diff ||= begin
114
- files = affected(text).uniq
115
- @commit.split("Index: ")
116
- .select { |i| files.any? { |f| i.start_with? f } }
117
- .map { |i| i.split "\n" }
118
- .flatten
119
- end
121
+ files = affected(text).uniq
122
+ @commit.split("Index: ")
123
+ .select { |i| files.any? { |f| i.start_with? f } }
124
+ .map { |i| i.split "\n" }
125
+ .flatten
126
+ end
120
127
  end
121
128
 
122
129
  # Detect affected files with particular text
@@ -125,7 +132,7 @@ module Lazylead
125
132
  lines[i].start_with?("+") && text.any? { |t| lines[i].include? t }
126
133
  end
127
134
  occurrences.map do |occ|
128
- lines[2..occ].reverse.find { |l| l.start_with? "Index: " }[7..-1]
135
+ lines[2..occ].reverse.find { |l| l.start_with? "Index: " }[7..]
129
136
  end
130
137
  end
131
138
  end