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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rspec +0 -2
- data/.rubocop.yml +2 -0
- data/Gemfile +1 -5
- data/Rakefile +35 -3
- data/bin/site_hook +5 -1
- data/features/get_help.feature +3 -0
- data/features/step_definitions/get_help_step_definition.rb +1 -0
- data/features/step_definitions/my_steps.rb +3 -0
- data/features/support/env.rb +1 -0
- data/lib/site_hook.rb +2 -28
- data/lib/site_hook/cli.rb +22 -39
- data/lib/site_hook/commands/config_class.rb +22 -68
- data/lib/site_hook/commands/jekyll_class.rb +38 -0
- data/lib/site_hook/commands/server_class.rb +38 -34
- data/lib/site_hook/config.rb +390 -14
- data/lib/site_hook/config_sections.rb +60 -9
- data/lib/site_hook/deprecate.rb +34 -11
- data/lib/site_hook/env/env.rb +2 -0
- data/lib/site_hook/exceptions.rb +26 -2
- data/lib/site_hook/log.rb +20 -15
- data/lib/site_hook/logger.rb +94 -173
- data/lib/site_hook/loggers.rb +10 -0
- data/lib/site_hook/loggers/access.rb +20 -0
- data/lib/site_hook/loggers/app.rb +78 -0
- data/lib/site_hook/loggers/build.rb +77 -0
- data/lib/site_hook/loggers/fake.rb +52 -0
- data/lib/site_hook/loggers/git.rb +81 -0
- data/lib/site_hook/loggers/hook.rb +74 -0
- data/lib/site_hook/methods.rb +26 -0
- data/lib/site_hook/paths.rb +65 -2
- data/lib/site_hook/prelogger.rb +88 -0
- data/lib/site_hook/prompt.rb +14 -0
- data/lib/site_hook/prompts/prompt_project.rb +48 -0
- data/lib/site_hook/runner.rb +36 -0
- data/lib/site_hook/sender.rb +4 -9
- data/lib/site_hook/string_ext.rb +57 -0
- data/lib/site_hook/version.rb +2 -2
- data/lib/site_hook/webhook.rb +120 -129
- data/site_hook.gemspec +39 -22
- data/spec/spec_helper.rb +13 -0
- data/spec/string_ext_spec.rb +10 -0
- metadata +87 -85
- data/CODE_OF_CONDUCT.md +0 -74
- data/bin/console +0 -14
- data/lib/site_hook/assets/css/styles.css +0 -26
- data/lib/site_hook/commands/debug_class.rb +0 -29
- data/lib/site_hook/config_sections/cli.rb +0 -24
- data/lib/site_hook/config_sections/log_levels.rb +0 -15
- data/lib/site_hook/config_sections/projects.rb +0 -22
- data/lib/site_hook/const.rb +0 -10
- data/lib/site_hook/gem.rb +0 -26
- data/lib/site_hook/persist.rb +0 -14
- data/lib/site_hook/prompts/gen_config.rb +0 -48
- data/lib/site_hook/spinner.rb +0 -19
- data/lib/site_hook/views/layout.haml +0 -24
- data/lib/site_hook/views/webhooks.haml +0 -7
@@ -1,13 +1,64 @@
|
|
1
|
-
require 'yaml'
|
2
1
|
module SiteHook
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts
|
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
|
data/lib/site_hook/deprecate.rb
CHANGED
@@ -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
|
-
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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.
|
12
|
-
|
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.
|
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)
|
data/lib/site_hook/exceptions.rb
CHANGED
@@ -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
|
data/lib/site_hook/log.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
'hook' => 'info',
|
12
|
+
DEFAULT = {
|
13
|
+
'hook' => 'info',
|
10
14
|
'build' => 'info',
|
11
|
-
'git'
|
12
|
-
'app'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/site_hook/logger.rb
CHANGED
@@ -1,194 +1,115 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
#
|
129
|
-
|
130
|
-
|
85
|
+
# @return [Access]
|
86
|
+
def self.access
|
87
|
+
Loggers::Access.new(base: 'SiteHook::Log::Access')
|
88
|
+
end
|
131
89
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
90
|
+
# @return [Loggers::Fake]
|
91
|
+
def self.fake
|
92
|
+
Loggers::Fake.new
|
93
|
+
end
|
136
94
|
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
-
#
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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
|