lazylead 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.0pdd.yml +4 -1
  3. data/.docs/accuracy.md +107 -0
  4. data/.docs/accuracy_email.jpg +0 -0
  5. data/.docs/accuracy_jira_comment.jpg +0 -0
  6. data/.docs/propagate_down.md +1 -1
  7. data/.pdd +1 -1
  8. data/.rubocop.yml +6 -0
  9. data/bin/lazylead +6 -3
  10. data/lazylead.gemspec +4 -4
  11. data/lib/lazylead/exchange.rb +1 -1
  12. data/lib/lazylead/log.rb +30 -8
  13. data/lib/lazylead/model.rb +44 -22
  14. data/lib/lazylead/opts.rb +68 -0
  15. data/lib/lazylead/postman.rb +1 -1
  16. data/lib/lazylead/schedule.rb +3 -3
  17. data/lib/lazylead/smtp.rb +1 -1
  18. data/lib/lazylead/system/jira.rb +16 -14
  19. data/lib/lazylead/system/synced.rb +2 -1
  20. data/lib/lazylead/task/accuracy/accuracy.rb +140 -0
  21. data/lib/lazylead/task/accuracy/affected_build.rb +43 -0
  22. data/lib/lazylead/task/accuracy/requirement.rb +40 -0
  23. data/lib/lazylead/task/alert.rb +8 -6
  24. data/lib/lazylead/task/confluence_ref.rb +4 -3
  25. data/lib/lazylead/task/echo.rb +4 -0
  26. data/lib/lazylead/task/fix_version.rb +10 -6
  27. data/lib/lazylead/task/missing_comment.rb +7 -5
  28. data/lib/lazylead/task/propagate_down.rb +11 -3
  29. data/lib/lazylead/task/savepoint.rb +1 -1
  30. data/lib/lazylead/task/touch.rb +102 -0
  31. data/lib/lazylead/version.rb +1 -1
  32. data/lib/messages/accuracy.erb +118 -0
  33. data/lib/messages/svn_touch.erb +147 -0
  34. data/readme.md +17 -16
  35. data/test/lazylead/cc_test.rb +2 -2
  36. data/test/lazylead/cli/app_test.rb +2 -2
  37. data/test/lazylead/exchange_test.rb +3 -3
  38. data/test/lazylead/model_test.rb +4 -4
  39. data/test/lazylead/opts_test.rb +66 -0
  40. data/test/lazylead/postman_test.rb +1 -1
  41. data/test/lazylead/smtp_test.rb +1 -1
  42. data/test/lazylead/system/jira_test.rb +35 -1
  43. data/test/lazylead/task/accuracy/accuracy_test.rb +73 -0
  44. data/test/lazylead/task/accuracy/affected_build_test.rb +42 -0
  45. data/test/lazylead/task/assignee_alert_test.rb +2 -2
  46. data/test/lazylead/task/duedate_test.rb +36 -26
  47. data/test/lazylead/task/fix_version_test.rb +9 -6
  48. data/test/lazylead/task/missing_comment_test.rb +11 -9
  49. data/test/lazylead/task/propagate_down_test.rb +4 -2
  50. data/test/lazylead/task/touch_test.rb +63 -0
  51. data/upgrades/sqlite/999.testdata.sql +2 -1
  52. metadata +25 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4564fa672731c29fe8e9dc32d2f09c56bf0b9245fce2900b4335c49442d08fb2
4
- data.tar.gz: 58ff724cc12437d3106978913f0c2ef12a189f2e80b87ec07a2202bcd0f90267
3
+ metadata.gz: d8f6929a5583f40fca08c1d1293b77cf2f19ea22b1844eb9888a860b79c86b7c
4
+ data.tar.gz: 07b70000fe7e00aeb7c33b321d1f35c99dccb8220f477650b90a693ea8688c0c
5
5
  SHA512:
6
- metadata.gz: e7b23097dca908102e6863d5527769bfe3d5405003cbab920da7ee6fd7f4118b554eb3d3a5f1170830dfdbf8fb08f752e6276fae4157f919f6e39ec070a91089
7
- data.tar.gz: be8745b87907ab9ad30e9e4eb67f0ebf44ae0dcc01dcdbedefd79ab480e1222bbdc8835a397d465b5e491e995ee7ceaf685464385d7d87c0f0014900325d38ac
6
+ metadata.gz: 1699bbdc2484d6a77715b11bb0f666e70e18e3bc5927d79ee02cee3bfcc4e6bf6d848a74a5c287990e56d059f669f07dc9e450f7af6992b63881288f481e062e
7
+ data.tar.gz: 0c471418e7ed2a92d740d0e362c0bcd9ce37eca1538272eab8abe0eff4fb3b01df1559b5f16d7af9ed3dfa52d06ebb5ff1c6a10cb897df7aeab3e119f8fe63c3
data/.0pdd.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  errors:
2
2
  - yurii.dubinka@gmail.com
3
-
3
+ alerts:
4
+ suppress:
5
+ - on-found-puzzle
6
+ - on-lost-puzzle
4
7
  tags:
5
8
  - pdd
@@ -0,0 +1,107 @@
1
+ ## Give the score for the format of each incoming ticket to your team
2
+ #### Why?
3
+ When you have a pipeline between several teams, there should be criteria on how to pass a task between groups.
4
+ Without this, you may get the delays for your task because your team members have to do the work that is not their business, or they even don't have the skills to do it properly.
5
+ As a result, it may cause task delays or quality decreasing.
6
+
7
+ Even if you define the criteria for passing tasks between teams, it's tough to monitor that those criteria aren't violating. To hire a well-paid additional manager who will check each ticket and send emails its expensive unless you work for a bloody reach company.
8
+
9
+ This rule periodically checks the format of the ticket, post score results to the ticket, and raise email (one email per bunch of tickets) to you with details.
10
+
11
+ #### How to use lazylead for this
12
+ Let's assume that
13
+ 1. Your team is working in Jira
14
+ 2. You want daily to check the format of incoming defects to your team
15
+ 3. [JQL](https://www.atlassian.com/blog/jira-software/jql-the-most-flexible-way-to-search-jira-14) for incoming defects: `project='PRJ' and type=Defect and created < -2h and created > -26h`.
16
+ This `< -2h` and `> -26h` gives reporter 2h to fill the ticket correctly, and, after that, the task will evaluate the ticket score.
17
+ 4. you've saved this [JQL](https://www.atlassian.com/blog/jira-software/jql-the-most-flexible-way-to-search-jira-14) as jira filter with id `222`.
18
+
19
+ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
20
+ 1. Define yml file with `docker-compose` configuration in `lazylead.yml`
21
+ ```yml
22
+ version: '2.3'
23
+ services:
24
+ lazylead:
25
+ image: dgroup/lazylead:latest
26
+ container_name: lazylead
27
+ mem_limit: 128m
28
+ environment:
29
+ # The jira server details.
30
+ # Please ensure that your jira filter(s) grants this user to see issues.
31
+ # Sometimes jira filter(s) may be created with restricted visibility, thus
32
+ # lazylead can't find the issues.
33
+ jira_url: https://your.jira.com
34
+ jira_user: theuser
35
+ jira_password: thepass
36
+ volumes:
37
+ - ./:/lazylead/db
38
+ # db/ll.db is sqlite file with jira related annoying tasks
39
+ entrypoint: bin/lazylead --sqlite db/ll.db --trace --verbose
40
+ ```
41
+
42
+ 2. Create a container, using `docker-compose -f lazylead.yml up`
43
+ The container will stop as there were no tasks provided:
44
+ ```bash
45
+ ll > docker-compose -f lazylead.yml up
46
+ Creating lazylead ... done
47
+ Attaching to lazylead
48
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] Version: 0.4.0
49
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] Memory footprint at start is 52MB
50
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] Database: '/lazylead/db/ll.db', sql migration dir: '/lazylead/upgrades/sqlite'
51
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] Migration applied to /lazylead/db/ll.db from /lazylead/upgrades/sqlite
52
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] Database connection established
53
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] SMTP connection established with {host} as {user}.
54
+ lazylead | [2020-08-09T06:17:32] WARN [main] ll-001: No tasks found.
55
+ lazylead | [2020-08-09T06:17:32] DEBUG [main] Memory footprint at the end is 67MB
56
+ ll >
57
+ ```
58
+
59
+ 3. Define your team and tasks in database.
60
+ The tables structure defined [here](../upgrades/sqlite/001-install-main-lazylead-tables.sql).
61
+ Modify you [sqlite](https://sqlite.com/index.html) file(`ll.db`) using [DB Browser](https://sqlitebrowser.org/) or any similar tool.
62
+ ```sql
63
+ insert into teams (id, name, properties)
64
+ values (1, 'Dream team with lazylead', '{}');
65
+ insert into systems(id, properties)
66
+ values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
67
+ insert into tasks (name, cron, enabled, id, system, team_id, action, properties)
68
+ values ('Post ticket score and accuracy to the tickets',
69
+ '0 8 * * 1-5',
70
+ 'true',
71
+ 1, 1, 1,
72
+ 'Lazylead::Task::Accuracy',
73
+ '{
74
+ "jql": "filter=222",
75
+ "to": "lead@fake.com",
76
+ "rules": "Lazylead::RequirementAffectedBuild",
77
+ "colors": "{ "0": "#FF4F33", "35": "#FF9F33", "57": "#19DD1E", "90": "#0FA81A" }",
78
+ "docs": "https://github.com/dgroup/lazylead/blob/master/.github/ISSUE_TEMPLATE/bug_report.md",
79
+ "max_results": "200",
80
+ "subject": "[LL] Raised tickets",
81
+ "template": "lib/messages/accuracy.erb"
82
+ }
83
+ ');
84
+ ```
85
+ Yes, for task scheduling we are using [cron](https://crontab.guru).
86
+
87
+ 4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
88
+ ```bash
89
+ ll > docker-compose -f .github/tasks.yml restart
90
+ Restarting lazylead ... done
91
+ ```
92
+
93
+ 5. Once task completed, please check your defects, they should have comment like
94
+ ![jira comment](accuracy_jira_comment.jpg)
95
+
96
+ and you'll get an email like
97
+ ![email](accuracy_email.jpg)
98
+
99
+
100
+ #### Where is the code?
101
+ | Logic | Tests |
102
+ | :-----: | :------: |
103
+ | [accuracy.rb](../lib/lazylead/task/accuracy/accuracy.rb)| [accuracy_test.rb](../test/lazylead/task/accuracy/accuracy_test.rb) |
104
+
105
+ #### How can I add my own rules?
106
+ The custom rules should extend `Lazylead::Requirement` class and placed it to the `lib/lazylead/task/accuracy` folder.
107
+ After that, you need to mention your custom rules in `rules` option in the column `properties` from `tasks` table
Binary file
@@ -64,7 +64,7 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
64
64
  'true',
65
65
  1, 1, 1,
66
66
  'Lazylead::Task::PropagateDown',
67
- '{"jql":"filter=222", "fields":"customfield_1"}');
67
+ '{"jql":"filter=222", "propagate":"customfield_1"}');
68
68
 
69
69
  ```
70
70
  Yes, for task scheduling we are using [cron](https://crontab.guru).
data/.pdd CHANGED
@@ -2,4 +2,4 @@
2
2
  --verbose
3
3
  --exclude target/**/*
4
4
  --exclude coverage/**/*
5
- --rule min-words:5
5
+ --rule min-words:7
@@ -77,6 +77,12 @@ Style/HashTransformKeys:
77
77
  Style/HashTransformValues:
78
78
  Enabled: true
79
79
 
80
+ # @todo #/DEV accuracy.rb is using % symbol in text message and rubocop
81
+ # complains about it. It's false-positive violation, thus, for now ignored for this file
82
+ Style/FormatStringToken:
83
+ Exclude:
84
+ - "lib/lazylead/task/accuracy/accuracy.rb"
85
+
80
86
  Lint/RaiseException:
81
87
  Enabled: true
82
88
 
@@ -39,11 +39,14 @@ require_relative "../lib/lazylead/schedule"
39
39
  require_relative "../lib/lazylead/allocated"
40
40
  require_relative "../lib/lazylead/cli/app"
41
41
 
42
- log = Lazylead::Log::ERRORS
42
+ log = Lazylead::Log.new
43
43
  Thread.current.name = "main"
44
+ Logging.mdc["tid"] = Thread.current.name
44
45
  Encoding.default_external = Encoding::UTF_8
45
46
  Encoding.default_internal = Encoding::UTF_8
46
47
 
48
+ # @todo #/DEV Decorate ARGV with custom methods in order to avoid code
49
+ # duplication, like { ARGV.include? "--trace" }
47
50
  opts = Slop.parse(ARGV, strict: false, suppress_errors: true) do |o|
48
51
  o.banner = "Usage: lazylead [options]
49
52
  Available options:"
@@ -67,7 +70,7 @@ Available options:"
67
70
  "Apply the database VCS migration with test data",
68
71
  default: false
69
72
  o.on "--verbose", "Enable extra logging information" do
70
- log = Lazylead::Log::VERBOSE
73
+ log.verbose
71
74
  end
72
75
  o.on "-v", "--version", "Show current version" do
73
76
  log.debug Lazylead::VERSION
@@ -91,7 +94,7 @@ cmd = lambda do
91
94
  return 0
92
95
  rescue StandardError => e
93
96
  log.error("#{e.message} (#{e.class.name})")
94
- log.error(Backtrace.new(e)) if opts["trace"]
97
+ log.error(Backtrace.new(e)) if ARGV.include? "--trace"
95
98
  return -1
96
99
  end
97
100
  code = 0
@@ -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.3.1"
35
+ s.version = "0.4.0"
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.3.1!
48
+ s.post_install_message = "Thanks for installing Lazylead v0.4.0!
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
@@ -60,7 +60,7 @@ tasks instead of solving technical problems."
60
60
  s.add_runtime_dependency "faraday", "1.0.1"
61
61
  s.add_runtime_dependency "get_process_mem", "0.2.5"
62
62
  s.add_runtime_dependency "jira-ruby", "1.7.1"
63
- s.add_runtime_dependency "json", "2.2.0"
63
+ s.add_runtime_dependency "json", "2.3.0"
64
64
  s.add_runtime_dependency "logging", "2.2.2"
65
65
  s.add_runtime_dependency "mail", "2.7.1"
66
66
  s.add_runtime_dependency "memory_profiler", "0.9.13"
@@ -75,7 +75,7 @@ tasks instead of solving technical problems."
75
75
  s.add_runtime_dependency "tzinfo-data", "1.2019.3"
76
76
  s.add_runtime_dependency "vcs4sql", "0.1.0"
77
77
  s.add_runtime_dependency "viewpoint", "1.1.0"
78
- s.add_development_dependency "codecov", "0.1.14"
78
+ s.add_development_dependency "codecov", "0.2.3"
79
79
  s.add_development_dependency "guard", "2.15.0"
80
80
  s.add_development_dependency "guard-minitest", "2.4.6"
81
81
  s.add_development_dependency "minitest", "5.11.3"
@@ -42,7 +42,7 @@ module Lazylead
42
42
  include Emailing
43
43
 
44
44
  def initialize(
45
- log = Log::NOTHING, salt = Salt.new("exchange_salt"), opts = ENV.to_h
45
+ log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h
46
46
  )
47
47
  @log = log
48
48
  @salt = salt
@@ -23,16 +23,38 @@
23
23
  # OR OTHER DEALINGS IN THE SOFTWARE.
24
24
 
25
25
  require "logging"
26
+ require "forwardable"
26
27
 
27
28
  module Lazylead
28
- # Loggers.
29
+ # The main application logger
30
+ class Log
31
+ extend Forwardable
32
+ def_delegators :@log, :debug, :info, :warn, :error
33
+
34
+ def initialize(log = Lazylead::Level::ERRORS)
35
+ @log = log
36
+ @log = Lazylead::Level::DEBUG if ARGV.include? "--trace"
37
+ end
38
+
39
+ def nothing
40
+ @log = Lazylead::Level::NOTHING
41
+ self
42
+ end
43
+
44
+ def verbose
45
+ @log = Lazylead::Level::DEBUG
46
+ self
47
+ end
48
+ end
49
+
50
+ # Predefined logging levels.
29
51
  #
30
52
  # There are 3 colored loggers so far:
31
53
  # NOTHING - for cases when logging isn't required
32
54
  # VERBOSE - all logging levels including debug
33
55
  # ERRORS - for errors only which are critical for app.
34
56
  #
35
- module Log
57
+ module Level
36
58
  # Coloring configuration for appender(s).
37
59
  Logging.color_scheme("bright",
38
60
  levels: {
@@ -46,7 +68,7 @@ module Lazylead
46
68
  Logging.appenders.stdout(
47
69
  "stdout",
48
70
  layout: Logging.layouts.pattern(
49
- pattern: "[%d] %-5l %m\n",
71
+ pattern: "[%d] %-5l [%X{tid}] %m\n",
50
72
  color_scheme: "bright"
51
73
  )
52
74
  )
@@ -57,12 +79,12 @@ module Lazylead
57
79
  NOTHING.freeze
58
80
 
59
81
  # All levels including debug
60
- VERBOSE = Logging.logger["verbose"]
61
- VERBOSE.level = :debug
62
- VERBOSE.add_appenders "stdout"
63
- VERBOSE.freeze
82
+ DEBUG = Logging.logger["debug"]
83
+ DEBUG.level = :debug
84
+ DEBUG.add_appenders "stdout"
85
+ DEBUG.freeze
64
86
 
65
- # Alerts
87
+ # Alerts/errors
66
88
  ERRORS = Logging.logger["errors"]
67
89
  ERRORS.level = :error
68
90
  ERRORS.add_appenders "stdout"
@@ -22,12 +22,15 @@
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 "active_record"
25
+ require "backtrace"
26
26
  require "require_all"
27
+ require "forwardable"
28
+ require "active_record"
27
29
  require_rel "task"
28
30
  require_rel "system"
29
31
  require_relative "cc"
30
32
  require_relative "log"
33
+ require_relative "opts"
31
34
  require_relative "postman"
32
35
  require_relative "exchange"
33
36
 
@@ -91,18 +94,11 @@ module Lazylead
91
94
  belongs_to :team, foreign_key: "team_id"
92
95
  belongs_to :system, foreign_key: "system"
93
96
 
94
- # @todo #/DEV Add error handling for StandartError with support of
95
- # verbose key from ARGV like in /bin/lazylead. That will make error
96
- # messages more human readable. Maybe there is some integration between
97
- # Slop and ARGV in order to avoid logic duplication.
98
- def exec(log = Log::NOTHING)
99
- log.debug("Task ##{id} '#{name}' is started")
100
- sys = system.connect(log)
101
- pman = postman(log)
102
- opts = props(log)
97
+ def exec
98
+ sys = system.connect
99
+ opts = props
103
100
  opts = detect_cc(sys) if opts.key? "cc"
104
- action.constantize.new(log).run(sys, pman, opts)
105
- log.debug("Task ##{id} '#{name}' is completed")
101
+ action.constantize.new(log).run(sys, postman, opts)
106
102
  end
107
103
 
108
104
  def detect_cc(sys)
@@ -112,33 +108,60 @@ module Lazylead
112
108
  opts
113
109
  end
114
110
 
115
- def props(log = Log::NOTHING)
111
+ def props
116
112
  @props ||= begin
117
113
  if team.nil?
118
- log.warn("Team for task #{id} isn't defined.")
119
- env(to_hash)
114
+ Opts.new(env(to_hash))
120
115
  else
121
- env(team.to_hash.merge(to_hash))
116
+ Opts.new(env(team.to_hash.merge(to_hash)))
122
117
  end
123
118
  end
124
119
  end
125
120
 
126
- def postman(log = Log::NOTHING)
121
+ def postman
127
122
  if props.key? "postman"
128
- props["postman"].constantize.new(log)
123
+ props["postman"].constantize.new
129
124
  else
130
- log.warn "No postman details provided, an local stub is used."
131
125
  Postman.new
132
126
  end
133
127
  end
134
128
  end
135
129
 
130
+ # A task with extended logging
131
+ # @see Lazylead::ORM::Task
132
+ class VerboseTask
133
+ extend Forwardable
134
+ def_delegators :@orig, :id, :name, :team, :to_s, :inspect, :props
135
+
136
+ def initialize(orig, log = Log.new)
137
+ @orig = orig
138
+ @log = log
139
+ end
140
+
141
+ def exec
142
+ Logging.mdc["tid"] = "task #{id}"
143
+ @log.debug "'#{name}' is started."
144
+ @log.warn "No postman, stub is used." unless props.key? "postman"
145
+ @log.warn "No team." if team.nil?
146
+ @orig.exec @log
147
+ @log.debug "'#{name}' is completed"
148
+ rescue StandardError => e
149
+ msg = <<~MSG
150
+ ll-006: Task ##{id} #{e} (#{e.class}) at #{self}
151
+ #{Backtrace.new(e) if ARGV.include? '--trace'}"
152
+ MSG
153
+ @log.error msg
154
+ ensure
155
+ Logging.mdc["tid"] = ""
156
+ end
157
+ end
158
+
136
159
  # Ticketing systems to monitor.
137
160
  class System < ActiveRecord::Base
138
161
  include ORM
139
162
 
140
163
  # Make an instance of ticketing system for future interaction.
141
- def connect(log = Log::NOTHING)
164
+ def connect(log = Log.new)
142
165
  opts = to_hash
143
166
  if opts["type"].empty?
144
167
  log.warn "No task system details provided, an empty stub is used."
@@ -146,8 +169,7 @@ module Lazylead
146
169
  else
147
170
  opts["type"].constantize.new(
148
171
  env(opts.except("type", "salt")),
149
- opts["salt"].blank? ? NoSalt.new : Salt.new(opts["salt"]),
150
- log
172
+ opts["salt"].blank? ? NoSalt.new : Salt.new(opts["salt"])
151
173
  )
152
174
  end
153
175
  end
@@ -0,0 +1,68 @@
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 "forwardable"
26
+
27
+ module Lazylead
28
+ #
29
+ # Default options for all lazylead tasks.
30
+ #
31
+ # Author:: Yurii Dubinka (yurii.dubinka@gmail.com)
32
+ # Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
33
+ # License:: MIT
34
+ class Opts
35
+ extend Forwardable
36
+ def_delegators :@origin, :[], :[]=, :to_s, :key?, :fetch, :merge
37
+
38
+ def initialize(origin = {})
39
+ @origin = origin
40
+ end
41
+
42
+ # Split text value by delimiter, trim all spaces and reject blank items
43
+ def slice(key, delim)
44
+ to_h[key].split(delim).map(&:chomp).map(&:strip).reject(&:blank?)
45
+ end
46
+
47
+ def blank?(key)
48
+ to_h[key].nil? || @origin[key].blank?
49
+ end
50
+
51
+ def to_h
52
+ @origin
53
+ end
54
+
55
+ # Default Jira options to use during search for all Jira-based tasks.
56
+ def jira_defaults
57
+ {
58
+ max_results: fetch("max_results", 50),
59
+ fields: jira_fields
60
+ }
61
+ end
62
+
63
+ # Default fields which to fetch within the Jira issue
64
+ def jira_fields
65
+ to_h.fetch("fields", "").split(",").map(&:to_sym)
66
+ end
67
+ end
68
+ end