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
@@ -27,17 +27,13 @@ require_relative "requirement"
27
27
  module Lazylead
28
28
  # Check that ticket has an attachment.
29
29
  class Attachment < Lazylead::Requirement
30
- def initialize(desc, score, field)
31
- super(desc, score, field)
32
- end
33
-
34
30
  def passed(issue)
35
- issue.attachments.any?(&method(:matching))
31
+ issue.attachments.any? { |a| matches?(a) }
36
32
  end
37
33
 
38
34
  # Check a single attachment from ticket.
39
35
  # Potential extension point for custom verification logic.
40
- def matching(attachment)
36
+ def matches?(attachment)
41
37
  !attachment.nil?
42
38
  end
43
39
  end
@@ -27,14 +27,18 @@ require_relative "attachment"
27
27
  module Lazylead
28
28
  # Check that ticket has log file(s) in attachment.
29
29
  class Logs < Lazylead::Attachment
30
- def initialize
30
+ def initialize(files = %w[log.zip logs.zip log.gz logs.gz log.tar.gz
31
+ logs.tar.gz log.7z logs.7z log.tar logs.tar])
31
32
  super("Log files", 2, "Attachments")
33
+ @files = files
32
34
  end
33
35
 
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")
36
+ # Ensure that ticket has a '*.log' file more '5KB'
37
+ def matches?(attachment)
38
+ name = attachment.attrs["filename"].downcase
39
+ return false unless attachment.attrs["size"].to_i > 5120
40
+ return true if File.extname(name).start_with? ".log", ".txt", ".out"
41
+ @files.any? { |l| name.end_with? l }
38
42
  end
39
43
  end
40
44
  end
@@ -0,0 +1,147 @@
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 "../../log"
26
+ require_relative "../../opts"
27
+
28
+ module Lazylead
29
+ module Task
30
+ #
31
+ # Ensure that ticket accuracy evaluation labels are set only by LL, not by
32
+ # some person.
33
+ #
34
+ # The task supports the following features:
35
+ # - fetch issues from remote ticketing system by query
36
+ # - check the history of labels modification
37
+ # - remove evaluation labels if they set not by LL
38
+ class OnlyLL
39
+ def initialize(log = Log.new)
40
+ @log = log
41
+ end
42
+
43
+ def run(sys, postman, opts)
44
+ found = sys.issues(opts["jql"],
45
+ opts.jira_defaults.merge(expand: "changelog"))
46
+ .map { |i| Labels.new(i, opts) }
47
+ .select(&:exists?)
48
+ .reject(&:valid?)
49
+ .each(&:remove)
50
+ postman.send opts.merge(tickets: found) unless found.empty?
51
+ end
52
+ end
53
+ end
54
+
55
+ # The ticket with grid labels
56
+ class Labels
57
+ attr_reader :issue
58
+
59
+ def initialize(issue, opts)
60
+ @issue = issue
61
+ @opts = opts
62
+ end
63
+
64
+ # Ensure that issue has evaluation labels for accuracy rules
65
+ def exists?
66
+ return false if @issue.labels.nil? || @issue.labels.empty?
67
+ return false unless @issue.labels.is_a? Array
68
+ grid.any? { |g| @issue.labels.any? { |l| g.eql? l } }
69
+ end
70
+
71
+ # Compare the score evaluated by LL and current ticket score.
72
+ # @return true if current score equal to LL evaluation
73
+ def valid?
74
+ score.eql?(@issue.labels.sort.find { |l| grid.any? { |g| l.eql? g } })
75
+ end
76
+
77
+ # Find expected ticket score evaluated by LL.
78
+ # If LL evaluated the same ticket several times (no matter why),
79
+ # then the last score would be returned.
80
+ def score
81
+ to_l(
82
+ @issue.history
83
+ .select { |h| h["author"]["key"].eql? @opts["author"] }
84
+ .reverse
85
+ .find { |h| to_l(h) }
86
+ ).fetch("toString", "").split.find { |l| grid.any? { |g| l.eql? g } }
87
+ end
88
+
89
+ # Find history record with labels changes.
90
+ def to_l(history)
91
+ return {} if history.nil? || history.empty?
92
+ history["items"].find { |f| f["field"].eql? "labels" }
93
+ end
94
+
95
+ # Detect the percentage grid for tickets, by default its 0%, 10%, 20%, etc.
96
+ def grid
97
+ @grid ||= begin
98
+ if @opts.key? "grid"
99
+ @opts.slice("grid", ",")
100
+ else
101
+ %w[0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%]
102
+ end
103
+ end
104
+ end
105
+
106
+ # Remove score labels from the ticket.
107
+ def remove
108
+ @issue.labels!(@issue.labels - grid)
109
+ end
110
+
111
+ # Detect the violators with their changes.
112
+ # .violators => ["Tom Hhhh set 40%", "Bob Mmmm set 50%"]
113
+ def violators
114
+ @issue.history
115
+ .reject { |h| h["author"]["key"].eql? @opts["author"] }
116
+ .select { |h| grid?(h) }
117
+ .group_by { |h| h["author"]["key"] }
118
+ .map do |a|
119
+ "#{a.last.first['author']['displayName']} set #{hacked(a.last)}"
120
+ end
121
+ end
122
+
123
+ # Ensure that history record has label change related to LL grid labels.
124
+ # @return true if LL grid labels added
125
+ def grid?(record)
126
+ diff(record).any? { |d| d.find { |l| grid.any? { |g| l.eql? g } } }
127
+ end
128
+
129
+ # Detect label diff in single history record from ticket's history.
130
+ def diff(record)
131
+ record["items"].select { |f| f["field"].eql? "labels" }
132
+ .reject { |f| f["toString"].nil? || f["toString"].blank? }
133
+ .map do |f|
134
+ from = []
135
+ from = f["fromString"].split unless f["fromString"].nil?
136
+ f["toString"].split - from
137
+ end
138
+ end
139
+
140
+ # Hacked score by violator in ticket's history.
141
+ def hacked(record)
142
+ diff(record.first)
143
+ .first
144
+ .find { |l| grid.any? { |g| l.eql? g } }
145
+ end
146
+ end
147
+ end
@@ -38,7 +38,7 @@ module Lazylead
38
38
  end
39
39
 
40
40
  # Ensure that ticket has an attachment with video-file extension
41
- def matching(attach)
41
+ def matches?(attach)
42
42
  @ext.any? { |e| e.eql? File.extname(attach.attrs["filename"]).downcase }
43
43
  end
44
44
  end
@@ -38,13 +38,22 @@ module Lazylead
38
38
 
39
39
  def passed(issue)
40
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 } }
41
+ "#{issue['environment']}\n#{issue.description}".split("\n")
42
+ .reject(&:blank?)
43
+ .map(&:strip)
44
+ .flat_map { |l| l.split.map(&:strip) }
45
+ .select { |u| url?(u) }
46
+ .any? { |u| match?(u) }
47
+ end
48
+
49
+ # Ensure that particular text contains web url
50
+ def url?(text)
51
+ text.include?("http://") || text.include?("https://")
52
+ end
53
+
54
+ # Ensure that particular url matches expected servers urls
55
+ def match?(url)
56
+ @envs.any? { |e| url.match? e }
48
57
  end
49
58
  end
50
59
  end
@@ -34,24 +34,64 @@ module Lazylead
34
34
 
35
35
  def passed(issue)
36
36
  return false if issue.description.nil?
37
- !frames(issue.description).select { |f| oracle?(f) || java?(f) }.empty?
37
+ frames(issue.description).any? { |f| oracle?(f) || java?(f) }
38
38
  end
39
39
 
40
- # Detect all {noformat} frames in description field
40
+ # Detect all {noformat}, {code} frames in ticket description
41
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]
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
46
84
  end
85
+ snippets.select { |s| s.size == 2 }
47
86
  end
48
87
 
49
88
  # @return true if frame has few lines with java stack frames
50
89
  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
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
55
95
  end
56
96
 
57
97
  # @return true if frame has Oracle error
@@ -38,10 +38,10 @@ 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.strip.downcase)
42
- detect_tc(line, i)
43
- detect_ar(line, i)
44
- detect_er(line, i)
41
+ line = escape l.downcase.gsub(/(\s+|\*)/, "")
42
+ detect_tc line, i
43
+ detect_ar line, i
44
+ detect_er line, i
45
45
  break if with_tc_ar_er?
46
46
  end
47
47
  with_tc_ar_er?
@@ -65,21 +65,28 @@ module Lazylead
65
65
  # Detect index of line with test case
66
66
  def detect_tc(line, index)
67
67
  return unless @tc.negative?
68
- @tc = index if %w[testcase: tc: teststeps: teststeps steps:].any? do |e|
69
- e.eql? line
70
- end
68
+ @tc = index if eql? line,
69
+ %w[testcase: tc: teststeps: teststeps steps: tcsteps:]
71
70
  end
72
71
 
73
72
  # Detect index of line with actual result
74
73
  def detect_ar(line, index)
75
74
  return unless @ar.negative? && index > @tc
76
- @ar = index if %w[ar: actualresult: ar=].any? { |e| line.start_with? e }
75
+ @ar = index if starts? line, %w[ar: actualresult: ar= [ar]]
77
76
  end
78
77
 
79
78
  # Detect index of line with expected result
80
79
  def detect_er(line, index)
81
80
  return unless @er.negative? && index > @tc
82
- @er = index if %w[er: expectedresult: er=].any? { |e| line.start_with? e }
81
+ @er = index if starts? line, %w[er: expectedresult: er= [er]]
82
+ end
83
+
84
+ def starts?(line, text)
85
+ text.any? { |t| line.start_with? t }
86
+ end
87
+
88
+ def eql?(line, text)
89
+ text.any? { |t| t.eql? line }
83
90
  end
84
91
  end
85
92
  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