site_hook 0.8.2 → 0.9.3

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rspec +0 -2
  4. data/.rubocop.yml +2 -0
  5. data/Gemfile +1 -5
  6. data/Rakefile +35 -3
  7. data/bin/site_hook +5 -1
  8. data/features/get_help.feature +3 -0
  9. data/features/step_definitions/get_help_step_definition.rb +1 -0
  10. data/features/step_definitions/my_steps.rb +3 -0
  11. data/features/support/env.rb +1 -0
  12. data/lib/site_hook.rb +2 -28
  13. data/lib/site_hook/cli.rb +22 -39
  14. data/lib/site_hook/commands/config_class.rb +22 -68
  15. data/lib/site_hook/commands/jekyll_class.rb +38 -0
  16. data/lib/site_hook/commands/server_class.rb +38 -34
  17. data/lib/site_hook/config.rb +390 -14
  18. data/lib/site_hook/config_sections.rb +60 -9
  19. data/lib/site_hook/deprecate.rb +34 -11
  20. data/lib/site_hook/env/env.rb +2 -0
  21. data/lib/site_hook/exceptions.rb +26 -2
  22. data/lib/site_hook/log.rb +20 -15
  23. data/lib/site_hook/logger.rb +94 -173
  24. data/lib/site_hook/loggers.rb +10 -0
  25. data/lib/site_hook/loggers/access.rb +20 -0
  26. data/lib/site_hook/loggers/app.rb +78 -0
  27. data/lib/site_hook/loggers/build.rb +77 -0
  28. data/lib/site_hook/loggers/fake.rb +52 -0
  29. data/lib/site_hook/loggers/git.rb +81 -0
  30. data/lib/site_hook/loggers/hook.rb +74 -0
  31. data/lib/site_hook/methods.rb +26 -0
  32. data/lib/site_hook/paths.rb +65 -2
  33. data/lib/site_hook/prelogger.rb +88 -0
  34. data/lib/site_hook/prompt.rb +14 -0
  35. data/lib/site_hook/prompts/prompt_project.rb +48 -0
  36. data/lib/site_hook/runner.rb +36 -0
  37. data/lib/site_hook/sender.rb +4 -9
  38. data/lib/site_hook/string_ext.rb +57 -0
  39. data/lib/site_hook/version.rb +2 -2
  40. data/lib/site_hook/webhook.rb +120 -129
  41. data/site_hook.gemspec +39 -22
  42. data/spec/spec_helper.rb +13 -0
  43. data/spec/string_ext_spec.rb +10 -0
  44. metadata +87 -85
  45. data/CODE_OF_CONDUCT.md +0 -74
  46. data/bin/console +0 -14
  47. data/lib/site_hook/assets/css/styles.css +0 -26
  48. data/lib/site_hook/commands/debug_class.rb +0 -29
  49. data/lib/site_hook/config_sections/cli.rb +0 -24
  50. data/lib/site_hook/config_sections/log_levels.rb +0 -15
  51. data/lib/site_hook/config_sections/projects.rb +0 -22
  52. data/lib/site_hook/const.rb +0 -10
  53. data/lib/site_hook/gem.rb +0 -26
  54. data/lib/site_hook/persist.rb +0 -14
  55. data/lib/site_hook/prompts/gen_config.rb +0 -48
  56. data/lib/site_hook/spinner.rb +0 -19
  57. data/lib/site_hook/views/layout.haml +0 -24
  58. data/lib/site_hook/views/webhooks.haml +0 -7
@@ -1,13 +1,64 @@
1
- require 'yaml'
2
1
  module SiteHook
3
- module ConfigSections
4
- autoload :Cli, 'site_hook/config_sections/cli'
5
- autoload :LogLevels, 'site_hook/config_sections/log_levels'
6
- autoload :Projects, 'site_hook/config_sections/projects'
7
- module_function
8
- def print_example_config
9
- full_config = [Cli.example, LogLevels.example, Projects.example].flatten(1)
10
- puts full_config
2
+ class ConfigSections
3
+ def self.all_samples
4
+ sections = self.constants
5
+ @@sample = []
6
+ sections.each do |section|
7
+ @@sample << self.const_get(section).sample
8
+ end
9
+ puts @@sample
10
+ end
11
+ class Webhook
12
+ def self.sample
13
+ <<~WEBHOOK
14
+ webhook:
15
+ host: 127.0.0.1
16
+ port: 9090
17
+
18
+ WEBHOOK
19
+ end
20
+
21
+ end
22
+ class LogLevels
23
+ def self.sample
24
+ <<~LOGLEVELS
25
+ log_levels:
26
+ # unknown, fatal, error, warn, info, debug
27
+ app: info
28
+ build: info
29
+ git: info
30
+ hook: info
31
+
32
+ LOGLEVELS
33
+ end
34
+ end
35
+ class Cli
36
+ def self.sample
37
+ <<~CLI
38
+ cli:
39
+ config:
40
+ mkpass:
41
+ length: 20
42
+ symbols: false
43
+
44
+ CLI
45
+ end
46
+ end
47
+ class Projects
48
+ def self.sample
49
+ <<~PROJECTS
50
+ projects:
51
+ project1:
52
+ config: _config.yml
53
+ src: /path/2/site/source
54
+ dst: /path/2/build/destination
55
+ host: github.com
56
+ repo: some/repo
57
+ hookpass: SOMESECRETSTRING
58
+ private: false
59
+
60
+ PROJECTS
61
+ end
11
62
  end
12
63
  end
13
64
  end
@@ -1,16 +1,39 @@
1
+ require 'paint/util'
1
2
  module SiteHook
3
+
4
+ class DeprecationError < SiteHookError
5
+ def initialize(msg)
6
+ super(msg, 99)
7
+ end
8
+ end
2
9
  class Deprecation
3
- attr_reader :instructions
4
- def initialize(message, situation, instructions)
5
- @str = "▼▼▼ [#{Paint['DEPRECATION ERROR', :red, :bold]}] —— The following situation is deprecated! ▼▼▼"
6
- @situation = situation
7
- @str << "\n#{@situation}"
8
- @instructions = instructions
9
- @str << "\n#{@instructions}"
10
+
11
+ def self.deprecate(command, situation, instructions, continue)
12
+ @@exe_name = command.topmost_ancestor.parent.exe_name
13
+ @@str = "▼▼▼ [#{Paint['DEPRECATION ERROR', 'red', :bold]}] —— #{Paint['The following situation is deprecated', 'yellow', :bold, :blink]}! ▼▼▼"
14
+ @@situation = situation
15
+ @@str << "\n#{@@situation}"
16
+ @@instructions = instructions
17
+ @@str << "\n#{@@instructions}"
18
+
19
+ return {msg: @@str, exit: !continue}
20
+ end
21
+ def self.deprecate_config(command)
22
+ return self.deprecate(
23
+ command,
24
+ "'#{Paint[SiteHook::Paths.old_config.to_s, 'red']}' is deprecated in favor of '#{Paint[SiteHook::Paths.config, 'green']}'",
25
+ <<~INSTRUCT,
26
+ Please run `#{Paint["#{command.topmost_ancestor.parent.exe_name} config upgrade-shrc", 'red', :blink]}` to rectify this.
27
+ Once version 1.0.0 is released, '#{Paint["#{SiteHook::Paths.config}", 'green']}' will
28
+ be the only config file option, and '#{Paint["#{SiteHook::Paths.old_config}", 'orange']}' will not be allowed.
29
+ any existance of '#{Paint["#{Dir.home}/.jph", 'red']}' after the #{Paint['1.0.0', :bold]} release will result in an Exception being raised.
30
+ #{"#{Paint['Once the exception is raised', 'red']}, site_hook will #{Paint['exit', 'red']} and return a #{Paint['99', 'red']} status code."}
31
+ INSTRUCT
32
+ true
33
+ )
10
34
  end
11
- def self.deprecate(situation, instructions, continue)
12
- puts @str if @str
13
- return continue
35
+ def self.raise_error(msg)
36
+ raise DeprecationError.new(msg)
14
37
  end
15
38
  end
16
39
  class NotImplemented
@@ -18,7 +41,7 @@ module SiteHook
18
41
 
19
42
  def initialize(command)
20
43
  @command_object = command
21
- @exe_name = @command_object.parent.parent.exe_name
44
+ @exe_name = @command_object.topmost_ancestor.parent.exe_name
22
45
  @output_string = "Command `#{@exe_name} #{command.name_for_help.join(' ')}"
23
46
  end
24
47
  def self.declare(command)
@@ -0,0 +1,2 @@
1
+ require 'grape'
2
+ require 'grape-route-helpers'
@@ -1,9 +1,33 @@
1
1
  require 'paint'
2
2
  module SiteHook
3
3
  class SiteHookError < StandardError
4
+ def initialize(msg, err)
5
+ super(msg)
6
+ exit err
7
+ end
4
8
  end
5
9
  class ConfigExistsError < SiteHookError
6
10
  end
7
-
8
-
11
+ class NoConfigError < SiteHookError
12
+ attr_reader :path
13
+ def initialize(path)
14
+ @str = "Config path '#{Paint[path, 'red']}' does not exist!"
15
+ @path = path
16
+ super(@str,98)
17
+ end
18
+ end
19
+ class NeitherConfigError < SiteHookError
20
+ attr_reader :paths
21
+ def initialize
22
+ @str = "Neither '#{SiteHook::Paths.old_config}' nor '#{SiteHook::Paths.config}'"
23
+ end
24
+ end
25
+ class NoLogsError < SiteHookError
26
+ attr_reader :path
27
+ def initialize(path)
28
+ @str = "Log path '#{Paint[path, 'red']}' does not exist!"
29
+ @path = path
30
+ super(@str,97)
31
+ end
32
+ end
9
33
  end
@@ -1,26 +1,31 @@
1
+ require 'site_hook/configs/log_levels'
1
2
  module SiteHook
2
3
  autoload :Paths, 'site_hook/paths'
4
+ autoload :Config, 'site_hook/config'
5
+ ##
3
6
  # Logs
4
7
  # Give logs related methods
8
+ #
9
+
5
10
  module Logs
6
11
  module_function
7
- def self.log_levels
8
- default = {
9
- 'hook' => 'info',
12
+ DEFAULT = {
13
+ 'hook' => 'info',
10
14
  'build' => 'info',
11
- 'git' => 'info',
12
- 'app' => 'info'
13
- }
14
- begin
15
- log_level = YAML.load_file(SiteHook::Paths.config).fetch('log_levels')
16
- if log_level
17
- log_level
18
- end
19
- rescue KeyError
20
- default
21
- rescue Errno::ENOENT
22
- default
15
+ 'git' => 'info',
16
+ 'app' => 'info'
17
+ }
18
+ # @return [Hash] the log levels
19
+ def self.log_levels
20
+ puts SiteHook::Configs::LogLevels.methods
21
+ log_level = SiteHook::Configs::LogLevels
22
+ if log_level
23
+ log_level
23
24
  end
25
+ rescue KeyError
26
+ DEFAULT
27
+ rescue Errno::ENOENT
28
+ DEFAULT
24
29
  end
25
30
  end
26
31
  end
@@ -1,194 +1,115 @@
1
- require 'paint'
2
- require 'logging'
3
- require 'pathname'
4
- require 'active_support/core_ext/string'
5
-
6
- Logging.init %w(NONE DEBUG INFO WARN ERROR FATAL)
7
- Logging.color_scheme(
8
- 'bright',
9
- :levels => {
10
- :debug => [:yellow, :on_white],
11
- :info => :blue,
12
- :warn => :yellow,
13
- :error => :red,
14
- :fatal => [:red, :on_white],
15
- },
16
- :date => :white,
17
- :logger => :cyan,
18
- :message => :green,
19
- )
20
- PATTERN = '[%d] %-5l %c: %m\n'
21
- DATE_PATTERN = '%Y-%m-%d %H:%M:%S'
22
- layout = Logging.layouts.pattern \
23
- :pattern => PATTERN,
24
- :date_pattern => DATE_PATTERN,
25
- :color_scheme => 'bright'
26
-
27
- Logging.appenders.stdout \
28
- :layout => layout
29
-
1
+ require 'logger'
2
+ require 'recursive_open_struct'
3
+ require 'site_hook/loggers'
4
+ require 'site_hook/paths'
5
+ require 'yaml'
6
+ require 'site_hook/string_ext'
7
+ #require 'site_hook/configs'
30
8
  module SiteHook
31
- def mklogdir
32
- path = Pathname(Dir.home).join('.jph', 'logs')
33
- if path.exist?
34
- # Path exists, don't do anything
35
- else
36
- FileUtils.mkpath(path.to_s)
9
+ class Log
10
+ def self.defaults
11
+ RecursiveOpenStruct.new(
12
+ {
13
+ Hook: {
14
+ level: 'info'
15
+ },
16
+ App: {
17
+ level: 'info'
18
+ },
19
+ Build: {
20
+ level: 'info'
21
+ },
22
+ Git: {
23
+ level: 'info'
24
+ },
25
+ Access: {
26
+ level: nil
27
+ },
28
+ Fake: {
29
+ level: nil
30
+ }
31
+ })
37
32
  end
38
- end
39
-
40
- def safe_log_name(klass)
41
- klass.class.name.split('::').last.underscore
42
- end
43
-
44
- module_function :mklogdir, :safe_log_name
45
-
46
- class LogLogger
47
- attr :log
48
- attr :log_level
49
33
 
50
- def initialize(log_level = 'info') # only change this to debug when testing
51
- @log = Logging.logger[SiteHook.safe_log_name(self)]
52
- @log_level = log_level
53
-
54
- flayout = Logging.appenders.rolling_file \
55
- Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
56
- :age => 'daily',
57
- :pattern => PATTERN
58
- @log.add_appenders 'stdout', flayout
59
- @log.level = log_level
60
- end
61
- end
62
-
63
- mklogdir
64
- LL = LogLogger.new.log
65
- LL.debug "#{SiteHook.safe_log_name(LL.class)} initialized."
66
-
67
- class HookLogger
68
-
69
- # Log App Actions
70
- class AppLog
71
- attr :log
72
- attr :log_level
73
-
74
- def initialize(log_level = nil)
75
- LL.debug "Initializing #{SiteHook.safe_log_name(self)}"
76
- @log = Logging.logger[SiteHook.safe_log_name(self)]
77
- @log_level = log_level
78
-
79
- flayout = Logging.appenders.rolling_file \
80
- Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
81
- :age => 'daily',
82
- :pattern => PATTERN
83
- @log.add_appenders 'stdout', flayout
84
- @log.level = log_level
85
- LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
34
+ def self.validate(config)
35
+ invalid_types = []
36
+ valid_config_log_types = [
37
+ 'hook',
38
+ 'git',
39
+ 'app',
40
+ 'build'
41
+ ]
42
+ invalid_config_log_types = [
43
+ 'access',
44
+ 'fake'
45
+ ]
46
+ config = config['log_levels']
47
+ is_config_valid = config.all? do |x|
48
+ if valid_config_log_types.include? x
49
+ true
50
+ else
51
+ if invalid_config_log_types.include? x
52
+ invalid_types << x
53
+ false
54
+ end
55
+ end
56
+ end
57
+ unless is_config_valid
58
+ raise ArgumentError "invalid log type(s) in config, [#{invalid_types.join(', ')}]"
86
59
  end
87
60
  end
88
61
 
89
- # Log Hook Actions
90
- class HookLog
91
- attr :log
92
- attr :log_level
93
-
94
- def initialize(log_level = nil)
95
- LL.debug "Initializing #{SiteHook.safe_log_name(self)}"
96
- @log = Logging.logger[SiteHook.safe_log_name(self)]
97
- @log_level = log_level
98
- flayout = Logging.appenders.rolling_file \
99
- Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
100
- :age => 'daily',
101
- :pattern => PATTERN
102
- @log.add_appenders 'stdout', flayout
103
- @log.level = @log_level
104
- LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
62
+ def inspect
63
+ meths = %i[hook build git app fake access]
64
+ sections = {}
65
+ meths.each do |m|
66
+ sections[m] = self.class.send(m).inspect
105
67
  end
68
+ secs = []
69
+ sections.each { |name, instance| secs << "#{name}=#{instance}" }
70
+ "#<SiteHook::Log #{secs.join(' ')}>"
106
71
  end
107
72
 
108
- # Log Build Actions
109
- class BuildLog
110
- attr :log
111
-
112
- def initialize(log_level = nil)
113
- LL.debug "Initializing #{SiteHook.safe_log_name(self)}"
114
- @log = Logging.logger[SiteHook.safe_log_name(self)]
115
- @log_level = log_level
73
+ def initialize(input, output, errput)
116
74
 
117
- flayout = Logging.appenders.rolling_file \
118
- Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
119
- :age => 'daily',
120
- :pattern => PATTERN
121
- @log.add_appenders 'stdout', flayout
122
- @log.level = log_level
75
+ begin
76
+ @@config = SiteHook::Config.log_levels
77
+ rescue Errno::ENOENT
78
+ raise NoConfigError path
79
+ rescue NoMethodError
123
80
 
124
- LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
125
81
  end
82
+
126
83
  end
127
84
 
128
- # Log Git Actions
129
- class GitLog
130
- attr :log
85
+ # @return [Access]
86
+ def self.access
87
+ Loggers::Access.new(base: 'SiteHook::Log::Access')
88
+ end
131
89
 
132
- def initialize(log_level = nil)
133
- LL.debug "Initializing #{SiteHook.safe_log_name(self)}"
134
- @log = Logging.logger[SiteHook.safe_log_name(self)]
135
- @log_level = log_level
90
+ # @return [Loggers::Fake]
91
+ def self.fake
92
+ Loggers::Fake.new
93
+ end
136
94
 
137
- flayout = Logging.appenders.rolling_file \
138
- Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
139
- :age => 'daily',
140
- :pattern => PATTERN
141
- @log.add_appenders 'stdout', flayout
142
- @log.level = log_level
143
- LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
144
- end
95
+ # @return [Loggers::Hook]
96
+ def self.hook
97
+ Loggers::Hook.new(level: @@config.hook, base: 'SiteHook::Log::Hook')
145
98
  end
146
99
 
147
- # Fake Logger for GitLog to preprocess output
148
- class FakeLog < StringIO
149
- attr :info_output, :debug_output
150
- def initialize
151
- @info_output = []
152
- @debug_output = []
153
- end
154
- # @param [Any] message message to log
155
- def info(message)
156
- case
157
- when message =~ /git .* pull/
158
- @info_output << "Starting Git"
159
- @debug_output << message
160
- else
161
- @debug_output << message
162
- end
163
- end
164
- # @param [Any] message message to log
165
- def debug(message)
166
- case
167
- when message =~ /\n/
168
- msgs = message.lines
169
- msgs.each do |msg|
170
- msg.squish!
171
- case
172
- when msg =~ /From (.*?):(.*?)\/(.*)(\.git)?/
173
- @info_output << "Pulling via #{$2}/#{$3} on #{$1}."
174
- when msg =~ /\* branch (.*?) -> .*/
175
- @info_output << "Using #{$1} branch"
176
- else
177
- @debug_output << msg
178
- end
179
- end
180
- else
181
- @debug_output << message
182
- end
183
- end
100
+ # @return [Loggers::Git]
101
+ def self.git
102
+ Loggers::Git.new(level: @@config.git, base: 'SiteHook::Log::Git')
103
+ end
184
104
 
185
- # @return [Hash] Hash of log entries
186
- def entries
187
- {
188
- info: @info_output,
189
- debug: @debug_output
190
- }
191
- end
105
+ # @return [Loggers::Build]
106
+ def self.build
107
+ Loggers::Build.new(level: @@config.build, base: 'SiteHook::Log::Build')
108
+ end
109
+
110
+ # @return [Loggers::App]
111
+ def self.app
112
+ Loggers::App.new(level: @@config.app, base: 'SiteHook::Log::App')
192
113
  end
193
114
  end
194
- end
115
+ end