lazylead 0.4.3 → 0.6.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.
- checksums.yaml +4 -4
- data/.docs/accuracy.md +2 -2
- data/.docs/duedate_expired.md +3 -3
- data/.docs/propagate_down.md +3 -3
- data/.gitattributes +1 -0
- data/Rakefile +6 -3
- data/bin/lazylead +7 -5
- data/lazylead.gemspec +4 -3
- data/lib/lazylead/cli/app.rb +11 -3
- data/lib/lazylead/exchange.rb +15 -9
- data/lib/lazylead/log.rb +2 -1
- data/lib/lazylead/model.rb +42 -1
- data/lib/lazylead/opts.rb +13 -0
- data/lib/lazylead/postman.rb +13 -7
- data/lib/lazylead/schedule.rb +16 -15
- data/lib/lazylead/smtp.rb +3 -1
- data/lib/lazylead/system/jira.rb +65 -4
- data/lib/lazylead/task/accuracy/accuracy.rb +13 -8
- data/lib/lazylead/task/accuracy/affected_build.rb +2 -6
- data/lib/lazylead/task/accuracy/attachment.rb +44 -0
- data/lib/lazylead/task/accuracy/environment.rb +39 -0
- data/lib/lazylead/task/accuracy/logs.rb +42 -0
- data/lib/lazylead/task/accuracy/records.rb +45 -0
- data/lib/lazylead/task/accuracy/requirement.rb +9 -0
- data/lib/lazylead/task/accuracy/servers.rb +50 -0
- data/lib/lazylead/task/accuracy/stacktrace.rb +103 -0
- data/lib/lazylead/task/accuracy/testcase.rb +92 -0
- data/lib/lazylead/task/accuracy/wiki.rb +41 -0
- data/lib/lazylead/task/assignment.rb +96 -0
- data/lib/lazylead/task/echo.rb +18 -0
- data/lib/lazylead/task/fix_version.rb +13 -2
- data/lib/lazylead/task/svn/diff.rb +85 -0
- data/lib/lazylead/task/svn/grep.rb +111 -0
- data/lib/lazylead/task/svn/touch.rb +101 -0
- data/lib/lazylead/version.rb +1 -1
- data/lib/messages/illegal_assignee_change.erb +123 -0
- data/lib/messages/illegal_fixversion_change.erb +2 -0
- data/lib/messages/svn_diff.erb +110 -0
- data/lib/messages/svn_diff_attachment.erb +117 -0
- data/lib/messages/svn_grep.erb +114 -0
- data/license.txt +1 -1
- data/readme.md +5 -5
- data/test/lazylead/cli/app_test.rb +11 -11
- data/test/lazylead/model_test.rb +10 -0
- data/test/lazylead/system/jira_test.rb +41 -4
- data/test/lazylead/task/accuracy/accuracy_test.rb +1 -1
- data/test/lazylead/task/accuracy/affected_build_test.rb +2 -2
- data/test/lazylead/task/accuracy/attachment_test.rb +50 -0
- data/test/lazylead/task/accuracy/environment_test.rb +42 -0
- data/test/lazylead/task/accuracy/logs_test.rb +138 -0
- data/test/lazylead/task/accuracy/records_test.rb +60 -0
- data/test/lazylead/task/accuracy/score_test.rb +46 -0
- data/test/lazylead/task/accuracy/servers_test.rb +66 -0
- data/test/lazylead/task/accuracy/stacktrace_test.rb +340 -0
- data/test/lazylead/task/accuracy/testcase_test.rb +254 -0
- data/test/lazylead/task/accuracy/wiki_test.rb +40 -0
- data/test/lazylead/task/assignment_test.rb +53 -0
- data/test/lazylead/task/svn/diff_test.rb +97 -0
- data/test/lazylead/task/svn/grep_test.rb +61 -0
- data/test/lazylead/task/{touch_test.rb → svn/touch_test.rb} +8 -8
- data/test/test.rb +16 -0
- data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -5
- data/upgrades/sqlite/999.testdata.sql +13 -17
- metadata +72 -20
- data/.travis.yml +0 -16
- data/lib/lazylead/task/touch.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 847a338ce12f9cd01529f1e6a66d810e68cde504e2a0873ecb41b869adcda7cc
|
4
|
+
data.tar.gz: 8ca65bb46faced2b89f07f1b65002b2890ecf2c78d4d53e74d017a712133d0f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f527721696b9f7215efc7628ea39c6cbf18c3145908d715ef5e698de57fcb5b6b28af8d0fe167b54b5418c9f15915071d0ff7ff2c7df3315f107f0d49c4c95d9
|
7
|
+
data.tar.gz: 1a71de8819ce9aa81fd0e11c4d0248e8b44d846d17f71adb0be18c6a74c9fe58d2ad257fd639f263c29546898cea0725dd6850dbdb417de6e03f541009fbebe0
|
data/.docs/accuracy.md
CHANGED
@@ -66,7 +66,7 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
|
66
66
|
values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
|
67
67
|
insert into tasks (name, cron, enabled, id, system, team_id, action, properties)
|
68
68
|
values ('Post ticket score and accuracy to the tickets',
|
69
|
-
'0 8 * * 1-5',
|
69
|
+
'cron:0 8 * * 1-5',
|
70
70
|
'true',
|
71
71
|
1, 1, 1,
|
72
72
|
'Lazylead::Task::Accuracy',
|
@@ -82,7 +82,7 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
|
82
82
|
}
|
83
83
|
');
|
84
84
|
```
|
85
|
-
Yes, for task scheduling we are using [cron](https://crontab.guru).
|
85
|
+
Yes, for task scheduling we are using [cron](https://crontab.guru) here, but you may use other scheduling types from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
86
86
|
|
87
87
|
4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
|
88
88
|
```bash
|
data/.docs/duedate_expired.md
CHANGED
@@ -68,16 +68,16 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
|
68
68
|
values (1, 'Dream team with lazylead', '{}');
|
69
69
|
insert into systems(id, properties)
|
70
70
|
values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
|
71
|
-
insert into tasks (name,
|
71
|
+
insert into tasks (name, schedule, enabled, id, system, team_id, action, properties)
|
72
72
|
values ('Expired due dates',
|
73
|
-
'0 8 * * 1-5',
|
73
|
+
'cron:0 8 * * 1-5',
|
74
74
|
'true',
|
75
75
|
1, 1, 1,
|
76
76
|
'Lazylead::Task::AssigneeAlert',
|
77
77
|
'{"sql":"filter=222", "cc":"<youremail.com>", "subject":"[LL] Expired due dates", "template":"lib/messages/due_date_expired.erb", "postman":"Lazylead::Exchange"}');
|
78
78
|
|
79
79
|
```
|
80
|
-
Yes, for task scheduling we are using [cron](https://crontab.guru).
|
80
|
+
Yes, for task scheduling we are using [cron](https://crontab.guru) here, but you may use other scheduling types from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
81
81
|
|
82
82
|
4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
|
83
83
|
```bash
|
data/.docs/propagate_down.md
CHANGED
@@ -58,16 +58,16 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
|
58
58
|
values (1, 'Dream team with lazylead', '{}');
|
59
59
|
insert into systems(id, properties)
|
60
60
|
values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
|
61
|
-
insert into tasks (name,
|
61
|
+
insert into tasks (name, schedule, enabled, id, system, team_id, action, properties)
|
62
62
|
values ('Propagate customfield_1 (External ID) to sub-tasks',
|
63
|
-
'0 8 * * 1-5',
|
63
|
+
'cron:0 8 * * 1-5',
|
64
64
|
'true',
|
65
65
|
1, 1, 1,
|
66
66
|
'Lazylead::Task::PropagateDown',
|
67
67
|
'{"jql":"filter=222", "propagate":"customfield_1"}');
|
68
68
|
|
69
69
|
```
|
70
|
-
Yes, for task scheduling we are using [cron](https://crontab.guru).
|
70
|
+
Yes, for task scheduling we are using [cron](https://crontab.guru) here, but you may use other scheduling types from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
71
71
|
|
72
72
|
4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
|
73
73
|
```bash
|
data/.gitattributes
CHANGED
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ require "rubygems"
|
|
26
26
|
require "rake"
|
27
27
|
require "date"
|
28
28
|
require "rdoc"
|
29
|
-
require "
|
29
|
+
require "colorize"
|
30
30
|
require "rake/clean"
|
31
31
|
|
32
32
|
# @todo #/DEV Investigate the possibility of using migrations from active_record
|
@@ -112,9 +112,10 @@ task :sqlint do
|
|
112
112
|
total += violations.count { |lint| lint.type == :error }
|
113
113
|
end
|
114
114
|
if total.positive?
|
115
|
-
abort "#{
|
115
|
+
abort "#{total.colorize(:red)} SQL violations found."
|
116
116
|
else
|
117
|
-
puts "#{src.size} files inspected, #{
|
117
|
+
puts "#{src.size} files inspected, #{'no offenses'.colorize(:green)} " \
|
118
|
+
"detected"
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
@@ -127,4 +128,6 @@ task :docker do
|
|
127
128
|
system "docker-compose -f .docker/docker-compose.yml build "\
|
128
129
|
" --build-arg release_tags='latest 1.0'"\
|
129
130
|
" --build-arg version=1.0"
|
131
|
+
system "docker-compose -f .docker/docker-compose.yml rm --force -s lazylead"
|
132
|
+
system "docker-compose -f .docker/docker-compose.yml up"
|
130
133
|
end
|
data/bin/lazylead
CHANGED
@@ -29,7 +29,7 @@ STDOUT.sync = true
|
|
29
29
|
|
30
30
|
require "slop"
|
31
31
|
require "sqlite3"
|
32
|
-
require "
|
32
|
+
require "colorize"
|
33
33
|
require "logging"
|
34
34
|
require "backtrace"
|
35
35
|
require "memory_profiler"
|
@@ -77,12 +77,13 @@ Available options:"
|
|
77
77
|
exit
|
78
78
|
end
|
79
79
|
end
|
80
|
-
log.debug
|
81
|
-
log.debug
|
80
|
+
log.debug "Version: #{Lazylead::VERSION.colorize(:green)}"
|
81
|
+
log.debug "Memory footprint at start is " \
|
82
|
+
"#{Lazylead::Allocated.new.to_s.colorize(:light_blue)}."
|
82
83
|
cmd = lambda do
|
83
84
|
Lazylead::CLI::App.new(
|
84
85
|
log,
|
85
|
-
Lazylead::Schedule.new(log),
|
86
|
+
Lazylead::Schedule.new(log: log),
|
86
87
|
Lazylead::Smtp.new(
|
87
88
|
log, Lazylead::Salt.new("smtp_salt"),
|
88
89
|
smtp_host: ENV["smtp_host"],
|
@@ -103,5 +104,6 @@ if opts["memory-dump"]
|
|
103
104
|
else
|
104
105
|
code = cmd.call
|
105
106
|
end
|
106
|
-
log.debug
|
107
|
+
log.debug "Memory footprint at the end is " \
|
108
|
+
"#{Lazylead::Allocated.new.to_s.colorize(:light_blue)}."
|
107
109
|
exit(code) unless code.zero?
|
data/lazylead.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.rubygems_version = "2.2"
|
33
33
|
s.required_ruby_version = ">=2.6.5"
|
34
34
|
s.name = "lazylead"
|
35
|
-
s.version = "0.
|
35
|
+
s.version = "0.6.1"
|
36
36
|
s.license = "MIT"
|
37
37
|
s.summary = "Eliminate the annoying work within bug-trackers."
|
38
38
|
s.description = "Ticketing systems (Github, Jira, etc.) are strongly
|
@@ -45,7 +45,7 @@ tasks instead of solving technical problems."
|
|
45
45
|
s.authors = ["Yurii Dubinka"]
|
46
46
|
s.email = "yurii.dubinka@gmail.com"
|
47
47
|
s.homepage = "http://github.com/dgroup/lazylead"
|
48
|
-
s.post_install_message = "Thanks for installing Lazylead v0.
|
48
|
+
s.post_install_message = "Thanks for installing Lazylead v0.6.1!
|
49
49
|
Read our blog posts: https://lazylead.org
|
50
50
|
Stay in touch with the community in Telegram: https://t.me/lazylead
|
51
51
|
Follow us on Twitter: https://twitter.com/lazylead
|
@@ -57,6 +57,7 @@ tasks instead of solving technical problems."
|
|
57
57
|
s.extra_rdoc_files = %w[readme.md license.txt]
|
58
58
|
s.add_runtime_dependency "activerecord", "6.0.3"
|
59
59
|
s.add_runtime_dependency "backtrace", "0.3"
|
60
|
+
s.add_runtime_dependency "colorize", "0.8.1"
|
60
61
|
s.add_runtime_dependency "faraday", "1.0.1"
|
61
62
|
s.add_runtime_dependency "get_process_mem", "0.2.5"
|
62
63
|
s.add_runtime_dependency "jira-ruby", "1.7.1"
|
@@ -65,11 +66,11 @@ tasks instead of solving technical problems."
|
|
65
66
|
s.add_runtime_dependency "mail", "2.7.1"
|
66
67
|
s.add_runtime_dependency "memory_profiler", "0.9.13"
|
67
68
|
s.add_runtime_dependency "openssl", "2.1.2"
|
68
|
-
s.add_runtime_dependency "rainbow", "3.0.0"
|
69
69
|
s.add_runtime_dependency "require_all", "3.0.0"
|
70
70
|
s.add_runtime_dependency "rufus-scheduler", "3.6.0"
|
71
71
|
s.add_runtime_dependency "slop", "4.4"
|
72
72
|
s.add_runtime_dependency "sqlite3", "1.4.2"
|
73
|
+
s.add_runtime_dependency "tempfile", "0.1.0"
|
73
74
|
s.add_runtime_dependency "tilt", "2.0.10"
|
74
75
|
s.add_runtime_dependency "tzinfo", "1.1"
|
75
76
|
s.add_runtime_dependency "tzinfo-data", "1.2019.3"
|
data/lib/lazylead/cli/app.rb
CHANGED
@@ -22,6 +22,7 @@
|
|
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 "colorize"
|
25
26
|
require "vcs4sql/sqlite/migration"
|
26
27
|
require_relative "../smtp"
|
27
28
|
require_relative "../schedule"
|
@@ -58,9 +59,11 @@ module Lazylead
|
|
58
59
|
def apply_vcs_migration(opts)
|
59
60
|
@db = File.expand_path(opts[:home]) + "/" + opts[:sqlite]
|
60
61
|
vcs = File.expand_path(opts[:home]) + "/" + opts[:vcs4sql]
|
61
|
-
@log.debug "Database: '#{@db}',
|
62
|
+
@log.debug "Database: '#{@db.colorize(:light_blue)}', "\
|
63
|
+
"sql migration dir: '#{vcs.colorize(:light_blue)}'"
|
62
64
|
Vcs4sql::Sqlite::Migration.new(@db).upgrade vcs, opts[:testdata]
|
63
|
-
@log.debug "Migration applied to #{@db} from
|
65
|
+
@log.debug "Migration applied to '#{@db.colorize(:light_blue)}' from " \
|
66
|
+
"'#{vcs.colorize(:light_blue)}'"
|
64
67
|
end
|
65
68
|
|
66
69
|
def enable_active_record(opts)
|
@@ -78,7 +81,12 @@ module Lazylead
|
|
78
81
|
@log.warn "ll-001: No tasks found."
|
79
82
|
else
|
80
83
|
todo.find_each do |task|
|
81
|
-
|
84
|
+
if task.to_h?
|
85
|
+
@schedule.register task
|
86
|
+
else
|
87
|
+
@log.warn "ll-011: Scheduling skipped due to configuration " \
|
88
|
+
"mistake in #{task}"
|
89
|
+
end
|
82
90
|
end
|
83
91
|
@schedule.join
|
84
92
|
end
|
data/lib/lazylead/exchange.rb
CHANGED
@@ -54,19 +54,25 @@ module Lazylead
|
|
54
54
|
def send(opts)
|
55
55
|
to = opts["to"] || opts[:to]
|
56
56
|
to = [to] unless to.is_a? Array
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
to_recipients: to
|
63
|
-
}
|
57
|
+
if to.reject { |e| e.nil? || e.blank? }.empty?
|
58
|
+
@log.warn "Email can't be sent to '#{to}, more: '#{opts}'"
|
59
|
+
return
|
60
|
+
end
|
61
|
+
msg = make_msg(to, opts)
|
64
62
|
msg.update(cc_recipients: opts["cc"]) if opts.key? "cc"
|
65
63
|
add_attachments(msg, opts)
|
66
64
|
cli.send_message msg
|
67
65
|
close_attachments msg
|
68
|
-
@log.debug "
|
69
|
-
|
66
|
+
@log.debug "#{__FILE__} sent '#{opts['subject']}' to '#{to}'."
|
67
|
+
end
|
68
|
+
|
69
|
+
def make_msg(to, opts)
|
70
|
+
{
|
71
|
+
subject: opts["subject"],
|
72
|
+
body: make_body(opts),
|
73
|
+
body_type: "HTML",
|
74
|
+
to_recipients: to
|
75
|
+
}
|
70
76
|
end
|
71
77
|
|
72
78
|
def add_attachments(msg, opts)
|
data/lib/lazylead/log.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
# OR OTHER DEALINGS IN THE SOFTWARE.
|
24
24
|
|
25
25
|
require "logging"
|
26
|
+
require "colorize"
|
26
27
|
require "forwardable"
|
27
28
|
|
28
29
|
module Lazylead
|
@@ -68,7 +69,7 @@ module Lazylead
|
|
68
69
|
Logging.appenders.stdout(
|
69
70
|
"stdout",
|
70
71
|
layout: Logging.layouts.pattern(
|
71
|
-
pattern: "[%d] %-5l [%X{tid}] %m\n",
|
72
|
+
pattern: "[%d] %-5l #{'[%X{tid}]'.colorize(:light_green)} %m\n",
|
72
73
|
color_scheme: "bright"
|
73
74
|
)
|
74
75
|
)
|
data/lib/lazylead/model.rb
CHANGED
@@ -80,6 +80,13 @@ module Lazylead
|
|
80
80
|
JSON.parse(properties).to_h
|
81
81
|
end
|
82
82
|
|
83
|
+
def to_h?
|
84
|
+
return true unless to_hash.nil?
|
85
|
+
false
|
86
|
+
rescue StandardError => _e
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
83
90
|
def to_s
|
84
91
|
attributes.map { |k, v| "#{k}='#{v}'" }.join(", ")
|
85
92
|
end
|
@@ -94,6 +101,7 @@ module Lazylead
|
|
94
101
|
belongs_to :team, foreign_key: "team_id"
|
95
102
|
belongs_to :system, foreign_key: "system"
|
96
103
|
|
104
|
+
# Execute task
|
97
105
|
def exec
|
98
106
|
sys = system.connect
|
99
107
|
opts = props
|
@@ -101,6 +109,25 @@ module Lazylead
|
|
101
109
|
action.constantize.new.run(sys, postman, opts)
|
102
110
|
end
|
103
111
|
|
112
|
+
# Scheduling type.
|
113
|
+
# Current implementation is based on 'rufus-scheduler' gem and supports
|
114
|
+
# the following types: 'cron', 'interval', 'in', 'at', 'every'
|
115
|
+
def type
|
116
|
+
trigger.first
|
117
|
+
end
|
118
|
+
|
119
|
+
# Scheduling unit.
|
120
|
+
# Current implementation is based on 'rufus-scheduler' gem thus each
|
121
|
+
# scheduling type has own arguments:
|
122
|
+
# 1. Scheduling type 'cron' has 'unit' = '00 09 * * *'
|
123
|
+
# 2. Scheduling type 'interval' has 'unit' = '2h'
|
124
|
+
# 3. Scheduling type 'every' has 'unit' = '3h'
|
125
|
+
# 4. Scheduling type 'in' has 'unit' = '10d'
|
126
|
+
# 5. Scheduling type 'at' has 'unit' = '2014/12/24 2000'
|
127
|
+
def unit
|
128
|
+
trigger.last
|
129
|
+
end
|
130
|
+
|
104
131
|
def detect_cc(sys)
|
105
132
|
opts = props
|
106
133
|
opts["cc"] = CC.new.detect(opts["cc"], sys)
|
@@ -125,13 +152,27 @@ module Lazylead
|
|
125
152
|
Postman.new
|
126
153
|
end
|
127
154
|
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
# Parse scheduling #type and #unit
|
159
|
+
def trigger
|
160
|
+
@trigger ||= begin
|
161
|
+
trg = schedule.split(":")
|
162
|
+
unless trg.size == 2
|
163
|
+
raise "ll-007: illegal schedule format '#{schedule}'"
|
164
|
+
end
|
165
|
+
trg.map(&:strip).map(&:chomp)
|
166
|
+
end
|
167
|
+
end
|
128
168
|
end
|
129
169
|
|
130
170
|
# A task with extended logging
|
131
171
|
# @see Lazylead::ORM::Task
|
132
172
|
class VerboseTask
|
133
173
|
extend Forwardable
|
134
|
-
def_delegators :@orig, :id, :name, :team, :to_s, :inspect, :props
|
174
|
+
def_delegators :@orig, :id, :name, :team, :to_s, :inspect, :props, :type,
|
175
|
+
:unit
|
135
176
|
|
136
177
|
def initialize(orig, log = Log.new)
|
137
178
|
@orig = orig
|
data/lib/lazylead/opts.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
# OR OTHER DEALINGS IN THE SOFTWARE.
|
24
24
|
|
25
25
|
require "forwardable"
|
26
|
+
require_relative "salt"
|
26
27
|
|
27
28
|
module Lazylead
|
28
29
|
#
|
@@ -41,6 +42,7 @@ module Lazylead
|
|
41
42
|
|
42
43
|
# Split text value by delimiter, trim all spaces and reject blank items
|
43
44
|
def slice(key, delim)
|
45
|
+
return [] unless to_h.key? key
|
44
46
|
to_h[key].split(delim).map(&:chomp).map(&:strip).reject(&:blank?)
|
45
47
|
end
|
46
48
|
|
@@ -64,5 +66,16 @@ module Lazylead
|
|
64
66
|
def jira_fields
|
65
67
|
to_h.fetch("fields", "").split(",").map(&:to_sym)
|
66
68
|
end
|
69
|
+
|
70
|
+
# Decrypt particular option using cryptography salt
|
71
|
+
# @param key option to be decrypted
|
72
|
+
# @param sid the name of the salt to be used for the description
|
73
|
+
# @see Lazylead::Salt
|
74
|
+
def decrypt(key, sid)
|
75
|
+
text = to_h[key]
|
76
|
+
return text if text.blank? || text.nil?
|
77
|
+
return Salt.new(sid).decrypt(text) if ENV.key? sid
|
78
|
+
text
|
79
|
+
end
|
67
80
|
end
|
68
81
|
end
|
data/lib/lazylead/postman.rb
CHANGED
@@ -53,26 +53,32 @@ module Lazylead
|
|
53
53
|
# Send an email.
|
54
54
|
# :opts :: the mail configuration like to, from, cc, subject, template.
|
55
55
|
def send(opts)
|
56
|
-
|
56
|
+
mail = make_email(opts)
|
57
|
+
mail.deliver
|
58
|
+
@log.debug "#{__FILE__} sent '#{mail.subject}' to '#{mail.to}'."
|
59
|
+
end
|
60
|
+
|
61
|
+
# Construct an email based on input arguments
|
62
|
+
def make_email(opts)
|
57
63
|
mail = Mail.new
|
58
64
|
mail.to opts[:to] || opts["to"]
|
59
65
|
mail.from opts["from"]
|
60
66
|
mail.cc opts["cc"] if opts.key? "cc"
|
61
67
|
mail.subject opts["subject"]
|
68
|
+
html = make_body(opts)
|
62
69
|
mail.html_part do
|
63
70
|
content_type "text/html; charset=UTF-8"
|
64
71
|
body html
|
65
72
|
end
|
66
73
|
add_attachments mail, opts
|
67
|
-
mail
|
68
|
-
@log.debug "Email was generated from #{opts} and send by #{__FILE__}. " \
|
69
|
-
"Here is the body: #{html}"
|
74
|
+
mail
|
70
75
|
end
|
71
76
|
|
72
77
|
def add_attachments(mail, opts)
|
73
|
-
return unless opts.key?
|
74
|
-
opts["attachments"]
|
75
|
-
|
78
|
+
return unless opts.key?("attachments") || opts.key?(:attachments)
|
79
|
+
attach = opts["attachments"] || opts[:attachments]
|
80
|
+
return if attach.nil?
|
81
|
+
attach.select { |a| File.file? a }.each { |a| mail.add_file a }
|
76
82
|
end
|
77
83
|
end
|
78
84
|
end
|
data/lib/lazylead/schedule.rb
CHANGED
@@ -34,23 +34,18 @@ module Lazylead
|
|
34
34
|
# Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
|
35
35
|
# License:: MIT
|
36
36
|
class Schedule
|
37
|
-
|
38
|
-
# The minimum time period for cron is 1 minute and it's not suitable for
|
39
|
-
# unit testing, thus its better to introduce new types which allows to
|
40
|
-
# schedule some task once or at particular time period like in next 200ms).
|
41
|
-
# For cron expressions we should define separate test suite which will test
|
42
|
-
# in parallel without blocking main CI process.
|
43
|
-
def initialize(log = Log.new, cling = true)
|
37
|
+
def initialize(log: Log.new, cling: true, trigger: Rufus::Scheduler.new)
|
44
38
|
@log = log
|
45
39
|
@cling = cling
|
46
|
-
@trigger =
|
40
|
+
@trigger = trigger
|
47
41
|
end
|
48
42
|
|
49
|
-
# @todo #/DEV error code is required for
|
50
|
-
# application.
|
43
|
+
# @todo #/DEV error code is required for each 'raise' statement within the
|
44
|
+
# application. Align the naming of existing one, the error code should be
|
45
|
+
# like ll-xxx.
|
51
46
|
def register(task)
|
52
47
|
raise "ll-002: task can't be a null" if task.nil?
|
53
|
-
@trigger.
|
48
|
+
@trigger.method(task.type).call(task.unit) do
|
54
49
|
ActiveRecord::Base.connection_pool.with_connection do
|
55
50
|
ORM::VerboseTask.new(task, @log).exec
|
56
51
|
end
|
@@ -60,7 +55,9 @@ module Lazylead
|
|
60
55
|
|
61
56
|
# @todo #/DEV inspect the current execution status. This method should
|
62
57
|
# support several format for output, by default is `json`.
|
63
|
-
def ps
|
58
|
+
def ps
|
59
|
+
@log.debug "#{self}#ps"
|
60
|
+
end
|
64
61
|
|
65
62
|
def join
|
66
63
|
@trigger.join if @cling
|
@@ -80,11 +77,15 @@ module Lazylead
|
|
80
77
|
end
|
81
78
|
|
82
79
|
def register(task)
|
83
|
-
@log.debug
|
80
|
+
@log.debug "Task registered: #{task}"
|
84
81
|
end
|
85
82
|
|
86
|
-
def ps
|
83
|
+
def ps
|
84
|
+
@log.debug "#{self}#ps"
|
85
|
+
end
|
87
86
|
|
88
|
-
def join
|
87
|
+
def join
|
88
|
+
@log.debug "#{self}#join"
|
89
|
+
end
|
89
90
|
end
|
90
91
|
end
|