lazylead 0.6.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +7 -2
- data/.docker/Dockerfile +17 -6
- data/.docs/duedate_expired.md +1 -1
- data/.rubocop.yml +119 -3
- data/.simplecov +1 -1
- data/Gemfile +1 -1
- data/Guardfile +2 -2
- data/Rakefile +7 -4
- data/bin/lazylead +4 -2
- data/lazylead.gemspec +33 -29
- data/lib/lazylead.rb +2 -2
- data/lib/lazylead/allocated.rb +1 -1
- data/lib/lazylead/cc.rb +22 -21
- data/lib/lazylead/cli/app.rb +3 -3
- data/lib/lazylead/confluence.rb +10 -3
- data/lib/lazylead/email.rb +1 -21
- data/lib/lazylead/exchange.rb +17 -29
- data/lib/lazylead/home.rb +1 -1
- data/lib/lazylead/log.rb +1 -1
- data/lib/lazylead/model.rb +25 -17
- data/lib/lazylead/opts.rb +68 -3
- data/lib/lazylead/postman.rb +14 -19
- data/lib/lazylead/requires.rb +38 -0
- data/lib/lazylead/salt.rb +2 -1
- data/lib/lazylead/schedule.rb +1 -1
- data/lib/lazylead/smtp.rb +1 -1
- data/lib/lazylead/system/empty.rb +1 -1
- data/lib/lazylead/system/fake.rb +1 -1
- data/lib/lazylead/system/jira.rb +28 -20
- data/lib/lazylead/system/synced.rb +1 -1
- data/lib/lazylead/task/accuracy/accuracy.rb +23 -30
- data/lib/lazylead/task/accuracy/affected_build.rb +1 -1
- data/lib/lazylead/task/accuracy/attachment.rb +3 -7
- data/lib/lazylead/task/accuracy/environment.rb +1 -1
- data/lib/lazylead/task/accuracy/logs.rb +10 -5
- data/lib/lazylead/task/accuracy/onlyll.rb +147 -0
- data/lib/lazylead/task/accuracy/records.rb +2 -2
- data/lib/lazylead/task/accuracy/requirement.rb +1 -1
- data/lib/lazylead/task/accuracy/servers.rb +17 -8
- data/lib/lazylead/task/accuracy/stacktrace.rb +2 -2
- data/lib/lazylead/task/accuracy/testcase.rb +3 -3
- data/lib/lazylead/task/accuracy/wiki.rb +1 -1
- data/lib/lazylead/task/{alert.rb → alert/alert.rb} +6 -6
- data/lib/lazylead/task/alert/alertif.rb +75 -0
- data/lib/lazylead/task/alert/changed_to.rb +58 -0
- data/lib/lazylead/task/assignment.rb +1 -1
- data/lib/lazylead/task/confluence_ref.rb +1 -1
- data/lib/lazylead/task/echo.rb +1 -1
- data/lib/lazylead/task/fix_version.rb +5 -3
- data/lib/lazylead/task/loading.rb +94 -0
- data/lib/lazylead/task/missing_comment.rb +1 -1
- data/lib/lazylead/task/propagate_down.rb +4 -4
- data/lib/lazylead/task/savepoint.rb +1 -1
- data/lib/lazylead/task/svn/diff.rb +6 -14
- data/lib/lazylead/task/svn/grep.rb +41 -13
- data/lib/lazylead/task/svn/touch.rb +3 -5
- data/lib/lazylead/version.rb +2 -2
- data/lib/messages/accuracy.erb +1 -1
- data/lib/messages/alertif.erb +134 -0
- data/lib/messages/created_recently.erb +110 -0
- data/lib/messages/illegal_fixversion_change.erb +8 -2
- data/lib/messages/loading.erb +117 -0
- data/lib/messages/only_ll.erb +107 -0
- data/lib/messages/svn_diff_attachment.erb +18 -8
- data/lib/messages/svn_grep.erb +1 -1
- data/readme.md +3 -3
- data/test/lazylead/allocated_test.rb +1 -1
- data/test/lazylead/cc_test.rb +2 -1
- data/test/lazylead/cli/app_test.rb +2 -2
- data/test/lazylead/confluence_test.rb +1 -1
- data/test/lazylead/exchange_test.rb +1 -1
- data/test/lazylead/model_test.rb +11 -1
- data/test/lazylead/opts_test.rb +48 -1
- data/test/lazylead/postman_test.rb +9 -6
- data/test/lazylead/salt_test.rb +1 -1
- data/test/lazylead/smoke_test.rb +14 -1
- data/test/lazylead/smtp_test.rb +2 -5
- data/test/lazylead/system/jira_test.rb +10 -1
- data/test/lazylead/task/accuracy/accuracy_test.rb +1 -1
- data/test/lazylead/task/accuracy/affected_build_test.rb +1 -1
- data/test/lazylead/task/accuracy/attachment_test.rb +2 -2
- data/test/lazylead/task/accuracy/environment_test.rb +1 -1
- data/test/lazylead/task/accuracy/logs_test.rb +13 -1
- data/test/lazylead/task/accuracy/onlyll_test.rb +138 -0
- data/test/lazylead/task/accuracy/records_test.rb +1 -1
- data/test/lazylead/task/accuracy/score_test.rb +2 -2
- data/test/lazylead/task/accuracy/servers_test.rb +3 -3
- data/test/lazylead/task/accuracy/stacktrace_test.rb +1 -1
- data/test/lazylead/task/accuracy/testcase_test.rb +28 -1
- data/test/lazylead/task/accuracy/wiki_test.rb +1 -1
- data/test/lazylead/task/alert/alertif_test.rb +54 -0
- data/test/lazylead/task/{assignee_alert_test.rb → alert/assignee_alert_test.rb} +10 -10
- data/test/lazylead/task/alert/changed_to_test.rb +42 -0
- data/test/lazylead/task/assignment_test.rb +1 -1
- data/test/lazylead/task/confluence_ref_test.rb +1 -1
- data/test/lazylead/task/created_recently_test.rb +53 -0
- data/test/lazylead/task/duedate_test.rb +5 -12
- data/test/lazylead/task/echo_test.rb +1 -1
- data/test/lazylead/task/fix_version_test.rb +2 -1
- data/test/lazylead/task/loading_test.rb +54 -0
- data/test/lazylead/task/missing_comment_test.rb +1 -1
- data/test/lazylead/task/propagate_down_test.rb +5 -4
- data/test/lazylead/task/savepoint_test.rb +10 -7
- data/test/lazylead/task/svn/diff_test.rb +1 -1
- data/test/lazylead/task/svn/grep_test.rb +44 -2
- data/test/lazylead/task/svn/touch_test.rb +1 -1
- data/test/lazylead/version_test.rb +1 -1
- data/test/sqlite_test.rb +1 -1
- data/test/test.rb +8 -9
- data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -1
- data/upgrades/sqlite/999.testdata.sql +3 -2
- metadata +133 -58
data/lib/lazylead/salt.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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"),
|
@@ -39,6 +39,7 @@ module Lazylead
|
|
39
39
|
#
|
40
40
|
class Salt
|
41
41
|
attr_reader :id
|
42
|
+
|
42
43
|
#
|
43
44
|
# Each salt should be defined as a environment variable with id, like
|
44
45
|
# salt1=E1F53135E559C253
|
data/lib/lazylead/schedule.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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"),
|
data/lib/lazylead/smtp.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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-
|
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"),
|
data/lib/lazylead/system/fake.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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"),
|
data/lib/lazylead/system/jira.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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"),
|
@@ -30,6 +30,10 @@ require_relative "../opts"
|
|
30
30
|
module Lazylead
|
31
31
|
# Jira system for manipulation with issues.
|
32
32
|
#
|
33
|
+
# Jira official documentation:
|
34
|
+
# - https://docs.atlassian.com/jira-software/REST/7.3.1/#agile/1.0/issue-getIssue
|
35
|
+
# - https://developer.atlassian.com/server/jira/platform/rest-apis/
|
36
|
+
#
|
33
37
|
# Author:: Yurii Dubinka (yurii.dubinka@gmail.com)
|
34
38
|
# Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
|
35
39
|
# License:: MIT
|
@@ -82,22 +86,7 @@ module Lazylead
|
|
82
86
|
@opts[:auth_type] = :basic if @opts[:auth_type].nil?
|
83
87
|
@opts["username"] = @salt.decrypt(@opts["username"]) if @salt.specified?
|
84
88
|
@opts["password"] = @salt.decrypt(@opts["password"]) if @salt.specified?
|
85
|
-
|
86
|
-
cp("username", :username)
|
87
|
-
cp("password", :password)
|
88
|
-
cp("context_path", :context_path)
|
89
|
-
@client = JIRA::Client.new(@opts)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Copy the required/mandatory parameter(s) for Jira client which can't
|
93
|
-
# be specified/defined at database level.
|
94
|
-
#
|
95
|
-
# @todo #/DEV Jira.cp - find a way how to avoid this method.
|
96
|
-
# Potentially, hash with indifferent access might be used.
|
97
|
-
# http://jocellyn.cz/2014/05/03/hash-with-indifferent-access.html
|
98
|
-
# key.kind_of?(Symbol) ? key.to_s : key
|
99
|
-
def cp(act, exp)
|
100
|
-
@opts[exp] = @opts[act] if @opts.key? act
|
89
|
+
@client = JIRA::Client.new(@opts.symbolize_keys)
|
101
90
|
end
|
102
91
|
end
|
103
92
|
|
@@ -177,7 +166,7 @@ module Lazylead
|
|
177
166
|
end
|
178
167
|
|
179
168
|
def url
|
180
|
-
@issue.attrs[
|
169
|
+
"#{@issue.attrs['self'].split('/rest/api/').first}/browse/#{key}"
|
181
170
|
end
|
182
171
|
|
183
172
|
def duedate
|
@@ -257,13 +246,20 @@ module Lazylead
|
|
257
246
|
lbl = [] if lbl.nil?
|
258
247
|
lbl << label
|
259
248
|
lbl += more if more.size.positive?
|
260
|
-
|
249
|
+
labels! lbl
|
261
250
|
end
|
262
251
|
|
252
|
+
# Get the labels for a particular issue
|
263
253
|
def labels
|
264
254
|
fields["labels"]
|
265
255
|
end
|
266
256
|
|
257
|
+
# Update the labels for a particular issue
|
258
|
+
def labels!(lbl)
|
259
|
+
return if lbl.nil? || lbl.empty?
|
260
|
+
save!("fields" => { "labels" => lbl.uniq })
|
261
|
+
end
|
262
|
+
|
267
263
|
def save!(opts)
|
268
264
|
@issue.save(opts)
|
269
265
|
end
|
@@ -306,7 +302,19 @@ module Lazylead
|
|
306
302
|
|
307
303
|
# Check that comment has expected text
|
308
304
|
def include?(text)
|
309
|
-
|
305
|
+
to_s.include? text
|
306
|
+
end
|
307
|
+
|
308
|
+
def to_s
|
309
|
+
@comment.attrs["body"]
|
310
|
+
end
|
311
|
+
|
312
|
+
def lines
|
313
|
+
to_s.split("\n").reject(&:blank?)
|
314
|
+
end
|
315
|
+
|
316
|
+
def author
|
317
|
+
@comment.attrs["author"]["displayName"]
|
310
318
|
end
|
311
319
|
end
|
312
320
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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-
|
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"),
|
@@ -27,6 +27,7 @@ require_relative "../../opts"
|
|
27
27
|
require_relative "../../email"
|
28
28
|
require_relative "../../version"
|
29
29
|
require_relative "../../postman"
|
30
|
+
require_relative "../../requires"
|
30
31
|
|
31
32
|
module Lazylead
|
32
33
|
module Task
|
@@ -43,15 +44,14 @@ module Lazylead
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def run(sys, postman, opts)
|
46
|
-
|
47
|
-
rules = opts.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
postman.send opts.merge(tickets: raised) unless raised.empty?
|
47
|
+
Requires.new(__dir__).load
|
48
|
+
opts[:rules] = opts.construct("rules")
|
49
|
+
opts[:total] = opts[:rules].sum(&:score)
|
50
|
+
opts[:tickets] = sys.issues(opts["jql"], opts.jira_defaults)
|
51
|
+
.map { |i| Score.new(i, opts) }
|
52
|
+
.each(&:evaluate)
|
53
|
+
.each(&:post)
|
54
|
+
postman.send(opts) unless opts[:tickets].empty?
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -60,28 +60,23 @@ module Lazylead
|
|
60
60
|
class Score
|
61
61
|
attr_reader :issue, :total, :score, :accuracy
|
62
62
|
|
63
|
-
def initialize(issue, opts
|
63
|
+
def initialize(issue, opts)
|
64
64
|
@issue = issue
|
65
|
-
@link = opts["docs"]
|
66
65
|
@opts = opts
|
67
|
-
@rules = rules
|
68
66
|
end
|
69
67
|
|
70
68
|
# Estimate the ticket score and accuracy.
|
71
69
|
# Accuracy is a percentage between current score and maximum possible value.
|
72
70
|
def evaluate(digits = 2)
|
73
|
-
@
|
74
|
-
@
|
75
|
-
.map(&:score)
|
76
|
-
.sum
|
77
|
-
@accuracy = (score / @total * 100).round(digits)
|
71
|
+
@score = @opts[:rules].select { |r| r.passed(@issue) }.sum(&:score)
|
72
|
+
@accuracy = (score / @opts[:total] * 100).round(digits)
|
78
73
|
end
|
79
74
|
|
80
75
|
# Post the comment with score and accuracy to the ticket.
|
81
76
|
def post
|
82
77
|
return if @opts.key? "silent"
|
83
78
|
@issue.post comment
|
84
|
-
@issue.add_label "LL.accuracy", "#{grade(@accuracy)}%"
|
79
|
+
@issue.add_label "LL.accuracy", "#{grade(@accuracy)}%", "#{@accuracy}%"
|
85
80
|
end
|
86
81
|
|
87
82
|
# The jira comment in markdown format
|
@@ -105,18 +100,16 @@ module Lazylead
|
|
105
100
|
|
106
101
|
# Link to ticket formatting rules
|
107
102
|
def docs_link
|
108
|
-
if @
|
103
|
+
if @opts["docs"].nil? || @opts["docs"].blank?
|
109
104
|
""
|
110
105
|
else
|
111
106
|
"The requirements/examples of ticket formatting rules you may find " \
|
112
|
-
"[here|#{@
|
107
|
+
"[here|#{@opts['docs']}]."
|
113
108
|
end
|
114
109
|
end
|
115
110
|
|
116
111
|
def color
|
117
|
-
if colors.nil? || !defined?(@score) || !@score.is_a?(Numeric)
|
118
|
-
return "#061306"
|
119
|
-
end
|
112
|
+
return "#061306" if colors.nil? || !defined?(@score) || !@score.is_a?(Numeric)
|
120
113
|
colors.reverse_each do |color|
|
121
114
|
return color.last if @accuracy >= color.first
|
122
115
|
end
|
@@ -125,12 +118,12 @@ module Lazylead
|
|
125
118
|
|
126
119
|
def colors
|
127
120
|
@colors ||= begin
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
121
|
+
JSON.parse(@opts["colors"])
|
122
|
+
.to_h
|
123
|
+
.to_a
|
124
|
+
.each { |e| e[0] = e[0].to_i }
|
125
|
+
.sort_by { |e| e[0] }
|
126
|
+
end
|
134
127
|
end
|
135
128
|
|
136
129
|
# Calculate grade for accuracy
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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-
|
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"),
|
@@ -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?(
|
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
|
36
|
+
def matches?(attachment)
|
41
37
|
!attachment.nil?
|
42
38
|
end
|
43
39
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
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-
|
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"),
|
@@ -27,16 +27,21 @@ 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
36
|
# Ensure that ticket has a '*.log' file more '5KB'
|
35
|
-
def
|
37
|
+
def matches?(attachment)
|
36
38
|
name = attachment.attrs["filename"].downcase
|
37
39
|
return false unless attachment.attrs["size"].to_i > 5120
|
38
|
-
return true if File.extname(name).start_with?
|
39
|
-
|
40
|
+
return true if File.extname(name).start_with? ".log", ".txt", ".out"
|
41
|
+
return true if @files.any? { |l| name.end_with? l }
|
42
|
+
%w[.zip .7z .gz tar.gz].any? do |l|
|
43
|
+
name.end_with?(l) && name.split(/(?:[^a-zA-Z0-9](?<![^\x00-\x7F]))+/).include?("logs")
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
@@ -0,0 +1,147 @@
|
|
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
|
+
|
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
|