site_hook 0.8.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 841978508b6330f36437b9ac39b99ed2eb0c94492838bc748bb870688c4cb203
|
4
|
+
data.tar.gz: 387b84aaab26fda6cdb6459f181b0e2346ca89b36d474b18a8be0319d05cf16b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f50358cdb39cec2d31904cf59d710814c776e810e71b6a30e8fdf880a0a92edc37a1c9f484d3ed207c97e6367f72ebaedb0e5bfa3b5f2cd77d679b0ef94b0c31
|
7
|
+
data.tar.gz: '04987f3d4c2f78d5f0cd42711bd1da021a87017e532c5225a6b8c170a3160a1f44ab233d0f8202e5261023e29f6ec7634a028cfba0f7d30ddda3e1f8c5dfcf2c'
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
|
-
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
group :dev do
|
5
|
-
gem 'pry', '~> 0.12.2'
|
6
|
-
end
|
2
|
+
# git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
7
3
|
# Specify your gem's dependencies in site_hook.gemspec
|
8
4
|
gemspec
|
data/Rakefile
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
|
-
|
4
|
+
begin
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'cucumber features')
|
7
|
+
rescue LoadError
|
8
|
+
# Don't worry about empty rescue
|
9
|
+
end
|
5
10
|
|
6
|
-
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
15
|
+
t.pattern = 'spec/**/*_spec.rb'
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
# Don't worry about empty rescue
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
require 'bundler'
|
23
|
+
Bundler.setup
|
24
|
+
require 'grape-route-helpers'
|
25
|
+
require 'grape-route-helpers/tasks'
|
26
|
+
require 'grape-raketasks'
|
27
|
+
require 'grape-raketasks/tasks'
|
28
|
+
|
29
|
+
desc 'load the Rake environment.'
|
30
|
+
task :environment do
|
31
|
+
require File.expand_path('lib/site_hook/env/env.rb', File.dirname(__FILE__))
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run tests and setup"
|
35
|
+
tasks = %i[spec cucumber]
|
36
|
+
task default: tasks
|
37
|
+
desc 'run tests'
|
38
|
+
task tests: %i[spec cucumber]
|
data/bin/site_hook
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
data/lib/site_hook.rb
CHANGED
@@ -1,29 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'site_hook/version'
|
4
|
-
require 'site_hook/sender'
|
5
|
-
require 'site_hook/gem'
|
6
|
-
require 'site_hook/log'
|
7
|
-
require 'site_hook/logger'
|
8
|
-
require 'site_hook/spinner'
|
9
|
-
require 'recursive-open-struct'
|
10
1
|
require 'site_hook/cli'
|
11
|
-
require '
|
12
|
-
|
13
|
-
require 'json'
|
14
|
-
require 'sinatra/json'
|
15
|
-
require 'yaml'
|
16
|
-
|
17
|
-
module SiteHook
|
18
|
-
autoload :Logs, 'site_hook/log'
|
19
|
-
autoload :Gem, 'site_hook/gem'
|
20
|
-
autoload :Paths, 'site_hook/paths'
|
21
|
-
# class CoffeeHandler (inherits from Sinatra::Base)
|
22
|
-
class CoffeeHandler < Sinatra::Base
|
23
|
-
set :views, Pathname(app_file).dirname.join('site_hook', 'static', 'coffee').to_s
|
24
|
-
get '/js/*.js' do
|
25
|
-
filename = params[:splat].first
|
26
|
-
coffee filename.to_sym
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
2
|
+
require 'highline'
|
3
|
+
HighLine::Menu.index_color = :rgb_84DE02
|
data/lib/site_hook/cli.rb
CHANGED
@@ -1,48 +1,31 @@
|
|
1
|
-
require '
|
1
|
+
require 'thor'
|
2
2
|
require 'highline'
|
3
3
|
require 'paint'
|
4
4
|
require 'pathname'
|
5
|
+
require 'site_hook/paths'
|
5
6
|
require 'site_hook/exceptions'
|
6
7
|
require 'site_hook/deprecate'
|
8
|
+
commands = SiteHook::Paths.lib_dir.join('site_hook/commands').children
|
9
|
+
commands.each do |filename|
|
10
|
+
next if filename == '.' or filename == '..'
|
11
|
+
f = filename.dirname
|
12
|
+
require "#{f + filename.basename('.*')}"
|
13
|
+
end
|
14
|
+
|
7
15
|
module SiteHook
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# projects are in .shrc/config
|
13
|
-
commands_from 'site_hook/commands'
|
14
|
-
desc 'Print info on the gem.'
|
15
|
-
command 'gem-info' do |c|
|
16
|
-
c.action do |global_options, options, arguments|
|
17
|
-
@hl.say "Gem Name: #{SiteHook::Gem::Info.name}"
|
18
|
-
@hl.say "Gem Constant: #{SiteHook::Gem::Info.constant_name}"
|
19
|
-
@hl.say "Gem Author: #{SiteHook::Gem::Info.author}"
|
20
|
-
@hl.say "Gem Version: v#{SiteHook::VERSION}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
around do |global_options, command, options, args, code|
|
24
|
-
@config_hash = YAML.load_file(SiteHook::Paths.config) || YAML.load_file(SiteHook::Paths.old_config)
|
25
|
-
@hl = HighLine.new(STDIN, STDOUT, 80, 1, 2, 0)
|
26
|
-
code.call
|
16
|
+
class CLI < Thor
|
17
|
+
desc '--version, -v', 'returns version and exits'
|
18
|
+
def __version
|
19
|
+
puts SiteHook::VERSION
|
27
20
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
any existance of ~/.jph after the 1.0.0 release will result in an Exception being raised.
|
37
|
-
Once the exception is raised, site_hook will exit and return a 99 status code.
|
38
|
-
INSTRUCT
|
39
|
-
true
|
21
|
+
map ['-v', '--version'] => :__version
|
22
|
+
|
23
|
+
desc 'config [subcommand] [options]', 'configure site_hook'
|
24
|
+
subcommand('config', SiteHook::Commands::ConfigClass)
|
25
|
+
desc 'server [subcommand] [options]', 'run server actions'
|
26
|
+
subcommand('server', SiteHook::Commands::ServerClass)
|
27
|
+
desc 'jekyll [subcommand] [options]', 'run jekyll actions'
|
28
|
+
subcommand('jekyll', SiteHook::Commands::JekyllClass)
|
40
29
|
|
41
|
-
)
|
42
|
-
continue
|
43
|
-
else
|
44
|
-
# don't do anything
|
45
|
-
end
|
46
|
-
end
|
47
30
|
end
|
48
|
-
end
|
31
|
+
end
|
@@ -1,81 +1,35 @@
|
|
1
|
-
require '
|
2
|
-
require 'highline'
|
1
|
+
require 'thor'
|
3
2
|
require 'random_password'
|
4
|
-
require '
|
5
|
-
require 'site_hook/config'
|
3
|
+
require 'site_hook/config_sections'
|
6
4
|
module SiteHook
|
5
|
+
module Commands
|
7
6
|
|
7
|
+
class ConfigClass < Thor
|
8
|
+
# def __version
|
9
|
+
# puts SiteHook::VERSION
|
10
|
+
# end
|
11
|
+
# map ['-v', '--version'] => __version
|
8
12
|
|
9
|
-
|
10
|
-
#
|
11
|
-
# Holds all of the commands for the config subcommand
|
12
|
-
class App
|
13
|
-
extend GLI::App
|
13
|
+
desc 'gen [options]', 'generate a sample config'
|
14
14
|
|
15
|
-
|
15
|
+
def gen
|
16
|
+
if SiteHook::Paths.default_config.exist?
|
17
|
+
puts SiteHook::ConfigSections.all_samples
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
command 'config' do |c|
|
19
|
-
c.command 'gen' do |gen|
|
20
|
-
gen.desc "Generate a example config file if one doesn't exist"
|
21
|
-
gen.action do |global_options, options, arguments|
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
'log_levels:',
|
26
|
-
' hook: info',
|
27
|
-
' build: info',
|
28
|
-
' git: info',
|
29
|
-
' app: info',
|
22
|
+
desc 'mkpass [options]', 'create a hook password'
|
23
|
+
method_option(:length, type: :numeric, banner: 'LENGTH', aliases: ['-l'], default: 20)
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
if shrc.exist?
|
34
|
-
puts "#{shrc} exists. Will not overwrite."
|
35
|
-
else
|
36
|
-
File.open(shrc, 'w') do |f|
|
37
|
-
yaml.each do |line|
|
38
|
-
f.puts line
|
39
|
-
end
|
40
|
-
end
|
41
|
-
say "Created #{shrc}"
|
42
|
-
say "You can now edit #{shrc} and add your projects."
|
43
|
-
end
|
44
|
-
end
|
25
|
+
def mkpass
|
26
|
+
puts RandomPassword.new(length: options[:length]).generate
|
45
27
|
end
|
46
|
-
desc 'generates a project block'
|
47
|
-
c.command 'gen-project' do |gen_project|
|
48
|
-
gen_project.action do |global_options, options, arguments|
|
49
|
-
SiteHook::NotImplemented.declare(gen_project)
|
50
|
-
# puts tpl
|
51
|
-
end
|
52
|
-
end
|
53
|
-
c.command 'add-project' do |add_project|
|
54
|
-
add_project.action do |global_options, options, arguments|
|
55
|
-
# @config_hash = SiteHook::Config::Set.new(SiteHook::Paths.config)
|
56
|
-
SiteHook::NotImplemented.declare(add_project)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
c.command 'mkpass' do |mkpass|
|
61
|
-
mkpass.flag('symbol-amt', arg_name: 'AMT', type: Integer, default_value: 0)
|
62
|
-
mkpass.flag('length', arg_name: 'LENGTH', type: Integer, default_value: 10)
|
63
|
-
mkpass.action do |global_options, options, arguments|
|
64
28
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
else
|
69
|
-
help_now! "Symbols amount must be between '0' and '128'."
|
70
|
-
end
|
71
|
-
else
|
72
|
-
help_now! "Length must be a positive 'Integer' between '8' and '255'"
|
73
|
-
end
|
74
|
-
end
|
29
|
+
desc 'inspect [options]', 'output the configuration'
|
30
|
+
def inspect
|
31
|
+
puts SiteHook::Config.new.inspect
|
75
32
|
end
|
76
33
|
end
|
77
34
|
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
# rubocop:enable Metrics/AbcSize
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'random_password'
|
3
|
+
require 'site_hook/config_sections'
|
4
|
+
require 'site_hook/sender'
|
5
|
+
module SiteHook
|
6
|
+
module Commands
|
7
|
+
|
8
|
+
class JekyllClass < Thor
|
9
|
+
# def __version
|
10
|
+
# puts SiteHook::VERSION
|
11
|
+
# end
|
12
|
+
# map ['-v', '--version'] => __version
|
13
|
+
|
14
|
+
desc 'build [options]', 'build sites'
|
15
|
+
|
16
|
+
def build(project_name)
|
17
|
+
if SiteHook::Paths.default_config.exist?
|
18
|
+
begin
|
19
|
+
project = SiteHook::Config.projects.send(StrExt.mkvar(project_name))
|
20
|
+
jekyll_status = SiteHook::Senders::Jekyll.build(project['src'], project['dst'], SiteHook::Log::Build, options: {config: project['config']})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'mkpass [options]', 'create a hook password'
|
26
|
+
method_option(:length, type: :numeric, banner: 'LENGTH', aliases: ['-l'], default: 20)
|
27
|
+
|
28
|
+
def mkpass
|
29
|
+
puts RandomPassword.new(length: options[:length]).generate
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'inspect [options]', 'output the configuration'
|
33
|
+
def inspect
|
34
|
+
puts SiteHook::Config.new.inspect
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,39 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
##########
|
9
|
-
require 'site_hook/persist'
|
10
|
-
require 'site_hook/paths'
|
11
|
-
require 'site_hook/const'
|
12
|
-
require 'gli'
|
1
|
+
require 'thor'
|
2
|
+
require 'grape'
|
3
|
+
require 'grape-route-helpers'
|
4
|
+
require 'site_hook/webhook'
|
5
|
+
require 'rack'
|
6
|
+
require 'site_hook/config'
|
7
|
+
SiteHook::Config.new
|
13
8
|
module SiteHook
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
SiteHook.mklogdir unless SiteHook::Paths.logs.exist?
|
32
|
-
SiteHook::Webhook.run!
|
9
|
+
module Commands
|
10
|
+
class ServerClass < Thor
|
11
|
+
# def __version
|
12
|
+
# puts SiteHook::VERSION
|
13
|
+
# end
|
14
|
+
# map ['-v', '--version'] => __version
|
15
|
+
method_option(:host, banner: 'HOST', aliases: ['-h'], type: :string, default: SiteHook::Config.webhook.host)
|
16
|
+
method_option(:port, banner: 'PORT', aliases: ['-p'], type: :numeric, default: SiteHook::Config.webhook.port)
|
17
|
+
desc 'listen [options]', ''
|
18
|
+
def listen
|
19
|
+
$threads << Thread.new do
|
20
|
+
Rack::Server.start(
|
21
|
+
app: SiteHook::Server,
|
22
|
+
Host: options[:host],
|
23
|
+
Port: options[:port],
|
24
|
+
debug: true
|
25
|
+
)
|
33
26
|
end
|
27
|
+
$threads << Thread.new do
|
28
|
+
loop do
|
29
|
+
case $stdin.gets
|
30
|
+
when "reload\n"
|
31
|
+
::SiteHook::Config.reload!
|
32
|
+
when "quit\n"
|
33
|
+
$threads.each do |thr|
|
34
|
+
thr == Thread.current ? exit(0) : thr.exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
$threads.each(&:join)
|
34
40
|
end
|
35
41
|
end
|
36
|
-
|
37
42
|
end
|
38
|
-
end
|
39
|
-
# rubocop:enable Metrics/AbcSize
|
43
|
+
end
|
data/lib/site_hook/config.rb
CHANGED
@@ -1,23 +1,399 @@
|
|
1
1
|
require 'site_hook/paths'
|
2
|
-
require '
|
3
|
-
|
2
|
+
require 'yaml'
|
3
|
+
require 'site_hook/string_ext'
|
4
|
+
require 'site_hook/prelogger'
|
4
5
|
module SiteHook
|
5
6
|
class Config
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# def self.validate(config)
|
8
|
+
# config.each do |section, hsh|
|
9
|
+
# case section.to_s
|
10
|
+
# when 'webhook'
|
11
|
+
# if hsh['port']
|
12
|
+
# port_validity = [
|
13
|
+
# hsh['port'].respond_to?(:to_i),
|
14
|
+
# hsh['port'].is_a?(Integer)
|
15
|
+
# ].drop_while(&:!)
|
16
|
+
# SiteHook::PreLogger.debug port_validity
|
17
|
+
# else
|
18
|
+
# raise InvalidConfigError 'webhook', index
|
19
|
+
# end
|
20
|
+
# if hsh['host']
|
21
|
+
# host_validity = [
|
22
|
+
# hsh['host'].respond_to?(:to_s)
|
23
|
+
#
|
24
|
+
# ]
|
25
|
+
# end
|
26
|
+
# [port_validity]
|
27
|
+
# when 'log_levels'
|
28
|
+
#
|
29
|
+
# when 'cli'
|
30
|
+
# when 'projects'
|
31
|
+
# when 'out'
|
32
|
+
# if hsh['out'].keys
|
33
|
+
# hsh['out'].keys.each do |key|
|
34
|
+
# case key
|
35
|
+
# when 'discord'
|
36
|
+
# when 'irc'
|
37
|
+
# else
|
38
|
+
# raise InvalidConfigError 'out', "#{key} is an invalid out service"
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# else
|
43
|
+
# raise UnknownFieldError section
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
def inspect
|
49
|
+
meths = %i[webhook log_levels cli projects]
|
50
|
+
sections = {}
|
51
|
+
meths.each do |m|
|
52
|
+
sections[m] = self.class.send(m).inspect
|
53
|
+
end
|
54
|
+
secs = []
|
55
|
+
sections.each { |name, instance| secs << "#{name}=#{instance}" }
|
56
|
+
"#<SiteHook::Config #{secs.join(' ')}>"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.reload!
|
60
|
+
@@config = YAML.load_file(@@filename)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.filename
|
64
|
+
@@filename
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.config
|
68
|
+
self.new
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize
|
72
|
+
@@config = {}
|
73
|
+
@@filename = SiteHook::Paths.default_config
|
74
|
+
begin
|
75
|
+
@@config = YAML.load_file(@@filename)
|
76
|
+
rescue Errno::ENOENT
|
77
|
+
raise NoConfigError path
|
78
|
+
rescue NoMethodError
|
79
|
+
@@filename.empty?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# @return [Webhook]
|
84
|
+
def self.webhook
|
85
|
+
Webhook.new(@@config['webhook'])
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [Projects]
|
89
|
+
def self.projects
|
90
|
+
Projects.new(@@config['projects'])
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [Cli]
|
94
|
+
def self.cli
|
95
|
+
Cli.new(@@config['cli'])
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [LogLevels]
|
99
|
+
def self.log_levels
|
100
|
+
LogLevels.new(@@config['log_levels'])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
class Webhook
|
104
|
+
def initialize(config)
|
105
|
+
config.each do |option, value|
|
106
|
+
sec = StrExt.mkatvar(option)
|
107
|
+
self.instance_variable_set(:"#{sec}", value)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def host
|
112
|
+
@host
|
113
|
+
end
|
114
|
+
|
115
|
+
def port
|
116
|
+
@port
|
117
|
+
end
|
118
|
+
|
119
|
+
def inspect
|
120
|
+
"#<SiteHook::Webhook host=#{host} port=#{port}>"
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
class Projects
|
125
|
+
def initialize(config)
|
126
|
+
config.each do |project, options|
|
127
|
+
instance_variable_set(StrExt.mkatvar(StrExt.mkvar(project)), Project.new(project, options))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def inspect
|
132
|
+
|
133
|
+
output = []
|
134
|
+
instance_variables.each do |project|
|
135
|
+
output << "#{StrExt.rematvar(project)}=#{instance_variable_get(project).inspect}"
|
13
136
|
end
|
137
|
+
"#<SiteHook::Projects #{output.join(' ')}"
|
138
|
+
end
|
14
139
|
|
140
|
+
def find_project(name)
|
141
|
+
public_vars = instance_variables.reject do |project_var|
|
142
|
+
instance_variable_get(project_var).private
|
143
|
+
end
|
144
|
+
project_obj = public_vars.select do |project|
|
145
|
+
project == StrExt.mkatvar(StrExt.mkvar(name))
|
146
|
+
end
|
147
|
+
project_obj = project_obj.join
|
148
|
+
begin
|
149
|
+
instance_variable_get(project_obj)
|
150
|
+
rescue NameError
|
151
|
+
nil
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
def get(project)
|
157
|
+
if instance_variables.empty?
|
158
|
+
return :no_projects
|
159
|
+
end
|
160
|
+
vars = instance_variables.select do |name|
|
161
|
+
name == StrExt.mkatvar(StrExt.mkvar(project))
|
162
|
+
end
|
163
|
+
if vars.empty?
|
164
|
+
return :not_found
|
165
|
+
end
|
166
|
+
obj = vars.join
|
167
|
+
begin
|
168
|
+
instance_variable_get(obj)
|
169
|
+
rescue NameError => e
|
170
|
+
return :not_found
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# Collect project names that meet certain criteria
|
176
|
+
def collect_public
|
177
|
+
public_vars = instance_variables.reject do |project_var|
|
178
|
+
instance_variable_get(project_var).private
|
179
|
+
end
|
180
|
+
public_projects = []
|
181
|
+
public_vars.each do |var|
|
182
|
+
public_projects << instance_variable_get(var)
|
183
|
+
end
|
184
|
+
public_projects
|
185
|
+
end
|
186
|
+
|
187
|
+
def to_h
|
188
|
+
projects = {}
|
189
|
+
each do |project|
|
190
|
+
projects[project.name] = {}
|
191
|
+
%i[src dst repo host].each do |option|
|
192
|
+
projects[project.name][option] = project.instance_variable_get(StrExt.mkatvar(option))
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
projects
|
197
|
+
end
|
198
|
+
|
199
|
+
def each(&block)
|
200
|
+
len1 = instance_variables.length
|
201
|
+
x = 0
|
202
|
+
while x < len1
|
203
|
+
base = self
|
204
|
+
yield instance_variable_get(instance_variables[x])
|
205
|
+
x += 1
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def self.length
|
210
|
+
instance_variables.length
|
211
|
+
end
|
212
|
+
end
|
213
|
+
class LogLevels
|
214
|
+
attr :app, :hook, :build, :git
|
215
|
+
|
216
|
+
def initialize(config)
|
217
|
+
|
218
|
+
LogLevels.defaults.each do |type, level|
|
219
|
+
if config.fetch(type.to_s, nil)
|
220
|
+
level(type.to_s, config.fetch(type.to_s))
|
221
|
+
else
|
222
|
+
level(type.to_s, level)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def to_h
|
228
|
+
output_hash = {}
|
229
|
+
wanted = %i[app hook build git]
|
230
|
+
wanted.each do |logger|
|
231
|
+
output_hash.store(logger, instance_variable_get(StrExt.mkatvar(logger)))
|
232
|
+
end
|
233
|
+
output_hash
|
234
|
+
end
|
235
|
+
|
236
|
+
def inspect
|
237
|
+
levels = []
|
238
|
+
instance_variables.each do |var|
|
239
|
+
levels << "#{StrExt.rematvar(var)}=#{self.instance_variable_get(var)}"
|
240
|
+
end
|
241
|
+
"#<SiteHook::LogLevels #{levels.join(' ')}>"
|
242
|
+
end
|
243
|
+
|
244
|
+
def fetch(key)
|
245
|
+
instance_variable_get(:"@#{key}")
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.defaults
|
249
|
+
{
|
250
|
+
app: 'info',
|
251
|
+
hook: 'info',
|
252
|
+
build: 'info',
|
253
|
+
git: 'info',
|
254
|
+
}
|
255
|
+
end
|
256
|
+
|
257
|
+
def level(type, level)
|
258
|
+
instance_variable_set(:"@#{type}", level)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
class Cli
|
262
|
+
SECTIONS = {
|
263
|
+
config: {
|
264
|
+
mkpass: [:length, :symbols]
|
265
|
+
},
|
266
|
+
server: {
|
267
|
+
# no host or port since those are set via Webhook
|
268
|
+
# webhook:
|
269
|
+
# host: 127.0.0.1
|
270
|
+
# port: 9090
|
271
|
+
#
|
272
|
+
# TODO: Find options to put here
|
273
|
+
},
|
274
|
+
}
|
275
|
+
|
276
|
+
def initialize(config)
|
277
|
+
# super
|
278
|
+
config.each do |sec, values|
|
279
|
+
instance_variable_set(StrExt.mkatvar(sec), values) unless values.empty?
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def server
|
284
|
+
CliClasses::Server.new(@server)
|
285
|
+
end
|
286
|
+
|
287
|
+
def config
|
288
|
+
CliClasses::Config.new(@config)
|
289
|
+
end
|
290
|
+
|
291
|
+
def inspect
|
292
|
+
wanted = instance_variables
|
293
|
+
outputs = []
|
294
|
+
wanted.each do |meth|
|
295
|
+
outputs << "#{StrExt.rematvar(meth)}=#{instance_variable_get(meth)}"
|
296
|
+
end
|
297
|
+
"#<SiteHook::Cli #{outputs.join(' ')}>"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
##
|
302
|
+
# Internal Classes for each section
|
303
|
+
#
|
304
|
+
# Projects:
|
305
|
+
# Project
|
306
|
+
# Cli:
|
307
|
+
# Command
|
308
|
+
#
|
309
|
+
class Project
|
310
|
+
attr_reader :name, :src, :dst, :host, :repo, :hookpass, :private, :config
|
311
|
+
|
312
|
+
def initialize(name, config)
|
313
|
+
@name = name.to_s
|
314
|
+
config.each do |option, value|
|
315
|
+
instance_variable_set(StrExt.mkatvar(option), value)
|
316
|
+
if instance_variable_get(StrExt.mkatvar(:config))
|
317
|
+
# variable exists in configuration
|
318
|
+
else
|
319
|
+
instance_variable_set(StrExt.mkatvar(:config), '_config.yml')
|
320
|
+
end
|
321
|
+
if config.fetch('private', nil)
|
322
|
+
instance_variable_set(StrExt.mkatvar(option), value) unless instance_variables.include?(:@private)
|
323
|
+
else
|
324
|
+
instance_variable_set(StrExt.mkatvar('private'), false)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def inspect
|
330
|
+
outputs = []
|
331
|
+
instance_variables.each do |sym|
|
332
|
+
outputs << "#{StrExt.rematvar(sym)}=#{instance_variable_get(sym)}"
|
333
|
+
end
|
334
|
+
"#<SiteHook::Project #{outputs.join(' ')}>"
|
335
|
+
end
|
336
|
+
end
|
337
|
+
class CliClasses
|
338
|
+
class Config
|
339
|
+
def initialize(config)
|
340
|
+
@configured_commands = {}
|
341
|
+
config.each do |command, values|
|
342
|
+
@configured_commands.store(command, values)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def mkpass
|
347
|
+
Command.new(:mkpass, @configured_commands[:mkpass])
|
348
|
+
end
|
349
|
+
|
350
|
+
def inspect
|
351
|
+
outputs = []
|
352
|
+
@configured_commands.each do |m, body|
|
353
|
+
outputs << "#{m}=#{body}"
|
354
|
+
end
|
355
|
+
"#<SiteHook::Cli::Config #{outputs.join(' ')}>"
|
356
|
+
end
|
357
|
+
end
|
358
|
+
class Server
|
359
|
+
def initialize(config)
|
360
|
+
@configured_commands = {}
|
361
|
+
config.each do |command, values|
|
362
|
+
@configured_commands.store(command, values)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
def listen
|
367
|
+
Command.new(:listen, @configured_commands[:listen])
|
368
|
+
end
|
369
|
+
|
370
|
+
def inspect
|
371
|
+
outputs = []
|
372
|
+
@configured_commands.each do |m, body|
|
373
|
+
outputs << "#{m}=#{body}"
|
374
|
+
end
|
375
|
+
"#<SiteHook::Cli::Server #{outputs.join(' ')}>"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
class Command
|
379
|
+
attr_reader :name
|
380
|
+
|
381
|
+
def initialize(name, options)
|
382
|
+
@name = name
|
383
|
+
options.each do |option, value|
|
384
|
+
self.class.define_method(option.to_sym) do
|
385
|
+
return value
|
386
|
+
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
def inspect
|
392
|
+
# Bleh
|
393
|
+
end
|
15
394
|
end
|
16
|
-
class
|
17
|
-
|
18
|
-
def initialize(cfg_path)
|
19
|
-
@filename = cfg_path
|
20
|
-
@config = YAML.load_file(@filename)
|
395
|
+
class CommandOption
|
396
|
+
def initialize(option, value)
|
21
397
|
end
|
22
398
|
end
|
23
399
|
end
|