lazylead 0.4.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.docs/accuracy.md +2 -2
  3. data/.docs/duedate_expired.md +3 -3
  4. data/.docs/propagate_down.md +3 -3
  5. data/.gitattributes +1 -0
  6. data/.github/dependabot.yml +6 -0
  7. data/Rakefile +6 -3
  8. data/bin/lazylead +7 -5
  9. data/lazylead.gemspec +5 -3
  10. data/lib/lazylead/cli/app.rb +5 -2
  11. data/lib/lazylead/exchange.rb +15 -9
  12. data/lib/lazylead/log.rb +2 -1
  13. data/lib/lazylead/model.rb +35 -1
  14. data/lib/lazylead/opts.rb +13 -0
  15. data/lib/lazylead/postman.rb +13 -7
  16. data/lib/lazylead/schedule.rb +16 -15
  17. data/lib/lazylead/smtp.rb +3 -1
  18. data/lib/lazylead/system/jira.rb +65 -4
  19. data/lib/lazylead/task/accuracy/accuracy.rb +13 -8
  20. data/lib/lazylead/task/accuracy/affected_build.rb +2 -6
  21. data/lib/lazylead/task/accuracy/attachment.rb +44 -0
  22. data/lib/lazylead/task/accuracy/environment.rb +39 -0
  23. data/lib/lazylead/task/accuracy/logs.rb +42 -0
  24. data/lib/lazylead/task/accuracy/records.rb +45 -0
  25. data/lib/lazylead/task/accuracy/requirement.rb +9 -0
  26. data/lib/lazylead/task/accuracy/servers.rb +50 -0
  27. data/lib/lazylead/task/accuracy/stacktrace.rb +103 -0
  28. data/lib/lazylead/task/accuracy/testcase.rb +91 -0
  29. data/lib/lazylead/task/accuracy/wiki.rb +41 -0
  30. data/lib/lazylead/task/assignment.rb +96 -0
  31. data/lib/lazylead/task/echo.rb +18 -0
  32. data/lib/lazylead/task/fix_version.rb +13 -2
  33. data/lib/lazylead/task/svn/diff.rb +76 -0
  34. data/lib/lazylead/task/svn/grep.rb +111 -0
  35. data/lib/lazylead/task/svn/touch.rb +101 -0
  36. data/lib/lazylead/version.rb +1 -1
  37. data/lib/messages/illegal_assignee_change.erb +123 -0
  38. data/lib/messages/illegal_fixversion_change.erb +2 -0
  39. data/lib/messages/svn_diff.erb +110 -0
  40. data/lib/messages/svn_diff_attachment.erb +117 -0
  41. data/lib/messages/svn_grep.erb +114 -0
  42. data/lib/messages/svn_touch.erb +1 -1
  43. data/license.txt +1 -1
  44. data/readme.md +5 -5
  45. data/test/lazylead/cli/app_test.rb +11 -11
  46. data/test/lazylead/system/jira_test.rb +41 -4
  47. data/test/lazylead/task/accuracy/accuracy_test.rb +1 -1
  48. data/test/lazylead/task/accuracy/affected_build_test.rb +2 -2
  49. data/test/lazylead/task/accuracy/attachment_test.rb +50 -0
  50. data/test/lazylead/task/accuracy/environment_test.rb +42 -0
  51. data/test/lazylead/task/accuracy/logs_test.rb +138 -0
  52. data/test/lazylead/task/accuracy/records_test.rb +60 -0
  53. data/test/lazylead/task/accuracy/score_test.rb +46 -0
  54. data/test/lazylead/task/accuracy/servers_test.rb +66 -0
  55. data/test/lazylead/task/accuracy/stacktrace_test.rb +340 -0
  56. data/test/lazylead/task/accuracy/testcase_test.rb +225 -0
  57. data/test/lazylead/task/accuracy/wiki_test.rb +40 -0
  58. data/test/lazylead/task/{touch_test.rb → assignment_test.rb} +17 -27
  59. data/test/lazylead/task/svn/diff_test.rb +97 -0
  60. data/test/lazylead/task/svn/grep_test.rb +61 -0
  61. data/test/lazylead/task/svn/touch_test.rb +61 -0
  62. data/test/test.rb +25 -0
  63. data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -5
  64. data/upgrades/sqlite/999.testdata.sql +12 -17
  65. metadata +88 -21
  66. data/.travis.yml +0 -16
  67. data/lib/lazylead/task/touch.rb +0 -102
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2020 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 "requirement"
26
+
27
+ module Lazylead
28
+ # Java stacktrace or Oracle errors in {noformat} section
29
+ class Stacktrace < Lazylead::Requirement
30
+ def initialize(score = 3)
31
+ super "Stacktrace/errors in *\\{noformat\\}* for JIRA indexing", score,
32
+ "Description"
33
+ end
34
+
35
+ def passed(issue)
36
+ return false if issue.description.nil?
37
+ frames(issue.description).any? { |f| oracle?(f) || java?(f) }
38
+ end
39
+
40
+ # Detect all {noformat}, {code} frames in ticket description
41
+ def frames(description)
42
+ noformat(description).concat(code(description))
43
+ end
44
+
45
+ # Detect all noformat blocks and give all text snippets in array
46
+ # @param desc The jira ticket description
47
+ def noformat(desc)
48
+ return [] unless desc.match?(/{(n|N)(o|O)(f|F)(o|O)(r|R)(m|M)(a|A)(t|T)}/)
49
+ desc.enum_for(:scan, /(?=\{(n|N)(o|O)(f|F)(o|O)(r|R)(m|M)(a|A)(t|T)})/)
50
+ .map { Regexp.last_match.offset(0).first }
51
+ .each_slice(2).map do |f|
52
+ desc[f.first, f.last - f.first + "{noformat}".size]
53
+ end
54
+ end
55
+
56
+ # Detect all {code:*} blocks and give all text snippets in array
57
+ # @param desc The jira ticket description
58
+ def code(desc)
59
+ return [] unless desc.match?(/{(c|C)(o|O)(d|D)(e|E)(:\S+)?}/)
60
+ words = desc.gsub(/{(c|C)(o|O)(d|D)(e|E)/, " {code")
61
+ .gsub("}", "} ")
62
+ .gsub("Caused by:", "Caused_by:")
63
+ .split(" ")
64
+ .map(&:strip)
65
+ .reject(&:blank?)
66
+ pairs(words, "{code").map { |s| words[s.first..s.last].join("\n") }
67
+ end
68
+
69
+ # Detect indexes of pairs which are starting from particular text
70
+ # @param words is array of words
71
+ # @param text is a label for pairs
72
+ #
73
+ # paris([aa,tag,bb,cc,tag,dd], "tag") => [[1, 4]]
74
+ # paris([aa,tag,bb,cc,tag,dd,tag,ee], "tag") => [[1, 4]] # non closed
75
+ #
76
+ def pairs(words, text)
77
+ snippets = [[]]
78
+ words.each_with_index do |e, i|
79
+ next unless e.start_with? text
80
+ pair = snippets.last
81
+ pair << i if pair.size.zero? || pair.size == 1
82
+ snippets[-1] = pair
83
+ snippets << [] if pair.size == 2
84
+ end
85
+ snippets.select { |s| s.size == 2 }
86
+ end
87
+
88
+ # @return true if frame has few lines with java stack frames
89
+ def java?(frame)
90
+ allowed = ["at", "Caused by:", "Caused_by:"]
91
+ frame.match?(/\s\S+\.\S+Exception:\s/) ||
92
+ frame.split("\n")
93
+ .map(&:strip)
94
+ .count { |l| allowed.any? { |a| l.start_with? a } } > 3
95
+ end
96
+
97
+ # @return true if frame has Oracle error
98
+ # @see https://docs.oracle.com/pls/db92/db92.error_search
99
+ def oracle?(frame)
100
+ frame.match?(/\WORA-\d{5}:/)
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2020 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 "requirement"
26
+
27
+ module Lazylead
28
+ # Check the 'Description' field that ticket has mandatory details like
29
+ # - test case (TC)
30
+ # - actual result (AR)
31
+ # - expected result (ER)
32
+ class Testcase < Lazylead::Requirement
33
+ def initialize(score = 4)
34
+ super "Test case with AR/ER", score, "Description"
35
+ end
36
+
37
+ def passed(issue)
38
+ return false if issue.description.nil?
39
+ @tc = @ar = @er = -1
40
+ issue.description.split("\n").reject(&:blank?).each_with_index do |l, i|
41
+ line = escape(l.downcase.gsub(/\s+/, ""))
42
+ detect_tc(line, i)
43
+ detect_ar(line, i)
44
+ detect_er(line, i)
45
+ break if with_tc_ar_er?
46
+ end
47
+ with_tc_ar_er?
48
+ end
49
+
50
+ def escape(line)
51
+ if line.include?("{color")
52
+ line.gsub(
53
+ /({color:(#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|[A-Za-z]+)})|{color}/, ""
54
+ )
55
+ else
56
+ line.gsub(/[^a-zA-Z(:|=)]/, "")
57
+ end
58
+ end
59
+
60
+ # @return true if description has test case, AR and ER
61
+ def with_tc_ar_er?
62
+ (@tc.zero? || @tc.positive?) && @ar.positive? && @er.positive?
63
+ end
64
+
65
+ # Detect index of line with test case
66
+ def detect_tc(line, index)
67
+ return unless @tc.negative?
68
+ @tc = index if eql?(line, %w[testcase: tc: teststeps: teststeps steps:])
69
+ end
70
+
71
+ # Detect index of line with actual result
72
+ def detect_ar(line, index)
73
+ return unless @ar.negative? && index > @tc
74
+ @ar = index if starts?(line, %w[ar: actualresult: ar= *ar*= *ar*:])
75
+ end
76
+
77
+ # Detect index of line with expected result
78
+ def detect_er(line, index)
79
+ return unless @er.negative? && index > @tc
80
+ @er = index if starts?(line, %w[er: expectedresult: er= *er*= *er*:])
81
+ end
82
+
83
+ def starts?(line, text)
84
+ text.any? { |t| line.start_with? t }
85
+ end
86
+
87
+ def eql?(line, text)
88
+ text.any? { |t| t.eql? line }
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2020 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 "requirement"
26
+
27
+ module Lazylead
28
+ # Check that ticket has a remote link to external system with relationship
29
+ # type = "Wiki Page".
30
+ class Wiki < Lazylead::Requirement
31
+ def initialize(score = 2, relationship = "Wiki Page")
32
+ super "Reference to design specification", score, "Ticket Links (Wiki)"
33
+ @relationship = relationship
34
+ end
35
+
36
+ def passed(issue)
37
+ return false if issue.remote_links.nil? || issue.remote_links.empty?
38
+ issue.remote_links.any? { |l| @relationship.eql? l.attrs["relationship"] }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2020 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
+ #
33
+ # Email alerts about illegal issue assignment(s).
34
+ #
35
+ # Author:: Yurii Dubinka (yurii.dubinka@gmail.com)
36
+ # Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
37
+ # License:: MIT
38
+ class Assignment
39
+ def initialize(log = Log.new)
40
+ @log = log
41
+ end
42
+
43
+ def run(sys, postman, opts)
44
+ allowed = opts.slice "allowed", ","
45
+ silent = opts.key? "silent"
46
+ issues = sys.issues opts["jql"],
47
+ opts.jira_defaults.merge(expand: "changelog")
48
+ return if issues.empty?
49
+ postman.send opts.merge(
50
+ assignees: issues.map { |i| Assignee.new(i, allowed, silent) }
51
+ .select(&:illegal?)
52
+ .each(&:add_label)
53
+ )
54
+ end
55
+ end
56
+
57
+ # Instance of "Assignee" history item for the particular ticket.
58
+ class Assignee
59
+ attr_reader :issue
60
+
61
+ def initialize(issue, allowed, silent)
62
+ @issue = issue
63
+ @allowed = allowed
64
+ @silent = silent
65
+ end
66
+
67
+ # Gives true when last change of "Assignee" field was done
68
+ # by not authorized person.
69
+ def illegal?
70
+ @allowed.none? do |a|
71
+ return false if last.nil?
72
+ a == last["author"]["name"]
73
+ end
74
+ end
75
+
76
+ # Detect details about last change of "Assignee" to non-null value
77
+ def last
78
+ @last ||= issue.history.reverse.find do |h|
79
+ h["items"].any? do |i|
80
+ i["field"] == "assignee"
81
+ end
82
+ end
83
+ end
84
+
85
+ # Mark ticket with particular label
86
+ def add_label(name = "LL.IllegalChangeOfAssignee")
87
+ @issue.add_label(name) unless @silent
88
+ end
89
+
90
+ # The name of current assignee for ticket
91
+ def to
92
+ @issue.fields["assignee"]["name"]
93
+ end
94
+ end
95
+ end
96
+ end
@@ -22,6 +22,8 @@
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
+
25
27
  module Lazylead
26
28
  module Task
27
29
  # Lazylead task which prints to STDOUT the current class name and team.
@@ -38,5 +40,21 @@ module Lazylead
38
40
  self.class.to_s
39
41
  end
40
42
  end
43
+
44
+ # Lazylead task which prints the current time to a file.
45
+ #
46
+ # Author:: Yurii Dubinka (yurii.dubinka@gmail.com)
47
+ # Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
48
+ # License:: MIT
49
+ class EchoIO
50
+ def initialize(log = Log.new, path = "test/resources/echo.txt")
51
+ @log = log
52
+ @path = path
53
+ end
54
+
55
+ def run(_, _, _)
56
+ File.open(@path, "w") { |f| f.write Time.now }
57
+ end
58
+ end
41
59
  end
42
60
  end
@@ -38,13 +38,15 @@ module Lazylead
38
38
 
39
39
  def run(sys, postman, opts)
40
40
  allowed = opts.slice("allowed", ",")
41
+ silent = opts.key? "silent"
41
42
  issues = sys.issues(
42
43
  opts["jql"], opts.jira_defaults.merge(expand: "changelog")
43
44
  )
44
45
  return if issues.empty?
45
46
  postman.send opts.merge(
46
- versions: issues.map { |i| Version.new(i, allowed) }
47
+ versions: issues.map { |i| Version.new(i, allowed, silent) }
47
48
  .select(&:changed?)
49
+ .each(&:add_label)
48
50
  )
49
51
  end
50
52
  end
@@ -53,9 +55,10 @@ module Lazylead
53
55
  class Version
54
56
  attr_reader :issue
55
57
 
56
- def initialize(issue, allowed)
58
+ def initialize(issue, allowed, silent)
57
59
  @issue = issue
58
60
  @allowed = allowed
61
+ @silent = silent
59
62
  end
60
63
 
61
64
  # Gives true when last change of "Fix Version" field was done
@@ -78,6 +81,14 @@ module Lazylead
78
81
  end
79
82
  end
80
83
  end
84
+
85
+ def add_label
86
+ @issue.add_label("LL.IllegalChangeOfFixVersion") unless @silent
87
+ end
88
+
89
+ def current
90
+ @issue.fields["fixVersions"].first["name"]
91
+ end
81
92
  end
82
93
  end
83
94
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License
4
+ #
5
+ # Copyright (c) 2019-2020 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 "tmpdir"
26
+ require "nokogiri"
27
+ require "active_support/core_ext/hash/conversions"
28
+ require_relative "../../salt"
29
+ require_relative "../../opts"
30
+
31
+ module Lazylead
32
+ module Task
33
+ module Svn
34
+ #
35
+ # Send notification about modification of svn files since particular
36
+ # revision.
37
+ #
38
+ class Diff
39
+ def initialize(log = Log.new)
40
+ @log = log
41
+ end
42
+
43
+ def run(_, postman, opts)
44
+ cmd = [
45
+ "svn log --diff --no-auth-cache",
46
+ "--username #{opts.decrypt('svn_user', 'svn_salt')}",
47
+ "--password #{opts.decrypt('svn_password', 'svn_salt')}",
48
+ "-r#{opts['since_rev']}:HEAD #{opts['svn_url']}"
49
+ ]
50
+ stdout = `#{cmd.join(" ")}`
51
+ send_email stdout, postman, opts unless stdout.blank?
52
+ end
53
+
54
+ # Send email with svn log as an attachment.
55
+ # The attachment won't be stored locally and we'll be removed once
56
+ # mail sent.
57
+ def send_email(stdout, postman, opts)
58
+ Dir.mktmpdir do |dir|
59
+ name = "svn-log-#{Date.today.strftime('%d-%b-%Y')}.html"
60
+ f = File.open(File.join(dir, name), "w")
61
+ f.write(
62
+ Email.new(
63
+ opts["template-attachment"],
64
+ opts.merge(stdout: stdout, version: Lazylead::VERSION)
65
+ ).render
66
+ )
67
+ postman.send opts.merge(stdout: stdout, attachments: [f.path])
68
+ rescue StandardError => e
69
+ @log.error "ll-010: Can't send an email for #{opts} based on "\
70
+ "'#{stdout}'", e
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end