lazylead 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) 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 +4 -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 +36 -2
  14. data/lib/lazylead/opts.rb +13 -1
  15. data/lib/lazylead/postman.rb +9 -4
  16. data/lib/lazylead/schedule.rb +16 -15
  17. data/lib/lazylead/smtp.rb +3 -1
  18. data/lib/lazylead/system/jira.rb +44 -0
  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 +40 -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 +63 -0
  28. data/lib/lazylead/task/accuracy/testcase.rb +85 -0
  29. data/lib/lazylead/task/accuracy/wiki.rb +41 -0
  30. data/lib/lazylead/task/echo.rb +18 -0
  31. data/lib/lazylead/task/fix_version.rb +9 -2
  32. data/lib/lazylead/task/touch.rb +28 -11
  33. data/lib/lazylead/version.rb +1 -1
  34. data/lib/messages/svn_log.erb +117 -0
  35. data/lib/messages/svn_touch.erb +1 -1
  36. data/license.txt +1 -1
  37. data/readme.md +5 -5
  38. data/test/lazylead/cli/app_test.rb +11 -11
  39. data/test/lazylead/opts_test.rb +4 -0
  40. data/test/lazylead/system/jira_test.rb +38 -0
  41. data/test/lazylead/task/accuracy/accuracy_test.rb +1 -1
  42. data/test/lazylead/task/accuracy/affected_build_test.rb +2 -2
  43. data/test/lazylead/task/accuracy/attachment_test.rb +50 -0
  44. data/test/lazylead/task/accuracy/environment_test.rb +42 -0
  45. data/test/lazylead/task/accuracy/logs_test.rb +78 -0
  46. data/test/lazylead/task/accuracy/records_test.rb +60 -0
  47. data/test/lazylead/task/accuracy/score_test.rb +46 -0
  48. data/test/lazylead/task/accuracy/servers_test.rb +66 -0
  49. data/test/lazylead/task/accuracy/stacktrace_test.rb +113 -0
  50. data/test/lazylead/task/accuracy/testcase_test.rb +215 -0
  51. data/test/lazylead/task/accuracy/wiki_test.rb +40 -0
  52. data/test/lazylead/task/touch_test.rb +48 -23
  53. data/test/test.rb +25 -0
  54. data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -5
  55. data/upgrades/sqlite/999.testdata.sql +12 -17
  56. metadata +59 -18
  57. data/.travis.yml +0 -16
@@ -23,6 +23,7 @@
23
23
  # OR OTHER DEALINGS IN THE SOFTWARE.
24
24
 
25
25
  require "mail"
26
+ require "colorize"
26
27
  require_relative "log"
27
28
  require_relative "salt"
28
29
 
@@ -45,7 +46,8 @@ module Lazylead
45
46
  Mail.defaults do
46
47
  delivery_method :test
47
48
  end
48
- @log.warn "SMTP connection enabled in test mode."
49
+ @log.warn "SMTP connection enabled in " \
50
+ "#{'test'.colorize(:light_yellow)} mode."
49
51
  else
50
52
  setup_smtp
51
53
  end
@@ -150,6 +150,11 @@ module Lazylead
150
150
  @issue.key
151
151
  end
152
152
 
153
+ def description
154
+ return "" if @issue.description.nil?
155
+ @issue.description
156
+ end
157
+
153
158
  def summary
154
159
  fields["summary"]
155
160
  end
@@ -175,9 +180,24 @@ module Lazylead
175
180
  end
176
181
 
177
182
  def fields
183
+ return {} if @issue.nil?
184
+ return {} unless @issue.respond_to? :fields
185
+ return {} if @issue.fields.nil?
186
+ return {} unless @issue.fields.respond_to? :[]
178
187
  @issue.fields
179
188
  end
180
189
 
190
+ def [](name)
191
+ return "" if fields[name].nil? || fields[name].blank?
192
+ fields[name]
193
+ end
194
+
195
+ def components
196
+ return [] unless @issue.respond_to? :components
197
+ return [] if @issue.components.nil?
198
+ @issue.components.map(&:name)
199
+ end
200
+
181
201
  def history
182
202
  return [] unless @issue.respond_to? :changelog
183
203
  return [] if @issue.changelog == nil? || @issue.changelog.empty?
@@ -206,6 +226,30 @@ module Lazylead
206
226
  def post(markdown)
207
227
  @issue.comments.build.save!(body: markdown)
208
228
  end
229
+
230
+ def remote_links
231
+ @issue.remotelink.all
232
+ end
233
+
234
+ def attachments
235
+ @issue.attachments
236
+ end
237
+
238
+ def add_label(label, *more)
239
+ lbl = labels
240
+ lbl = [] if lbl.nil?
241
+ lbl << label
242
+ lbl += more if more.size.positive?
243
+ save!("fields" => { "labels" => lbl.uniq })
244
+ end
245
+
246
+ def labels
247
+ fields["labels"]
248
+ end
249
+
250
+ def save!(opts)
251
+ @issue.save(opts)
252
+ end
209
253
  end
210
254
 
211
255
  # The jira issue comments
@@ -43,7 +43,7 @@ module Lazylead
43
43
  end
44
44
 
45
45
  def run(sys, postman, opts)
46
- require_rules
46
+ Dir[File.join(__dir__, "*.rb")].sort.each { |f| require f }
47
47
  rules = opts.slice("rules", ",")
48
48
  .map(&:constantize)
49
49
  .map(&:new)
@@ -53,12 +53,6 @@ module Lazylead
53
53
  .each(&:post)
54
54
  postman.send opts.merge(tickets: raised) unless raised.empty?
55
55
  end
56
-
57
- # Load all ticket accuracy rules for future verification
58
- def require_rules
59
- rules = File.dirname(__FILE__)
60
- $LOAD_PATH.unshift(rules) unless $LOAD_PATH.include?(rules)
61
- end
62
56
  end
63
57
  end
64
58
 
@@ -85,7 +79,9 @@ module Lazylead
85
79
 
86
80
  # Post the comment with score and accuracy to the ticket.
87
81
  def post
88
- @issue.post(comment) unless @opts.key? "silent"
82
+ return if @opts.key? "silent"
83
+ @issue.post comment
84
+ @issue.add_label "LL.accuracy", grade(@accuracy)
89
85
  end
90
86
 
91
87
  # The jira comment in markdown format
@@ -136,5 +132,14 @@ module Lazylead
136
132
  .sort_by { |e| e[0] }
137
133
  end
138
134
  end
135
+
136
+ # Calculate grade for accuracy
137
+ # For example,
138
+ # grade(7.5) => 0
139
+ # grade(12) => 10
140
+ # grade(25.5) => 20
141
+ def grade(value)
142
+ (value / 10).floor * 10
143
+ end
139
144
  end
140
145
  end
@@ -22,22 +22,18 @@
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 "../../email"
27
- require_relative "../../version"
28
- require_relative "../../postman"
29
25
  require_relative "requirement"
30
26
 
31
27
  module Lazylead
32
28
  # A requirement that Jira field "Affects Version/s" provided by the reporter.
33
- class RequirementAffectedBuild < Requirement
29
+ class AffectedBuild < Requirement
34
30
  def initialize(score = 0.5)
35
31
  super "Affected build", score, "Affects Version/s"
36
32
  end
37
33
 
38
34
  # @return true if an issue has non-empty "Affects Version/s" field
39
35
  def passed(issue)
40
- !issue.fields["versions"].nil? && !issue.fields["versions"].empty?
36
+ non_blank? issue, "versions"
41
37
  end
42
38
  end
43
39
  end
@@ -0,0 +1,44 @@
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 an attachment.
29
+ class Attachment < Lazylead::Requirement
30
+ def initialize(desc, score, field)
31
+ super(desc, score, field)
32
+ end
33
+
34
+ def passed(issue)
35
+ issue.attachments.any?(&method(:matching))
36
+ end
37
+
38
+ # Check a single attachment from ticket.
39
+ # Potential extension point for custom verification logic.
40
+ def matching(attachment)
41
+ !attachment.nil?
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,39 @@
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
+ # A requirement that Jira field "Environment" provided by the reporter.
29
+ class Environment < Requirement
30
+ def initialize(score = 0.5)
31
+ super "Environment details (URL, patches)", score, "Environment"
32
+ end
33
+
34
+ # @return true if an issue has non-empty "Environment" field
35
+ def passed(issue)
36
+ non_blank? issue, "environment"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
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 "attachment"
26
+
27
+ module Lazylead
28
+ # Check that ticket has log file(s) in attachment.
29
+ class Logs < Lazylead::Attachment
30
+ def initialize
31
+ super("Log files", 2, "Attachments")
32
+ end
33
+
34
+ # Ensure that ticket has a '*.log' file more '10KB'
35
+ def matching(attachment)
36
+ attachment.attrs["size"].to_i > 10_240 &&
37
+ File.extname(attachment.attrs["filename"]).downcase.start_with?(".log")
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
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 "attachment"
26
+
27
+ module Lazylead
28
+ # Check that ticket has video record(s) with reproducing results.
29
+ class Records < Lazylead::Attachment
30
+ def initialize(ext = [])
31
+ super("Recorded internal reproducing results", 5, "Attachments")
32
+ @ext = ext
33
+ return unless @ext.empty?
34
+ @ext = %w[.webm .mkv .flv .flv .vob .ogv .ogg .drc .gif .gifv .mng .avi
35
+ .mts .m2ts .ts .mov .qt .wmv .yuv .rm .rmvb .viv .asf .amv .mp4
36
+ .m4p .m4v .mpg .mp2 .mpeg .mpe .mpv .mpg .mpeg .m2v .m4v .svi
37
+ .3gp .3g2 .mxf .roq .nsv .flv .f4v .f4p .f4a .f4b .gif]
38
+ end
39
+
40
+ # Ensure that ticket has an attachment with video-file extension
41
+ def matching(attach)
42
+ @ext.any? { |e| e.eql? File.extname(attach.attrs["filename"]).downcase }
43
+ end
44
+ end
45
+ end
@@ -36,5 +36,14 @@ module Lazylead
36
36
  def passed(_)
37
37
  true
38
38
  end
39
+
40
+ def blank?(issue, field)
41
+ return false if issue.nil?
42
+ issue.fields[field].nil? || issue.fields[field].blank?
43
+ end
44
+
45
+ def non_blank?(issue, field)
46
+ !blank? issue, field
47
+ end
39
48
  end
40
49
  end
@@ -0,0 +1,50 @@
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 expected links to failed entities on dedicated
29
+ # servers.
30
+ class Servers < Lazylead::Requirement
31
+ #
32
+ # @param envs regexp expressions to match servers in description.
33
+ #
34
+ def initialize(score: 2, envs: [], desc: "Internal reproducing results")
35
+ super desc, score, "Description/Environment"
36
+ @envs = envs
37
+ end
38
+
39
+ def passed(issue)
40
+ return true if @envs.empty?
41
+ lines = issue["environment"].to_s + "\n" + issue.description
42
+ lines.split("\n")
43
+ .reject(&:blank?)
44
+ .map(&:strip)
45
+ .flat_map { |l| l.split(" ").map(&:strip) }
46
+ .select { |w| w.start_with?("http://", "https://") }
47
+ .any? { |u| @envs.any? { |e| u.match? e } }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,63 @@
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).select { |f| oracle?(f) || java?(f) }.empty?
38
+ end
39
+
40
+ # Detect all {noformat} frames in description field
41
+ def frames(description)
42
+ description.enum_for(:scan, /(?={noformat})/)
43
+ .map { Regexp.last_match.offset(0).first }
44
+ .each_slice(2).map do |f|
45
+ description[f.first, f.last - f.first + "{noformat}".size]
46
+ end
47
+ end
48
+
49
+ # @return true if frame has few lines with java stack frames
50
+ def java?(frame)
51
+ allowed = ["at ", "Caused by:"]
52
+ frame.split("\n")
53
+ .map(&:strip)
54
+ .count { |l| allowed.any? { |a| l.start_with? a } } > 3
55
+ end
56
+
57
+ # @return true if frame has Oracle error
58
+ # @see https://docs.oracle.com/pls/db92/db92.error_search
59
+ def oracle?(frame)
60
+ frame.match?(/\WORA-\d{5}:/)
61
+ end
62
+ end
63
+ end