site_hook 0.9.16 → 0.9.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 786e1546d93c5e357e19e206bff9d97d4bd0e532ef20f56a9f5e7c9228d11784
4
- data.tar.gz: 1169f46321516951906709d22b06e52bc848352167eb5454736e60b3dbc27e21
3
+ metadata.gz: '058b74bd66b905452e634bc863c081ed25db2c6168f23f82044aea362b1c2c11'
4
+ data.tar.gz: f80b40ceaa541a84b7ce423e71aa44cc4630c15625e5a9fb93dc65683f18c017
5
5
  SHA512:
6
- metadata.gz: 336543b8d3cea8ad7f938de0eb971bc0a3fc0b9f513a6fc0f39b1834fd540c7423ce83c394d8d0d5e49cc2f34d77781653e357505e663405e3108c32743feafa
7
- data.tar.gz: 014aaa2535911ba5cff4f0bb136294ad8ecea24bacdec6d6b2d7f7611c38b04d1e38aaef33ee821eef75e3a984ccdd857ae34319c2adbac35c6d242d3ac0c809
6
+ metadata.gz: fc442471bf2b8a7b689da756dfd5a054623d528fe94cf005e7025f820355ba30b37cc6e0c5b766450c5d0e423fb067584d2303f5c2fbd59e07a8539df123e56a
7
+ data.tar.gz: a290167d52b5e3985653d5bb0290156d3b7a4cf176c48f493cc90bb356aefbcc6e9b95b8d55a57f6cc11a6297884cb80bf16afe97707be54f19c2011dda1456d
data/lib/site_hook/cli.rb CHANGED
@@ -26,6 +26,8 @@ module SiteHook
26
26
  subcommand('server', SiteHook::Commands::ServerClass)
27
27
  desc 'jekyll [subcommand] [options]', 'run jekyll actions'
28
28
  subcommand('jekyll', SiteHook::Commands::JekyllClass)
29
+ desc 'init [subcommand] [options]', 'run init actions'
30
+ subcommand('init', SiteHook::Commands::InitClass)
29
31
 
30
32
  end
31
33
  end
@@ -1,50 +1,27 @@
1
- require 'thor'
2
- require 'random_password'
3
- require 'site_hook/config_sections'
1
+ require "thor"
2
+ require "random_password"
3
+ require "site_hook/config_sections"
4
+
4
5
  module SiteHook
5
6
  module Commands
6
-
7
7
  class ConfigClass < Thor
8
8
  # def __version
9
9
  # puts SiteHook::VERSION
10
10
  # end
11
11
  # map ['-v', '--version'] => __version
12
12
 
13
- desc 'gen [-o]', 'generate a sample config, -o will output to STDOUT instead of to the default config location'
14
- method_option(:output, type: :boolean, default: false, aliases: '-o')
15
- def gen
16
- unless SiteHook::Paths.default_config.exist?
17
- if options[:output] == true
18
- say SiteHook::ConfigSections.all_samples
19
- else
20
- File.open(SiteHook::Paths.config, 'w+') do |file|
21
- file.puts SiteHook::ConfigSections.all_samples
22
- end
23
- end
24
- else
25
- if options[:output] == true
26
- say SiteHook::ConfigSections.all_samples
27
- end
28
- if !SiteHook::Paths.default_config.exist?
29
- File.open(SiteHook::Paths.config, 'w+') do |file|
30
- file.puts SiteHook::ConfigSections.all_samples
31
- end
32
- end
33
- end
34
-
35
- end
36
-
37
- desc 'mkpass [options]', 'create a hook password'
38
- method_option(:length, type: :numeric, banner: 'LENGTH', aliases: ['-l'], default: 20)
13
+ desc "mkpass [options]", "create a hook password"
14
+ method_option(:length, type: :numeric, banner: "LENGTH", aliases: ["-l"], default: 20)
39
15
 
40
16
  def mkpass
41
17
  puts RandomPassword.new(length: options[:length]).generate
42
18
  end
43
19
 
44
- desc 'inspect [options]', 'output the configuration'
20
+ desc "inspect [options]", "output the configuration"
21
+
45
22
  def inspect
46
23
  puts SiteHook::Config.new.inspect
47
24
  end
48
25
  end
49
26
  end
50
- end
27
+ end
@@ -0,0 +1,38 @@
1
+ require "thor"
2
+ require "random_password"
3
+ require "site_hook/paths"
4
+ require "site_hook/config_sections"
5
+ require "tty-file"
6
+
7
+ module SiteHook
8
+ module Commands
9
+ class InitClass < Thor
10
+ include Thor::Actions
11
+ desc("all", "generate sample config and directories")
12
+
13
+ def all
14
+ invoke :create_shrc_dir
15
+ invoke :create_shrc_logs_dir
16
+ invoke :create_config_sample
17
+ end
18
+
19
+ desc "create_shrc_dir", "create the .shrc directory"
20
+
21
+ def create_shrc_dir
22
+ TTY::File.create_dir(SiteHook::Paths.dir)
23
+ end
24
+
25
+ desc "create_shrc_logs_dir", "create the .shrc/logs directory"
26
+
27
+ def create_shrc_logs_dir
28
+ TTY::File.create_dir(SiteHook::Paths.logs)
29
+ end
30
+
31
+ desc "create_config_sample", "create the config sample"
32
+
33
+ def create_config_sample
34
+ TTY::File.create_file(SiteHook::Paths.config, SiteHook::ConfigSections.all_samples)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -14,8 +14,8 @@ module SiteHook
14
14
  # puts SiteHook::VERSION
15
15
  # end
16
16
  # map ['-v', '--version'] => __version
17
- method_option(:host, banner: 'HOST', aliases: ['-h'], type: :string, default: SiteHook::Config.new.class.webhook.host)
18
- method_option(:port, banner: 'PORT', aliases: ['-p'], type: :numeric, default: SiteHook::Config.new.class.webhook.port)
17
+ # method_option(:host, banner: 'HOST', aliases: ['-h'], type: :string, default: SiteHook::Config.webhook.host)
18
+ # method_option(:port, banner: 'PORT', aliases: ['-p'], type: :numeric, default: SiteHook::Config.webhook.port)
19
19
  desc 'listen [options]', ''
20
20
  def listen
21
21
  $threads << Thread.new do
@@ -1,7 +1,8 @@
1
- require 'site_hook/paths'
2
- require 'yaml'
3
- require 'site_hook/string_ext'
4
- require 'site_hook/prelogger'
1
+ require "site_hook/paths"
2
+ require "yaml"
3
+ require "site_hook/string_ext"
4
+ require "site_hook/prelogger"
5
+
5
6
  module SiteHook
6
7
  class Config
7
8
  @@config = {}
@@ -47,14 +48,14 @@ module SiteHook
47
48
  # end
48
49
 
49
50
  def inspect
50
- meths = %i[webhook log_levels cli projects]
51
+ meths = %i[webhook log_levels cli projects]
51
52
  sections = {}
52
53
  meths.each do |m|
53
54
  sections[m] = self.class.send(m).inspect
54
55
  end
55
56
  secs = []
56
57
  sections.each { |name, instance| secs << "#{name}=#{instance}" }
57
- "#<SiteHook::Config #{secs.join(' ')}>"
58
+ "#<SiteHook::Config #{secs.join(" ")}>"
58
59
  end
59
60
 
60
61
  def self.reload!
@@ -70,64 +71,65 @@ module SiteHook
70
71
  end
71
72
 
72
73
  def initialize
73
- @@config = {}
74
+ @@config = {}
74
75
  @@filename = SiteHook::Paths.default_config
75
76
  begin
76
77
  @@config = YAML.load_file(@@filename)
77
78
  rescue Errno::ENOENT
79
+ PreLogger.error "ENOENT"
78
80
  raise SiteHook::NoConfigError.new @@filename
79
81
  rescue NoMethodError
80
- @@filename.empty?
82
+ PreLogger.error @@filename.empty?
81
83
  end
82
- rescue NoConfigError
83
- #SiteHook::Commands::ConfigClass.invoke()
84
- say SiteHook::Commands::ConfigClass.methods
85
- rescue NeitherConfigError
86
- #SiteHook::Commands::ConfigClass.invoke(:gen)
87
- say SiteHook::Commands::ConfigClass.methods
88
84
  end
89
85
 
90
86
  # @return [Webhook]
91
87
  def self.webhook
92
- Webhook.new(@@config['webhook'])
88
+ Webhook.new(@@config["webhook"])
93
89
  end
94
90
 
95
91
  # @return [Projects]
96
92
  def self.projects
97
- Projects.new(@@config['projects'])
93
+ Projects.new(@@config["projects"])
98
94
  end
99
95
 
100
96
  # @return [Cli]
101
97
  def self.cli
102
- Cli.new(@@config['cli'])
98
+ Cli.new(@@config["cli"])
103
99
  end
104
100
 
105
101
  # @return [LogLevels]
106
102
  def self.log_levels
107
- LogLevels.new(@@config['log_levels'])
103
+ LogLevels.new(@@config["log_levels"])
108
104
  end
109
105
  end
106
+
110
107
  class Webhook
111
108
  def initialize(config)
112
109
  config.each do |option, value|
113
110
  sec = StrExt.mkatvar(option)
114
111
  self.instance_variable_set(:"#{sec}", value)
112
+ sec2 = StrExt.mkatatvar(option)
113
+ self.class_variable_set(:"#{sec2}", value)
115
114
  end
116
115
  end
117
116
 
117
+ def self.host
118
+ end
119
+
118
120
  def host
119
- @host
121
+ @host || "0.0.0.0"
120
122
  end
121
123
 
122
124
  def port
123
- @port
125
+ @port || 9090
124
126
  end
125
127
 
126
128
  def inspect
127
129
  "#<SiteHook::Webhook host=#{host} port=#{port}>"
128
130
  end
129
-
130
131
  end
132
+
131
133
  class Projects
132
134
  def initialize(config)
133
135
  config.each do |project, options|
@@ -136,12 +138,11 @@ module SiteHook
136
138
  end
137
139
 
138
140
  def inspect
139
-
140
141
  output = []
141
142
  instance_variables.each do |project|
142
143
  output << "#{StrExt.rematvar(project)}=#{instance_variable_get(project).inspect}"
143
144
  end
144
- "#<SiteHook::Projects #{output.join(' ')}"
145
+ "#<SiteHook::Projects #{output.join(" ")}"
145
146
  end
146
147
 
147
148
  def find_project(name)
@@ -157,7 +158,6 @@ module SiteHook
157
158
  rescue NameError
158
159
  nil
159
160
  end
160
-
161
161
  end
162
162
 
163
163
  def get(project)
@@ -181,7 +181,7 @@ module SiteHook
181
181
  #
182
182
  # Collect project names that meet certain criteria
183
183
  def collect_public
184
- public_vars = instance_variables.reject do |project_var|
184
+ public_vars = instance_variables.reject do |project_var|
185
185
  instance_variable_get(project_var).private
186
186
  end
187
187
  public_projects = []
@@ -198,14 +198,13 @@ module SiteHook
198
198
  %i[src dst repo host private].each do |option|
199
199
  projects[project.name][option] = project.instance_variable_get(StrExt.mkatvar(option))
200
200
  end
201
-
202
201
  end
203
202
  projects
204
203
  end
205
204
 
206
205
  def each(&block)
207
206
  len1 = instance_variables.length
208
- x = 0
207
+ x = 0
209
208
  while x < len1
210
209
  base = self
211
210
  yield instance_variable_get(instance_variables[x])
@@ -217,11 +216,11 @@ module SiteHook
217
216
  instance_variables.length
218
217
  end
219
218
  end
219
+
220
220
  class LogLevels
221
221
  attr :app, :hook, :build, :git
222
222
 
223
223
  def initialize(config)
224
-
225
224
  LogLevels.defaults.each do |type, level|
226
225
  if config.fetch(type.to_s, nil)
227
226
  level(type.to_s, config.fetch(type.to_s))
@@ -233,7 +232,7 @@ module SiteHook
233
232
 
234
233
  def to_h
235
234
  output_hash = {}
236
- wanted = %i[app hook build git]
235
+ wanted = %i[app hook build git]
237
236
  wanted.each do |logger|
238
237
  output_hash.store(logger, instance_variable_get(StrExt.mkatvar(logger)))
239
238
  end
@@ -245,7 +244,7 @@ module SiteHook
245
244
  instance_variables.each do |var|
246
245
  levels << "#{StrExt.rematvar(var)}=#{self.instance_variable_get(var)}"
247
246
  end
248
- "#<SiteHook::LogLevels #{levels.join(' ')}>"
247
+ "#<SiteHook::LogLevels #{levels.join(" ")}>"
249
248
  end
250
249
 
251
250
  def fetch(key)
@@ -254,10 +253,10 @@ module SiteHook
254
253
 
255
254
  def self.defaults
256
255
  {
257
- app: 'info',
258
- hook: 'info',
259
- build: 'info',
260
- git: 'info',
256
+ app: "info",
257
+ hook: "info",
258
+ build: "info",
259
+ git: "info",
261
260
  }
262
261
  end
263
262
 
@@ -265,18 +264,19 @@ module SiteHook
265
264
  instance_variable_set(:"@#{type}", level)
266
265
  end
267
266
  end
267
+
268
268
  class Cli
269
269
  SECTIONS = {
270
- config: {
271
- mkpass: [:length, :symbols]
272
- },
273
- server: {
274
- # no host or port since those are set via Webhook
275
- # webhook:
276
- # host: 127.0.0.1
277
- # port: 9090
278
- #
279
- # TODO: Find options to put here
270
+ config: {
271
+ mkpass: [:length, :symbols],
272
+ },
273
+ server: {
274
+ # no host or port since those are set via Webhook
275
+ # webhook:
276
+ # host: 127.0.0.1
277
+ # port: 9090
278
+ #
279
+ # TODO: Find options to put here
280
280
  },
281
281
  }
282
282
 
@@ -296,12 +296,12 @@ module SiteHook
296
296
  end
297
297
 
298
298
  def inspect
299
- wanted = instance_variables
299
+ wanted = instance_variables
300
300
  outputs = []
301
301
  wanted.each do |meth|
302
302
  outputs << "#{StrExt.rematvar(meth)}=#{instance_variable_get(meth)}"
303
303
  end
304
- "#<SiteHook::Cli #{outputs.join(' ')}>"
304
+ "#<SiteHook::Cli #{outputs.join(" ")}>"
305
305
  end
306
306
  end
307
307
 
@@ -323,12 +323,12 @@ module SiteHook
323
323
  if instance_variable_get(StrExt.mkatvar(:config))
324
324
  # variable exists in configuration
325
325
  else
326
- instance_variable_set(StrExt.mkatvar(:config), '_config.yml')
326
+ instance_variable_set(StrExt.mkatvar(:config), "_config.yml")
327
327
  end
328
- if config.fetch('private', nil)
328
+ if config.fetch("private", nil)
329
329
  instance_variable_set(StrExt.mkatvar(option), value) unless instance_variables.include?(:@private)
330
330
  else
331
- instance_variable_set(StrExt.mkatvar('private'), false)
331
+ instance_variable_set(StrExt.mkatvar("private"), false)
332
332
  end
333
333
  end
334
334
  end
@@ -338,9 +338,10 @@ module SiteHook
338
338
  instance_variables.each do |sym|
339
339
  outputs << "#{StrExt.rematvar(sym)}=#{instance_variable_get(sym)}"
340
340
  end
341
- "#<SiteHook::Project #{outputs.join(' ')}>"
341
+ "#<SiteHook::Project #{outputs.join(" ")}>"
342
342
  end
343
343
  end
344
+
344
345
  class CliClasses
345
346
  class Config
346
347
  def initialize(config)
@@ -359,9 +360,10 @@ module SiteHook
359
360
  @configured_commands.each do |m, body|
360
361
  outputs << "#{m}=#{body}"
361
362
  end
362
- "#<SiteHook::Cli::Config #{outputs.join(' ')}>"
363
+ "#<SiteHook::Cli::Config #{outputs.join(" ")}>"
363
364
  end
364
365
  end
366
+
365
367
  class Server
366
368
  def initialize(config)
367
369
  @configured_commands = {}
@@ -379,9 +381,10 @@ module SiteHook
379
381
  @configured_commands.each do |m, body|
380
382
  outputs << "#{m}=#{body}"
381
383
  end
382
- "#<SiteHook::Cli::Server #{outputs.join(' ')}>"
384
+ "#<SiteHook::Cli::Server #{outputs.join(" ")}>"
383
385
  end
384
386
  end
387
+
385
388
  class Command
386
389
  attr_reader :name
387
390
 
@@ -390,7 +393,6 @@ module SiteHook
390
393
  options.each do |option, value|
391
394
  self.class.define_method(option.to_sym) do
392
395
  return value
393
-
394
396
  end
395
397
  end
396
398
  end
@@ -399,9 +401,10 @@ module SiteHook
399
401
  # Bleh
400
402
  end
401
403
  end
404
+
402
405
  class CommandOption
403
406
  def initialize(option, value)
404
407
  end
405
408
  end
406
409
  end
407
- end
410
+ end
@@ -1,7 +1,9 @@
1
1
  require 'paint/util'
2
2
  module SiteHook
3
3
 
4
+ # @returns SiteHook::DeprecationError
4
5
  class DeprecationError < SiteHookError
6
+ # @params [String] msg message to return
5
7
  def initialize(msg)
6
8
  super(msg, 99)
7
9
  end
@@ -9,7 +11,7 @@ module SiteHook
9
11
  class Deprecation
10
12
 
11
13
  def self.deprecate(command, situation, instructions, continue)
12
- @@exe_name = command.topmost_ancestor.parent.exe_name
14
+ @@exe_name = command
13
15
  @@str = "▼▼▼ [#{Paint['DEPRECATION ERROR', 'red', :bold]}] —— #{Paint['The following situation is deprecated', 'yellow', :bold, :blink]}! ▼▼▼"
14
16
  @@situation = situation
15
17
  @@str << "\n#{@@situation}"
@@ -22,8 +24,8 @@ module SiteHook
22
24
  return self.deprecate(
23
25
  command,
24
26
  "'#{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
+ <<-INSTRUCT,
28
+ Please run `site_hook config upgrade-shrc", 'red', :blink]}` to rectify this.
27
29
  Once version 1.0.0 is released, '#{Paint["#{SiteHook::Paths.config}", 'green']}' will
28
30
  be the only config file option, and '#{Paint["#{SiteHook::Paths.old_config}", 'orange']}' will not be allowed.
29
31
  any existance of '#{Paint["#{Dir.home}/.jph", 'red']}' after the #{Paint['1.0.0', :bold]} release will result in an Exception being raised.
@@ -41,7 +43,7 @@ module SiteHook
41
43
 
42
44
  def initialize(command)
43
45
  @command_object = command
44
- @exe_name = @command_object.topmost_ancestor.parent.exe_name
46
+ @exe_name = 'site_hook'
45
47
  @output_string = "Command `#{@exe_name} #{command.name_for_help.join(' ')}"
46
48
  end
47
49
  def self.declare(command)
@@ -1,33 +1,45 @@
1
- require 'paint'
1
+ require "paint"
2
+
2
3
  module SiteHook
3
4
  class SiteHookError < StandardError
5
+ attr :err, :status
6
+
4
7
  def initialize(msg, err)
8
+ @err = err
9
+ @status = @err
5
10
  super(msg)
6
- exit err
7
11
  end
8
12
  end
13
+
9
14
  class ConfigExistsError < SiteHookError
10
15
  end
16
+
11
17
  class NoConfigError < SiteHookError
12
18
  attr_reader :path
19
+
13
20
  def initialize(path)
14
- @str = "Config path '#{Paint[path, 'red']}' does not exist!"
15
- @path = path
16
- super(@str,98)
21
+ @str = "Config path '#{Paint[path, "red"]}' does not exist!"
22
+ @path = Pathname.new(path)
23
+ super(@str, 98)
17
24
  end
18
25
  end
26
+
19
27
  class NeitherConfigError < SiteHookError
20
28
  attr_reader :paths
29
+
21
30
  def initialize
22
31
  @str = "Neither '#{SiteHook::Paths.old_config}' nor '#{SiteHook::Paths.config}'"
32
+ super(@str, 99)
23
33
  end
24
34
  end
35
+
25
36
  class NoLogsError < SiteHookError
26
37
  attr_reader :path
38
+
27
39
  def initialize(path)
28
- @str = "Log path '#{Paint[path, 'red']}' does not exist!"
29
- @path = path
30
- super(@str,97)
40
+ @str = "Log path '#{Paint[path, "red"]}' does not exist!"
41
+ @path = Pathname.new(path)
42
+ super(@str, 97)
31
43
  end
32
44
  end
33
45
  end
@@ -1,90 +1,89 @@
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'
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
7
  #require 'site_hook/configs'
8
8
  module SiteHook
9
9
  class Log
10
10
  def self.defaults
11
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
- })
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
+ }
32
+ )
32
33
  end
33
34
 
34
35
  def self.validate(config)
35
- invalid_types = []
36
- valid_config_log_types = [
37
- 'hook',
38
- 'git',
39
- 'app',
40
- 'build'
36
+ invalid_types = []
37
+ valid_config_log_types = [
38
+ "hook",
39
+ "git",
40
+ "app",
41
+ "build",
41
42
  ]
42
43
  invalid_config_log_types = [
43
- 'access',
44
- 'fake'
44
+ "access",
45
+ "fake",
45
46
  ]
46
- config = config['log_levels']
47
- is_config_valid = config.all? do |x|
47
+ config = config["log_levels"]
48
+ is_config_valid = config.all? do |x|
48
49
  if valid_config_log_types.include? x
49
50
  true
51
+ elsif invalid_config_log_types.include? x
52
+ invalid_types << x
53
+ false
50
54
  else
51
- if invalid_config_log_types.include? x
52
- invalid_types << x
53
- false
54
- end
55
+ false
55
56
  end
56
57
  end
58
+
57
59
  unless is_config_valid
58
- raise ArgumentError "invalid log type(s) in config, [#{invalid_types.join(', ')}]"
60
+ raise ArgumentError "invalid log type(s) in config, [#{invalid_types.join(", ")}]"
59
61
  end
60
62
  end
61
63
 
62
64
  def inspect
63
- meths = %i[hook build git app fake access]
65
+ meths = %i[hook build git app fake access]
64
66
  sections = {}
65
67
  meths.each do |m|
66
68
  sections[m] = self.class.send(m).inspect
67
69
  end
68
70
  secs = []
69
71
  sections.each { |name, instance| secs << "#{name}=#{instance}" }
70
- "#<SiteHook::Log #{secs.join(' ')}>"
72
+ "#<SiteHook::Log #{secs.join(" ")}>"
71
73
  end
72
74
 
73
75
  def initialize(input, output, errput)
74
-
75
76
  begin
76
77
  @@config = SiteHook::Config.log_levels
77
78
  rescue Errno::ENOENT
78
79
  raise NoConfigError path
79
80
  rescue NoMethodError
80
-
81
81
  end
82
-
83
82
  end
84
83
 
85
84
  # @return [Access]
86
85
  def self.access
87
- Loggers::Access.new(base: 'SiteHook::Log::Access')
86
+ Loggers::Access.new(base: "SiteHook::Log::Access")
88
87
  end
89
88
 
90
89
  # @return [Loggers::Fake]
@@ -94,22 +93,22 @@ module SiteHook
94
93
 
95
94
  # @return [Loggers::Hook]
96
95
  def self.hook
97
- Loggers::Hook.new(level: @@config.hook, base: 'SiteHook::Log::Hook')
96
+ Loggers::Hook.new(level: @@config.hook, base: "SiteHook::Log::Hook")
98
97
  end
99
98
 
100
99
  # @return [Loggers::Git]
101
100
  def self.git
102
- Loggers::Git.new(level: @@config.git, base: 'SiteHook::Log::Git')
101
+ Loggers::Git.new(level: @@config.git, base: "SiteHook::Log::Git")
103
102
  end
104
103
 
105
104
  # @return [Loggers::Build]
106
105
  def self.build
107
- Loggers::Build.new(level: @@config.build, base: 'SiteHook::Log::Build')
106
+ Loggers::Build.new(level: @@config.build, base: "SiteHook::Log::Build")
108
107
  end
109
108
 
110
109
  # @return [Loggers::App]
111
110
  def self.app
112
- Loggers::App.new(level: @@config.app, base: 'SiteHook::Log::App')
111
+ Loggers::App.new(level: @@config.app, base: "SiteHook::Log::App")
113
112
  end
114
113
  end
115
- end
114
+ end
@@ -1,14 +1,34 @@
1
- require 'site_hook/config'
1
+ require "site_hook/config"
2
+
2
3
  module SiteHook
3
4
  class Methods
4
5
  def self.mklogdir
5
- path = SiteHook::Paths.default_logs
6
+ path = SiteHook::Paths.logs
6
7
  if path.exist?
8
+ STDERR.puts "'#{path}' exists, skipping.."
7
9
  # Path exists, don't do anything
8
10
  else
11
+ STDERR.puts "'#{path}' does not exist. Creating..."
9
12
  FileUtils.mkpath(path.to_s)
10
13
  end
11
14
  end
15
+ def self.mkconfdir
16
+ path = SiteHook::Paths.dir
17
+ if path.exist?
18
+ STDERR.puts "'#{path}' exists, skipping.."
19
+ else
20
+ STDERR.puts "'#{path}' does not exist. Creating..."
21
+ end
22
+ end
23
+ def self.mkconf
24
+ path = SiteHook::Paths.config
25
+ if path.exist?
26
+ STDERR.puts "'#{path}' exists, skipping.."
27
+ else
28
+ STDERR.puts "'#{path}' does not exist. Creating..."
29
+ TTY::File.create_file(path, SiteHook::ConfigSections.all_samples)
30
+ end
31
+ end
12
32
 
13
33
  # @param [String] hook_name the hook name as defined in the projects:... directive
14
34
  def self.find_hook(hook_name)
@@ -23,4 +43,4 @@ module SiteHook
23
43
  end
24
44
  end
25
45
  end
26
- end
46
+ end
@@ -6,75 +6,68 @@
6
6
  # -> Copyright (c) 2018 Ken Spencer
7
7
  # -> License: MIT
8
8
  ##########
9
- require 'site_hook/methods'
10
- require 'site_hook/exceptions'
11
- require 'site_hook/version'
9
+ require "site_hook/methods"
10
+ require "site_hook/exceptions"
11
+ require "site_hook/version"
12
+
12
13
  module SiteHook
13
14
  # Paths: Paths to gem resources and things
14
15
  class Paths
15
16
  def self.old_dir
16
- Pathname(Dir.home).join('.jph')
17
+ Pathname(Dir.home).join(".jph")
17
18
  end
18
19
  def self.old_config
19
- Pathname(Dir.home).join('.jph', 'config')
20
+ Pathname(Dir.home).join(".jph", "config")
20
21
  end
21
22
  def self.old_logs
22
- Pathname(Dir.home).join('.jph', 'logs')
23
+ Pathname(Dir.home).join(".jph", "logs")
23
24
  end
24
25
  def self.dir
25
- Pathname(Dir.home).join('.shrc')
26
+ Pathname(Dir.home).join(".shrc")
26
27
  end
27
28
  def self.config
28
- Pathname(Dir.home).join('.shrc', 'config')
29
+ Pathname(Dir.home).join(".shrc", "config")
29
30
  end
30
31
 
31
32
  def self.logs
32
- Pathname(Dir.home).join('.shrc', 'logs')
33
+ Pathname(Dir.home).join(".shrc", "logs")
33
34
  end
34
35
  def self.default_config(old_exists = self.old_config.exist?, new_exists = self.config.exist?)
35
- path = ''
36
- begin
36
+ path = ""
37
+ begin
37
38
  if old_exists
38
- path = self.old_config
39
+ SiteHook::Deprecation.deprecate_config("")
39
40
  else
40
41
  if new_exists
41
42
  path = self.config
42
43
  else
43
- raise SiteHook::NeitherConfigError.new
44
+ raise SiteHook::NoConfigError.new self.config
44
45
  end
45
46
  end
46
- rescue SiteHook::NeitherConfigError
47
- if self.dir.exist?
48
- path = self.config
49
- end
50
47
  end
51
48
  path
52
49
  end
53
50
  def self.default_logs(old_exists = self.old_logs.exist?, new_exists = self.logs.exist?)
54
- path = ''
55
- begin
56
- if old_exists
57
- path = self.old_logs
51
+ path = ""
52
+
53
+ if old_exists
54
+ path = self.old_logs
55
+ else
56
+ if new_exists
57
+ path = self.logs
58
58
  else
59
- if new_exists
60
- path = self.logs
61
- else
62
- raise SiteHook::NoLogsError.new path
63
- end
59
+ path = self.logs
60
+ STDERR.puts "#{path} does not exist"
64
61
  end
65
- rescue SiteHook::NoLogsError
66
- path = self.logs
67
62
  end
68
- path
69
63
  end
70
64
 
71
65
  def self.lib_dir
72
- if ENV['BUNDLE_GEMFILE']
73
- Pathname(ENV['BUNDLE_GEMFILE']).dirname.join('lib')
66
+ if ENV["BUNDLE_GEMFILE"]
67
+ Pathname(ENV["BUNDLE_GEMFILE"]).dirname.join("lib")
74
68
  else
75
- Pathname(::Gem.user_dir).join('gems', "site_hook-#{SiteHook::VERSION}", 'lib')
69
+ Pathname(::Gem.user_dir).join("gems", "site_hook-#{SiteHook::VERSION}", "lib")
76
70
  end
77
-
78
71
  end
79
72
  def self.make_log_name(klass, level = nil, old_exists = self.old_logs.exist?, new_exists = self.logs.exist?)
80
73
  if level
@@ -82,8 +75,12 @@ module SiteHook
82
75
  end
83
76
  case old_exists
84
77
  when true
85
- path = self.old_logs
86
- self.old_logs.join("#{klass.to_s.safe_log_name}#{level}.log")
78
+ SiteHook::Deprecation.deprecate(
79
+ "",
80
+ "The '.jph/**' directory and contents are now deprecated, and will start erroring and exiting.",
81
+ "Please use 'site_hook config upgrade-shrc' to upgrade your config to the newer '.shrc/**' folder style.",
82
+ false
83
+ )
87
84
  when false
88
85
  if new_exists
89
86
  self.logs.join("#{klass.to_s.safe_log_name}#{level}.log")
@@ -91,10 +88,7 @@ module SiteHook
91
88
  path ||= SiteHook::Paths.logs
92
89
  raise SiteHook::NoLogsError.new path
93
90
  end
94
-
95
91
  end
96
- rescue Errno::ENOENT => e
97
-
98
92
  end
99
93
  end
100
94
  end
@@ -9,6 +9,9 @@
9
9
  require 'site_hook/paths'
10
10
  module SiteHook
11
11
  class PreLogger
12
+ @@loggers = {}
13
+ @@levels = {}
14
+
12
15
  def initialize(input, output, errput)
13
16
  self.class.set_base_default
14
17
  @@levels = {
@@ -1,36 +1,48 @@
1
- require 'site_hook'
2
- require 'site_hook/logger'
1
+ require "site_hook"
2
+ require "site_hook/logger"
3
+
3
4
  module SiteHook
4
5
  class Runner
5
6
  def initialize(argv = ARGV, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
6
7
  @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
7
8
  end
9
+
8
10
  def execute!
9
- exit_code = begin
10
- $stderr = @stderr
11
- $stdin = @stdin
12
- $stdout = @stdout
11
+ begin
13
12
  SiteHook::PreLogger.new($stdin, $stdout, $stderr)
14
13
  SiteHook::Config.new
15
- SiteHook::Log.new($stdin, $stdout, $stderr)
16
- SiteHook::CLI.start(@argv)
17
- 0
18
-
19
- rescue StandardError => e
20
- b = e.backtrace
21
- STDERR.puts("#{b.shift}: #{e.message} (#{e.class})")
22
- STDERR.puts(b.map{|s| "\tfrom #{s}"}.join("\n"))
23
- 1
24
- rescue SystemExit => e
25
- STDERR.puts e.status
26
- 1
27
- ensure
28
-
29
- $stderr = STDERR
30
- $stdin = STDIN
31
- $stdout = STDOUT
14
+ rescue SiteHook::NoLogsError => e
15
+ FileUtils.mkpath(e.path)
16
+ rescue SiteHook::NoConfigError => e
17
+ TTY::File.create_file(e.path, SiteHook::ConfigSections.all_samples)
32
18
  end
19
+ exit_code = begin
20
+ $stderr = @stderr
21
+ $stdin = @stdin
22
+ $stdout = @stdout
23
+ SiteHook::PreLogger.new($stdin, $stdout, $stderr)
24
+ SiteHook::Config.new
25
+ SiteHook::Log.new($stdin, $stdout, $stderr)
26
+ SiteHook::CLI.start(@argv)
27
+ 0
28
+ rescue StandardError => e
29
+ b = e.backtrace
30
+ unless e.class == SiteHook::NoConfigError
31
+ STDERR.puts("#{b.shift}: #{e.message} (#{e.class})")
32
+ STDERR.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
33
+ 1
34
+ end
35
+ 0
36
+ rescue SystemExit => e
37
+ STDERR.puts e.backtrace
38
+ STDERR.puts e.status
39
+ 1
40
+ ensure
41
+ $stderr = STDERR
42
+ $stdin = STDIN
43
+ $stdout = STDOUT
44
+ end
33
45
  @kernel.exit(exit_code)
34
46
  end
35
47
  end
36
- end
48
+ end
@@ -0,0 +1,19 @@
1
+ require 'super_callbacks'
2
+ module SiteHook
3
+ module Templates
4
+ class Logs
5
+ include SuperCallbacks
6
+ before :created_log_log_header do
7
+ @@time = Time.now.utc.localtime.strftime("%Y%m%dT%H%M%SZ%Z")
8
+ end
9
+ ###
10
+ # Puts the log header to the start of the log files
11
+ # @param [String,File,Pathname] file file to
12
+ # @return NilClass
13
+ ###
14
+ def created_log_log_header
15
+ header = "### Log file created at #{@@time}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module SiteHook
2
- VERSION = '0.9.16'
2
+ VERSION = '0.9.19'
3
3
  end
data/site_hook.gemspec CHANGED
@@ -33,16 +33,17 @@ Gem::Specification.new do |spec|
33
33
  end
34
34
  spec.require_paths = ['lib']
35
35
  spec.add_dependency 'git', '~> 1.3'
36
- spec.add_dependency 'highline', '~> 2.0.1'
37
- spec.add_dependency 'grape', '~> 1.2.3'
36
+ spec.add_dependency 'grape-raketasks'
38
37
  spec.add_dependency 'grape-route-helpers', '~> 2.1'
38
+ spec.add_dependency 'grape', '~> 1.2.3'
39
+ spec.add_dependency 'highline', '~> 2.0.1'
39
40
  spec.add_dependency 'paint', '~> 2.0'
40
41
  spec.add_dependency 'random_password', '~> 0.1.1'
41
42
  spec.add_dependency 'recursive-open-struct', '~> 1.1'
42
43
  spec.add_dependency 'super_callbacks', '~> 1.3.1'
43
- spec.add_dependency 'thor', '~> 0.20.3'
44
- spec.add_dependency 'grape-raketasks'
45
44
  spec.add_dependency 'thin'
45
+ spec.add_dependency 'thor', '~> 0.20.3'
46
+ spec.add_dependency 'tty-file', '~> 0.8.0'
46
47
  spec.add_development_dependency 'rspec', '3.8.0'
47
48
  spec.add_development_dependency 'aruba', '~> 0.14.8'
48
49
  spec.add_development_dependency 'bundler', '~> 1.17.3', '< 2.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.16
4
+ version: 0.9.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Spencer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -25,19 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: highline
28
+ name: grape-raketasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: grape-route-helpers
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 2.0.1
47
+ version: '2.1'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 2.0.1
54
+ version: '2.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: grape
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +67,19 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: 1.2.3
55
69
  - !ruby/object:Gem::Dependency
56
- name: grape-route-helpers
70
+ name: highline
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '2.1'
75
+ version: 2.0.1
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '2.1'
82
+ version: 2.0.1
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: paint
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -123,47 +137,47 @@ dependencies:
123
137
  - !ruby/object:Gem::Version
124
138
  version: 1.3.1
125
139
  - !ruby/object:Gem::Dependency
126
- name: thor
140
+ name: thin
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - "~>"
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: 0.20.3
145
+ version: '0'
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - "~>"
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: 0.20.3
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
- name: grape-raketasks
154
+ name: thor
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: 0.20.3
146
160
  type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0'
166
+ version: 0.20.3
153
167
  - !ruby/object:Gem::Dependency
154
- name: thin
168
+ name: tty-file
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - ">="
171
+ - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0'
173
+ version: 0.8.0
160
174
  type: :runtime
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - ">="
178
+ - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0'
180
+ version: 0.8.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rspec
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -264,6 +278,7 @@ files:
264
278
  - lib/site_hook.rb
265
279
  - lib/site_hook/cli.rb
266
280
  - lib/site_hook/commands/config_class.rb
281
+ - lib/site_hook/commands/init_class.rb
267
282
  - lib/site_hook/commands/jekyll_class.rb
268
283
  - lib/site_hook/commands/server_class.rb
269
284
  - lib/site_hook/config.rb
@@ -288,6 +303,7 @@ files:
288
303
  - lib/site_hook/runner.rb
289
304
  - lib/site_hook/sender.rb
290
305
  - lib/site_hook/string_ext.rb
306
+ - lib/site_hook/templates/log_header.rb
291
307
  - lib/site_hook/version.rb
292
308
  - lib/site_hook/webhook.rb
293
309
  - site_hook.gemspec
@@ -326,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
342
  version: '0'
327
343
  requirements: []
328
344
  rubyforge_project:
329
- rubygems_version: 2.7.6.2
345
+ rubygems_version: 2.7.6
330
346
  signing_key:
331
347
  specification_version: 4
332
348
  summary: Catch a POST request from a git service push webhook and build a jekyll site.