lazylead 0.5.2 → 0.7.1

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +7 -2
  3. data/.docker/Dockerfile +17 -6
  4. data/.rubocop.yml +102 -1
  5. data/.simplecov +1 -1
  6. data/Guardfile +1 -1
  7. data/Rakefile +6 -3
  8. data/bin/lazylead +3 -1
  9. data/lazylead.gemspec +31 -26
  10. data/lib/lazylead/cc.rb +21 -20
  11. data/lib/lazylead/cli/app.rb +8 -3
  12. data/lib/lazylead/confluence.rb +9 -2
  13. data/lib/lazylead/email.rb +0 -20
  14. data/lib/lazylead/exchange.rb +16 -28
  15. data/lib/lazylead/model.rb +31 -16
  16. data/lib/lazylead/opts.rb +65 -2
  17. data/lib/lazylead/postman.rb +13 -17
  18. data/lib/lazylead/salt.rb +1 -0
  19. data/lib/lazylead/system/jira.rb +30 -6
  20. data/lib/lazylead/task/accuracy/accuracy.rb +10 -14
  21. data/lib/lazylead/task/accuracy/attachment.rb +2 -6
  22. data/lib/lazylead/task/accuracy/logs.rb +9 -5
  23. data/lib/lazylead/task/accuracy/onlyll.rb +147 -0
  24. data/lib/lazylead/task/accuracy/records.rb +1 -1
  25. data/lib/lazylead/task/accuracy/servers.rb +16 -7
  26. data/lib/lazylead/task/accuracy/stacktrace.rb +50 -10
  27. data/lib/lazylead/task/accuracy/testcase.rb +16 -9
  28. data/lib/lazylead/task/assignment.rb +96 -0
  29. data/lib/lazylead/task/fix_version.rb +6 -0
  30. data/lib/lazylead/task/propagate_down.rb +1 -1
  31. data/lib/lazylead/task/svn/diff.rb +77 -0
  32. data/lib/lazylead/task/svn/grep.rb +139 -0
  33. data/lib/lazylead/task/svn/touch.rb +99 -0
  34. data/lib/lazylead/version.rb +1 -1
  35. data/lib/messages/illegal_assignee_change.erb +123 -0
  36. data/lib/messages/illegal_fixversion_change.erb +8 -0
  37. data/lib/messages/only_ll.erb +107 -0
  38. data/lib/messages/svn_diff.erb +110 -0
  39. data/lib/messages/{svn_log.erb → svn_diff_attachment.erb} +19 -9
  40. data/lib/messages/svn_grep.erb +114 -0
  41. data/test/lazylead/cc_test.rb +1 -0
  42. data/test/lazylead/model_test.rb +20 -0
  43. data/test/lazylead/opts_test.rb +47 -0
  44. data/test/lazylead/postman_test.rb +8 -5
  45. data/test/lazylead/smoke_test.rb +13 -0
  46. data/test/lazylead/smtp_test.rb +1 -4
  47. data/test/lazylead/system/jira_test.rb +6 -7
  48. data/test/lazylead/task/accuracy/attachment_test.rb +1 -1
  49. data/test/lazylead/task/accuracy/logs_test.rb +62 -2
  50. data/test/lazylead/task/accuracy/onlyll_test.rb +138 -0
  51. data/test/lazylead/task/accuracy/servers_test.rb +2 -2
  52. data/test/lazylead/task/accuracy/stacktrace_test.rb +227 -0
  53. data/test/lazylead/task/accuracy/testcase_test.rb +39 -0
  54. data/test/lazylead/task/assignment_test.rb +53 -0
  55. data/test/lazylead/task/duedate_test.rb +3 -10
  56. data/test/lazylead/task/fix_version_test.rb +1 -0
  57. data/test/lazylead/task/propagate_down_test.rb +4 -3
  58. data/test/lazylead/task/savepoint_test.rb +9 -6
  59. data/test/lazylead/task/svn/diff_test.rb +97 -0
  60. data/test/lazylead/task/svn/grep_test.rb +103 -0
  61. data/test/lazylead/task/{touch_test.rb → svn/touch_test.rb} +7 -34
  62. data/test/test.rb +7 -8
  63. data/upgrades/sqlite/999.testdata.sql +3 -1
  64. metadata +141 -55
  65. data/lib/lazylead/task/touch.rb +0 -119
@@ -85,6 +85,12 @@ module Lazylead
85
85
  def add_label
86
86
  @issue.add_label("LL.IllegalChangeOfFixVersion") unless @silent
87
87
  end
88
+
89
+ def to
90
+ versions = @issue.fields["fixVersions"]
91
+ return "" if versions.nil? || versions.empty?
92
+ versions.map { |x| x["name"] }.join(",")
93
+ end
88
94
  end
89
95
  end
90
96
  end
@@ -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
 
@@ -0,0 +1,77 @@
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 "tempfile"
26
+ require "nokogiri"
27
+ require "backtrace"
28
+ require "active_support/core_ext/hash/conversions"
29
+ require_relative "../../salt"
30
+ require_relative "../../opts"
31
+
32
+ module Lazylead
33
+ module Task
34
+ module Svn
35
+ #
36
+ # Send notification about modification of svn files since particular
37
+ # revision.
38
+ #
39
+ class Diff
40
+ def initialize(log = Log.new)
41
+ @log = log
42
+ end
43
+
44
+ def run(_, postman, opts)
45
+ cmd = [
46
+ "svn log --diff --no-auth-cache",
47
+ "--username #{opts.decrypt('svn_user', 'svn_salt')}",
48
+ "--password #{opts.decrypt('svn_password', 'svn_salt')}",
49
+ "-r#{opts['since_rev']}:HEAD #{opts['svn_url']}"
50
+ ]
51
+ stdout = `#{cmd.join(" ")}`
52
+ send_email postman, opts.merge(stdout: stdout) unless stdout.blank?
53
+ end
54
+
55
+ # Send email with svn log as an attachment.
56
+ # The attachment won't be stored locally and we'll be removed once
57
+ # mail sent.
58
+ def send_email(postman, opts)
59
+ Dir.mktmpdir do |dir|
60
+ name = "svn-log-#{Date.today.strftime('%d-%b-%Y')}.html"
61
+ f = File.open(File.join(dir, name), "w")
62
+ begin
63
+ f.write opts.msg_body("template-attachment")
64
+ f.close
65
+ postman.send opts.merge(attachments: [f.path])
66
+ ensure
67
+ File.delete(f)
68
+ end
69
+ rescue StandardError => e
70
+ @log.error "ll-010: Can't send an email for #{opts} due to " \
71
+ "#{Backtrace.new(e)}'"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,139 @@
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
+ # Detect particular text in diff commit.
36
+ #
37
+ class Grep
38
+ def initialize(log = Log.new)
39
+ @log = log
40
+ end
41
+
42
+ def run(_, postman, opts)
43
+ text = opts.slice("text", ",")
44
+ commits = svn_log(opts).select { |c| c.includes? text }
45
+ postman.send(opts.merge(entries: commits)) unless commits.empty?
46
+ end
47
+
48
+ # Return all svn commits for particular date range in repo
49
+ def svn_log(opts)
50
+ cmd = [
51
+ "svn log --diff --no-auth-cache",
52
+ "--username #{opts.decrypt('svn_user', 'svn_salt')}",
53
+ "--password #{opts.decrypt('svn_password', 'svn_salt')}",
54
+ "-r {#{from(opts)}}:{#{now(opts)}} #{opts['svn_url']}"
55
+ ]
56
+ stdout = `#{cmd.join(" ")}`
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
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ # Single SVN commit details
78
+ class Entry
79
+ def initialize(commit)
80
+ @commit = commit
81
+ end
82
+
83
+ def to_s
84
+ "#{rev} #{msg}"
85
+ end
86
+
87
+ def rev
88
+ header.first[1..]
89
+ end
90
+
91
+ def author
92
+ header[1]
93
+ end
94
+
95
+ def time
96
+ header[2]
97
+ end
98
+
99
+ def msg
100
+ lines[1]
101
+ end
102
+
103
+ # The modified lines contains expected text
104
+ def includes?(text)
105
+ text = [text] unless text.respond_to? :each
106
+ lines[4..].select { |l| l.start_with? "+" }
107
+ .any? { |l| text.any? { |t| l.include? t } }
108
+ end
109
+
110
+ def lines
111
+ @lines ||= @commit.split("\n").reject(&:blank?)
112
+ end
113
+
114
+ def header
115
+ @header ||= lines.first.split(" | ").reject(&:blank?)
116
+ end
117
+
118
+ # Detect SVN diff lines with particular text
119
+ def diff(text)
120
+ @diff ||= begin
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
127
+ end
128
+
129
+ # Detect affected files with particular text
130
+ def affected(text)
131
+ occurrences = lines.each_index.select do |i|
132
+ lines[i].start_with?("+") && text.any? { |t| lines[i].include? t }
133
+ end
134
+ occurrences.map do |occ|
135
+ lines[2..occ].reverse.find { |l| l.start_with? "Index: " }[7..]
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,99 @@
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 critical files in svn repo.
36
+ #
37
+ class Touch
38
+ def initialize(log = Log.new)
39
+ @log = log
40
+ end
41
+
42
+ def run(_, postman, opts)
43
+ files = opts.slice("files", ",")
44
+ commits = touch(files, opts)
45
+ postman.send(opts.merge(entries: commits)) unless commits.empty?
46
+ end
47
+
48
+ # Return all svn commits for a particular date range, which are touching
49
+ # somehow the critical files within the svn repo.
50
+ def touch(files, opts)
51
+ xpath = files.map { |f| "contains(text(),\"#{f}\")" }.join(" or ")
52
+ svn_log(opts).xpath("//logentry[paths/path[#{xpath}]]")
53
+ .map { |xml| to_entry(xml) }
54
+ .each do |e|
55
+ e.paths.path.delete_if { |p| files.none? { |f| p.include? f } } if e.paths.path.respond_to? :delete_if
56
+ end
57
+ end
58
+
59
+ # Return all svn commits for particular date range in repo
60
+ def svn_log(opts)
61
+ now = if opts.key? "now"
62
+ DateTime.parse(opts["now"])
63
+ else
64
+ DateTime.now
65
+ end
66
+ start = (now.to_time - opts["period"].to_i).to_datetime
67
+ cmd = [
68
+ "svn log --no-auth-cache",
69
+ "--username #{opts.decrypt('svn_user', 'svn_salt')}",
70
+ "--password #{opts.decrypt('svn_password', 'svn_salt')}",
71
+ "--xml -v -r {#{start}}:{#{now}} #{opts['svn_url']}"
72
+ ]
73
+ raw = `#{cmd.join(" ")}`
74
+ Nokogiri.XML(raw, nil, "UTF-8")
75
+ end
76
+
77
+ # Convert single revision(XML text) to entry object.
78
+ # Entry object is a simple ruby struct object.
79
+ def to_entry(xml)
80
+ e = to_struct(Hash.from_xml(xml.to_s.strip)).logentry
81
+ if e.paths.path.respond_to? :each
82
+ e.paths.path.each(&:strip!)
83
+ else
84
+ e.paths.path.strip!
85
+ end
86
+ e
87
+ end
88
+
89
+ # Make a simple ruby struct object from hash hierarchically,
90
+ # considering nested hash(es) (if applicable)
91
+ def to_struct(hsh)
92
+ OpenStruct.new(
93
+ hsh.transform_values { |v| v.is_a?(Hash) ? to_struct(v) : v }
94
+ )
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -23,5 +23,5 @@
23
23
  # OR OTHER DEALINGS IN THE SOFTWARE.
24
24
 
25
25
  module Lazylead
26
- VERSION = "0.5.2"
26
+ VERSION = "0.7.1"
27
27
  end
@@ -0,0 +1,123 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <style>
5
+ /* CSS styles taken from https://github.com/yegor256/tacit */
6
+ th {
7
+ font-weight: 600
8
+ }
9
+
10
+ table tr {
11
+ border-bottom-width: 2.16px
12
+ }
13
+
14
+ table tr th {
15
+ border-bottom-width: 2.16px
16
+ }
17
+
18
+ table tr td, table tr th {
19
+ overflow: hidden;
20
+ padding: 5.4px 3.6px
21
+ }
22
+
23
+ a {
24
+ color: #275a90;
25
+ text-decoration: none
26
+ }
27
+
28
+ a:hover {
29
+ text-decoration: underline
30
+ }
31
+
32
+ pre, code, kbd, samp, var, output {
33
+ font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
34
+ font-size: 13px
35
+ }
36
+
37
+ pre code {
38
+ background: none;
39
+ border: 0;
40
+ line-height: 29.7px;
41
+ padding: 0
42
+ }
43
+
44
+ code, kbd {
45
+ background: #daf1e0;
46
+ border-radius: 3.6px;
47
+ color: #2a6f3b;
48
+ display: inline-block;
49
+ line-height: 18px;
50
+ padding: 3.6px 6.3px 2.7px
51
+ }
52
+
53
+ * {
54
+ border: 0;
55
+ border-collapse: separate;
56
+ border-spacing: 0;
57
+ box-sizing: border-box;
58
+ margin: 0;
59
+ max-width: 100%;
60
+ padding: 0;
61
+ vertical-align: baseline;
62
+ font-family: system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif;
63
+ font-size: 13px;
64
+ font-stretch: normal;
65
+ font-style: normal;
66
+ font-weight: 400;
67
+ line-height: 29.7px
68
+ }
69
+
70
+ html, body {
71
+ width: 100%
72
+ }
73
+
74
+ html {
75
+ height: 100%
76
+ }
77
+
78
+ body {
79
+ background: #fff;
80
+ color: #1a1919;
81
+ padding: 36px
82
+ }
83
+ </style>
84
+ <title>Not authorized "Assignee" change</title>
85
+ </head>
86
+ <body>
87
+ <p>Hi,</p>
88
+
89
+ <p>The <span style='font-weight:bold'>'Assignee'</span> for the following
90
+ ticket(s) changed by not authorized person(s):</p>
91
+ <table summary="ticket(s) where assignee changed">
92
+ <tr>
93
+ <th id="key">Key</th>
94
+ <th id="priority">Priority</th>
95
+ <th id="when">When</th>
96
+ <th id="who">Who</th>
97
+ <th id="to">To</th>
98
+ <th id="summary">Summary</th>
99
+ <th id="reporter">Reporter</th>
100
+ </tr>
101
+ <% assignees.each do |a| %>
102
+ <tr>
103
+ <td><a href='<%= a.issue.url %>'><%= a.issue.key %></a></td>
104
+ <td><%= a.issue.priority %></td>
105
+ <td><%= DateTime.parse(a.last["created"])
106
+ .strftime('%d-%b-%Y %I:%M:%S %p') %></td>
107
+ <td><span style='color: red'><%= a.last["author"]["displayName"] %></span>
108
+ (<%= a.last["author"]["name"] %>)
109
+ </td>
110
+ <td><%= a.to %></td>
111
+ <td><%= a.issue.summary %></td>
112
+ <td><%= a.issue.reporter.name %></td>
113
+ </tr>
114
+ <% end %>
115
+ </table>
116
+
117
+ <p>Authorized person(s) are: <code><%= allowed %></code>.</p>
118
+
119
+ <p>Posted by
120
+ <a href="https://github.com/dgroup/lazylead">lazylead v<%= version %></a>.
121
+ </p>
122
+ </body>
123
+ </html>