site_hook 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faa8b1808f36f0c69588f9590568133fb9b2a6288a3077d9aba94d197786c3ee
4
- data.tar.gz: 1972b2bb6b896b69b06b9967a9e21faf175e0f1dff4165859a7a71bec018098c
3
+ metadata.gz: a6a341dfc4c29d1ba33d5674d7b21fa24745a87d604aae643ffc941ed240d8f9
4
+ data.tar.gz: be30f028fd77aae806735990684028730a4a7f22662c1ecdb43cb56e7b4dc4c7
5
5
  SHA512:
6
- metadata.gz: 1dce31e06943728aa637c941bedc4baac41bed34010d1bc90b5749d509605a048400e926a42dd1392577b216e2fde6cc93bb80a1b875529f8fdcbe46bde8f96e
7
- data.tar.gz: 8b4948f0045924d7b2b802accd893d7da2c2978daa75966253e55284cbaa8584296854c12b81b1b000650761d087de1b243977750074d11ea018527fbbd7215e
6
+ metadata.gz: bef8e3ca33ea496f5ee60fad7a5c050a8d05acce7fbdfad5a79d855652825c2d8797c0aa342c5c925892abe52e4417a820a78da1ce2817daf172f9b91ae4e46b
7
+ data.tar.gz: fb3a74d336c1c6e7c5297b2ef6c6ef1edcf475c9f15e1f7e2c17b4704a4af24d55fab584e5e42b5f8d08d06fc44bd0233b1e34c46dfd5c0c57e70d8a4cf49a4d
data/.gitignore CHANGED
@@ -11,4 +11,6 @@
11
11
  /vendor
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
- Gemfile.lock
14
+ Gemfile.lock
15
+ vendor/
16
+ /.scannerwork
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
4
+ group :dev do
5
+ gem 'pry', '~> 0.12.2'
6
+ end
5
7
  # Specify your gem's dependencies in site_hook.gemspec
6
8
  gemspec
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:test)
5
5
 
6
- task :default => :spec
6
+ task :default => :test
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'site_hook'
4
- SiteHook::CLI.start(ARGV)
3
+ exit SiteHook::App.run(ARGV)
@@ -10,7 +10,6 @@ require 'recursive-open-struct'
10
10
  require 'site_hook/cli'
11
11
  require 'sinatra'
12
12
  require 'haml'
13
- require 'sass'
14
13
  require 'json'
15
14
  require 'sinatra/json'
16
15
  require 'yaml'
@@ -19,18 +18,6 @@ module SiteHook
19
18
  autoload :Logs, 'site_hook/log'
20
19
  autoload :Gem, 'site_hook/gem'
21
20
  autoload :Paths, 'site_hook/paths'
22
- # class SassHandler (inherits from Sinatra::Base)
23
- module_function
24
- def self.set_options(name, value)
25
- SiteHook.const_set("#{name.upcase}", value)
26
- end
27
- class SassHandler < Sinatra::Base
28
- set :views, Pathname(app_file).dirname.join('site_hook', 'static', 'sass').to_s
29
- get '/css/*.css' do
30
- filename = params[:splat].first
31
- scss filename.to_sym, cache: false
32
- end
33
- end
34
21
  # class CoffeeHandler (inherits from Sinatra::Base)
35
22
  class CoffeeHandler < Sinatra::Base
36
23
  set :views, Pathname(app_file).dirname.join('site_hook', 'static', 'coffee').to_s
@@ -10,17 +10,17 @@ h1 {
10
10
  .list-group-item {
11
11
  background-color: rgb(0, 51, 2);
12
12
  border-radius: 5px;
13
- &:hover {
13
+ }
14
+ .list-group-item:hover {
14
15
  background-color: #3a3a3a;
15
- }
16
16
  }
17
17
  a {
18
18
  color: darkgreen !important;
19
19
  text-decoration-color: darkgreen !important;
20
- &:hover {
21
- color: green !important;
22
- }
23
- &:focus {
24
- color: green !important;
25
- }
20
+ }
21
+ a:hover {
22
+ color: green !important;
23
+ }
24
+ a:focus {
25
+ color: green !important;
26
26
  }
@@ -1,32 +1,48 @@
1
- require 'thor'
2
- require 'site_hook/config_class'
3
- require 'site_hook/server_class'
4
- #require 'site_hook/debug_class'
1
+ require 'gli'
2
+ require 'highline'
3
+ require 'paint'
4
+ require 'pathname'
5
+ require 'site_hook/exceptions'
6
+ require 'site_hook/deprecate'
5
7
  module SiteHook
6
- class CLI < Thor
7
- map %w[--version -v] => :__print_version
8
- desc '--version, -v', 'Print the version'
9
-
10
- # Prints version string
11
- # @return [NilClass] nil
12
- def __print_version
13
- puts "Version: v#{SiteHook::VERSION}"
8
+ class App
9
+ extend GLI::App
10
+ version SiteHook::VERSION
11
+ # don't use config_file just use ~/.shrc/config's cli:...
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
14
22
  end
15
-
16
- map %w(--gem-info --info --about) => :__gem_info
17
- desc '--gem-info, --info, --about', 'Print info on the gem.'
18
- def __gem_info
19
- say "Gem Name: #{SiteHook::Gem::Info.name}"
20
- say "Gem Constant: #{SiteHook::Gem::Info.constant_name}"
21
- say "Gem Author: #{SiteHook::Gem::Info.author}"
22
- say "Gem Version: v#{SiteHook::VERSION}"
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
23
27
  end
24
- desc 'config SUBCOMMAND [OPTIONS]', 'Configure site_hook options'
25
- subcommand('config', SiteHook::ConfigClass)
26
- desc 'server SUBCOMMAND [OPTIONS]', 'Start the server'
27
- subcommand('server', SiteHook::ServerClass)
28
- #desc 'debug SUBCOMMAND [OPTIONS]', 'Debug the Gem'
29
- #subcommand('debug', SiteHook::DebugClass)
28
+ pre do |global_options, command, options, args|
29
+ if SiteHook::Paths.old_config.exist?
30
+ continue = SiteHook::Deprecation.deprecate(
31
+ "#{SiteHook::Paths.old_config.to_s} is deprecated in favor of #{SiteHook::Paths.config}",
32
+ <<~INSTRUCT,
33
+ Please run `#{exe_name} config upgrade-shrc` to rectify this.
34
+ Once version 1.0.0 is released, #{SiteHook::Paths.config} will
35
+ be the only config file option, and #{SiteHook::Paths.old_config} will not be allowed.
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
30
40
 
41
+ )
42
+ continue
43
+ else
44
+ # don't do anything
45
+ end
46
+ end
31
47
  end
32
48
  end
@@ -0,0 +1,81 @@
1
+ require 'gli'
2
+ require 'highline'
3
+ require 'random_password'
4
+ require 'yaml'
5
+ require 'site_hook/config'
6
+ module SiteHook
7
+
8
+
9
+ # *ConfigClass*
10
+ #
11
+ # Holds all of the commands for the config subcommand
12
+ class App
13
+ extend GLI::App
14
+
15
+ desc 'Configure site_hook options'
16
+
17
+ # rubocop:disable Metrics/AbcSize
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|
22
+
23
+ yaml = [
24
+ '# fatal, error, warn, info, debug',
25
+ 'log_levels:',
26
+ ' hook: info',
27
+ ' build: info',
28
+ ' git: info',
29
+ ' app: info',
30
+
31
+ ]
32
+ shrc = SiteHook::Paths.config
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
45
+ 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
+
65
+ if (8..255).include?(options[:length])
66
+ if (0..128).member?(options[:'symbol-amt'])
67
+ puts RandomPassword.generate(length: options[:length], symbols: options['symbol-amt'])
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
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+ # rubocop:enable Metrics/AbcSize
@@ -6,23 +6,24 @@
6
6
  # -> Copyright (c) 2018 Ken Spencer
7
7
  # -> License: MIT
8
8
  ##########
9
- require 'thor'
9
+ require 'gli'
10
10
 
11
11
  module SiteHook
12
- class FileExistsError < Exception
12
+ class FileExistsError < StandardError
13
13
  end
14
14
 
15
15
  # *DebugClass*
16
16
  #
17
- # Holds all of the commands for the config subcommand
18
- class DebugClass < Thor
17
+ # Holds all of the commands for the debug subcommand
18
+ class App
19
+ extend GLI::App
19
20
 
20
- desc 'paths [options]', "Return current paths for running site_hook"
21
+ desc "Return current paths for running site_hook"
21
22
  def paths
22
23
  home_gem_path = ENV['GEM_HOME']
23
24
  puts home_gem_path
24
25
  puts Pathname(::Gem.default_path.first).join('lib', 'site_hook')
25
- puts .exist?
26
+ # puts .exist?
26
27
  end
27
28
  end
28
29
  end
@@ -0,0 +1,39 @@
1
+ ##########
2
+ # -> File: /home/ken/RubymineProjects/site_hook/lib/site_hook/config_class.1.rb
3
+ # -> Project: site_hook
4
+ # -> Author: Ken Spencer <me@iotaspencer.me>
5
+ # -> Last Modified: 1/10/2018 21:45:36
6
+ # -> Copyright (c) 2018 Ken Spencer
7
+ # -> License: MIT
8
+ ##########
9
+ require 'site_hook/persist'
10
+ require 'site_hook/paths'
11
+ require 'site_hook/const'
12
+ require 'gli'
13
+ module SiteHook
14
+ autoload :Webhook, 'site_hook/webhook'
15
+ SHRC = YAML.load_file(SiteHook::Paths.config) || YAML.load_file(SiteHook::Paths.old_config)
16
+ # *ServerClass*
17
+ #
18
+ # Holds all of the commands for the config subcommand
19
+ class App
20
+ extend GLI::App
21
+
22
+ command 'server' do |c|
23
+ c.desc 'Start the server'
24
+ c.command 'listen' do |listen|
25
+ listen.desc 'Start SiteHook'
26
+ listen.flag :log_levels, type: :hash, arg_name: 'LEVELS', default: SiteHook::Logs.log_levels
27
+ listen.flag :host, type: :string, arg_name: 'BINDHOST', default: SHRC.fetch('host', '127.0.0.1')
28
+ listen.flag :port, type: :numeric, arg_name: 'BINDPORT', default: SHRC.fetch('port', 9090)
29
+ listen.action do |global_options, options, arguments|
30
+ SiteHook::Webhook.set_options(options[:host], options[:port])
31
+ SiteHook.mklogdir unless SiteHook::Paths.logs.exist?
32
+ SiteHook::Webhook.run!
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ # rubocop:enable Metrics/AbcSize
@@ -0,0 +1,24 @@
1
+ require 'site_hook/paths'
2
+ require 'recursive_open_struct'
3
+
4
+ module SiteHook
5
+ class Config
6
+ class Get
7
+ attr_reader :raw_config, :parsed_config, :config
8
+ def initialize(cfg_path = Pathname.new(SiteHook::Paths.config || SiteHook::Paths.old_config))
9
+ @filename = cfg_path
10
+ @raw_config = YAML.load_file(cfg_path)
11
+ @parsed_config = RecursiveOpenStruct.new(@raw_config, recurse_over_arrays: true, preserve_original_keys: true)
12
+ @config = @parsed_config
13
+ end
14
+
15
+ end
16
+ class Set
17
+ attr_reader :filename
18
+ def initialize(cfg_path)
19
+ @filename = cfg_path
20
+ @config = YAML.load_file(@filename)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+ 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
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ module SiteHook
2
+ module ConfigSections
3
+ class Cli
4
+
5
+ def self.example
6
+ [
7
+ 'cli:',
8
+ ' config:',
9
+ ' mkpass:',
10
+ ' symbols: 0',
11
+ ' length: 8',
12
+ ' gen-project:',
13
+ ' config-file: _config.yml',
14
+ ' add-project:',
15
+ ' gen:'
16
+
17
+
18
+
19
+
20
+ ]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module SiteHook
2
+ module ConfigSections
3
+ class LogLevels
4
+ def self.example
5
+ [
6
+ 'log_levels:',
7
+ ' app: info',
8
+ ' build: info',
9
+ ' git: info',
10
+ ' hook: info'
11
+ ]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module SiteHook
2
+ module ConfigSections
3
+ class Projects
4
+ def self.example
5
+ [
6
+ 'projects:',
7
+ ' PROJECT.NAME:',
8
+ " config: _config.yml",
9
+ " src: /path/2/site/source",
10
+ " dst: /path/2/destination/",
11
+ " host: git*.com",
12
+ " repo: USER/REPO",
13
+ " hookpass: SOMERANDOMSTRING",
14
+ " private: true/false"
15
+ ]
16
+ end
17
+ def initialize(**answers)
18
+ @answers = answers
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'site_hook/log'
2
+ require 'site_hook/logger'
3
+ module SiteHook
4
+ class Consts
5
+ HOOKLOG = SiteHook::HookLogger::HookLog.new(SiteHook::Logs.log_levels['hook']).log
6
+ BUILDLOG = SiteHook::HookLogger::BuildLog.new(SiteHook::Logs.log_levels['build']).log
7
+ APPLOG = SiteHook::HookLogger::AppLog.new(SiteHook::Logs.log_levels['app']).log
8
+ SHRC = YAML.load_file(Pathname(Dir.home).join('.jph', 'config'))
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ module SiteHook
2
+ 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
+ end
11
+ def self.deprecate(situation, instructions, continue)
12
+ puts @str if @str
13
+ return continue
14
+ end
15
+ end
16
+ class NotImplemented
17
+ attr_reader :command_object
18
+
19
+ def initialize(command)
20
+ @command_object = command
21
+ @exe_name = @command_object.parent.parent.exe_name
22
+ @output_string = "Command `#{@exe_name} #{command.name_for_help.join(' ')}"
23
+ end
24
+ def self.declare(command)
25
+ instance = self.new(command)
26
+ instance.instance_variable_set(
27
+ :'@output_string',
28
+ "#{instance.instance_variable_get(:'@output_string')}` is not implemented currently")
29
+ puts instance.instance_variable_get(:'@output_string')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ require 'paint'
2
+ module SiteHook
3
+ class SiteHookError < StandardError
4
+ end
5
+ class ConfigExistsError < SiteHookError
6
+ end
7
+
8
+
9
+ end
@@ -17,10 +17,11 @@ Logging.color_scheme(
17
17
  :logger => :cyan,
18
18
  :message => :green,
19
19
  )
20
-
20
+ PATTERN = '[%d] %-5l %c: %m\n'
21
+ DATE_PATTERN = '%Y-%m-%d %H:%M:%S'
21
22
  layout = Logging.layouts.pattern \
22
- :pattern => '[%d] %-5l %c: %m\n',
23
- :date_pattern => '%Y-%m-%d %H:%M:%S',
23
+ :pattern => PATTERN,
24
+ :date_pattern => DATE_PATTERN,
24
25
  :color_scheme => 'bright'
25
26
 
26
27
  Logging.appenders.stdout \
@@ -30,6 +31,7 @@ module SiteHook
30
31
  def mklogdir
31
32
  path = Pathname(Dir.home).join('.jph', 'logs')
32
33
  if path.exist?
34
+ # Path exists, don't do anything
33
35
  else
34
36
  FileUtils.mkpath(path.to_s)
35
37
  end
@@ -52,7 +54,7 @@ module SiteHook
52
54
  flayout = Logging.appenders.rolling_file \
53
55
  Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
54
56
  :age => 'daily',
55
- :pattern => '[%d] %-5l %c: %m\n'
57
+ :pattern => PATTERN
56
58
  @log.add_appenders 'stdout', flayout
57
59
  @log.level = log_level
58
60
  end
@@ -77,7 +79,7 @@ module SiteHook
77
79
  flayout = Logging.appenders.rolling_file \
78
80
  Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
79
81
  :age => 'daily',
80
- :pattern => '[%d] %-5l %c: %m\n'
82
+ :pattern => PATTERN
81
83
  @log.add_appenders 'stdout', flayout
82
84
  @log.level = log_level
83
85
  LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
@@ -96,7 +98,7 @@ module SiteHook
96
98
  flayout = Logging.appenders.rolling_file \
97
99
  Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
98
100
  :age => 'daily',
99
- :pattern => '[%d] %-5l %c: %m\n'
101
+ :pattern => PATTERN
100
102
  @log.add_appenders 'stdout', flayout
101
103
  @log.level = @log_level
102
104
  LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
@@ -115,7 +117,7 @@ module SiteHook
115
117
  flayout = Logging.appenders.rolling_file \
116
118
  Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
117
119
  :age => 'daily',
118
- :pattern => '[%d] %-5l %c: %m\n'
120
+ :pattern => PATTERN
119
121
  @log.add_appenders 'stdout', flayout
120
122
  @log.level = log_level
121
123
 
@@ -135,7 +137,7 @@ module SiteHook
135
137
  flayout = Logging.appenders.rolling_file \
136
138
  Pathname(Dir.home).join('.jph', 'logs', "#{SiteHook.safe_log_name(self)}-#{@log_level}.log").to_s,
137
139
  :age => 'daily',
138
- :pattern => '[%d] %-5l %c: %m\n'
140
+ :pattern => PATTERN
139
141
  @log.add_appenders 'stdout', flayout
140
142
  @log.level = log_level
141
143
  LL.debug "Initialized #{SiteHook.safe_log_name(self)}"
@@ -171,6 +173,8 @@ module SiteHook
171
173
  @info_output << "Pulling via #{$2}/#{$3} on #{$1}."
172
174
  when msg =~ /\* branch (.*?) -> .*/
173
175
  @info_output << "Using #{$1} branch"
176
+ else
177
+ @debug_output << msg
174
178
  end
175
179
  end
176
180
  else
@@ -10,12 +10,15 @@
10
10
  module SiteHook
11
11
  # Paths: Paths to gem resources and things
12
12
  class Paths
13
- def self.config
13
+ def self.old_config
14
14
  Pathname(Dir.home).join('.jph', 'config')
15
15
  end
16
+ def self.config
17
+ Pathname(Dir.home).join('.shrc', 'config')
18
+ end
16
19
 
17
20
  def self.logs
18
- Pathname(Dir.home).join('.jph', 'logs')
21
+ Pathname(Dir.home).join('.shrc', 'logs')
19
22
  end
20
23
  def self.lib_dir
21
24
  Pathname(::Gem.user_dir).join('gems', "site_hook-#{SiteHook::VERSION}", 'lib')
@@ -0,0 +1,14 @@
1
+ require 'site_hook/const'
2
+
3
+ module SiteHook
4
+ class Options
5
+ def self.set_options(global, local)
6
+ global.each do |option, value|
7
+ Options.class_variable_set(:"@@global-#{option}", value)
8
+ end
9
+ local.each do |option, value|
10
+ Options.class_variable_set(:"@@local-#{option}", value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ module SiteHook
2
+ class GenConfig
3
+ # @param [HighLine]
4
+ def initialize(hl)
5
+ @hl = hl
6
+
7
+ end
8
+ def prompt_project
9
+ @hl.say "First What's the name of the project?"
10
+ project_name = @hl.ask('> ')
11
+
12
+ @hl.say "What's the source path? e.g. /home/#{ENV['USER']}/sites/site.tld"
13
+ source_path = @hl.ask('> ')
14
+
15
+ @hl.say 'Where is the web root? e.g. /var/www/sites/site.tld'
16
+ dest_path = @hl.ask('> ')
17
+
18
+ @hl.say 'The next things are for the public webhook list.'
19
+ @hl.say "\n"
20
+ @hl.say "\n"
21
+ @hl.say "What's the hostname of the git service? e.g. github.com,"
22
+ @hl.say "gitlab.com, git.domain.tld"
23
+ git_host = @hl.ask('> ')
24
+
25
+ @hl.say "What's the repo path? e.g. UserName/SiteName, UserName/site, etc."
26
+ repo_path = @hl.ask('> ')
27
+
28
+ @hl.say 'Is this repo allowed to be shown publically?'
29
+ is_private = @hl.agree('> ', true) ? true : false
30
+
31
+ @hl.say "Generating a hook password for you. If this one isn't wanted"
32
+ @hl.say "then just change it afterwards using '#{exe_name} config mkpass'."
33
+ hook_pass = RandomPassword.new(length: 20, symbols: 0).generate
34
+ @hl.say 'Done.'
35
+ @hl.say 'Outputting...'
36
+ [
37
+ " #{project_name}:",
38
+ " src: #{source_path}",
39
+ " dst: #{dest_path}",
40
+ " hookpass: #{hook_pass}",
41
+ " host: #{git_host}",
42
+ " repo: #{repo_path}",
43
+ " private: #{is_private}"
44
+ ]
45
+
46
+ end
47
+ end
48
+ end
@@ -2,6 +2,7 @@ require 'open3'
2
2
  require 'site_hook/logger'
3
3
  require 'git'
4
4
  require 'paint'
5
+ require 'site_hook/persist'
5
6
  module SiteHook
6
7
  autoload :Logs, 'site_hook/log'
7
8
 
@@ -10,9 +11,14 @@ module SiteHook
10
11
  attr :jekyll_source, :build_dest
11
12
 
12
13
  class Build
14
+ def initialize(options)
15
+ @options = options
16
+ end
17
+
18
+ JEKYLL_SOURCE_VAR = '@jekyll_source'
13
19
 
14
20
  def do_grab_version
15
- jekyll_source = Jekyll.instance_variable_get('@jekyll_source')
21
+ jekyll_source = Jekyll.instance_variable_get(JEKYLL_SOURCE_VAR)
16
22
  log = Jekyll.instance_variable_get('@log')
17
23
  begin
18
24
  stdout_str, status = Open3.capture2({'BUNDLE_GEMFILE' => Pathname(jekyll_source).join('Gemfile').to_path}, "jekyll --version --source #{jekyll_source}")
@@ -26,7 +32,7 @@ module SiteHook
26
32
  def do_pull
27
33
  fakelog = SiteHook::HookLogger::FakeLog.new
28
34
  reallog = SiteHook::HookLogger::GitLog.new(SiteHook::Logs.log_levels['git']).log
29
- jekyll_source = Jekyll.instance_variable_get('@jekyll_source')
35
+ jekyll_source = Jekyll.instance_variable_get(JEKYLL_SOURCE_VAR)
30
36
  # build_dest = Jekyll.instance_variable_get('@build_dest')
31
37
  g = Git.open(jekyll_source, log: fakelog)
32
38
  g.pull
@@ -36,7 +42,7 @@ module SiteHook
36
42
  end
37
43
 
38
44
  def do_build
39
- jekyll_source = Jekyll.instance_variable_get('@jekyll_source')
45
+ jekyll_source = Jekyll.instance_variable_get(JEKYLL_SOURCE_VAR)
40
46
  build_dest = Jekyll.instance_variable_get('@build_dest')
41
47
  log = Jekyll.instance_variable_get('@log')
42
48
  Open3.popen2e({'BUNDLE_GEMFILE' => Pathname(jekyll_source).join('Gemfile').to_path}, "bundle exec jekyll build --source #{Pathname(jekyll_source).realdirpath.to_path} --destination #{Pathname(build_dest).to_path} --config #{Pathname(jekyll_source).join(@options[:config])}") { |in_io, outerr_io, thr|
@@ -58,17 +64,17 @@ module SiteHook
58
64
  case
59
65
  when line =~ /done in .*/
60
66
  log.info(line)
61
- when line =~ /Generating/
67
+ when line =~ /Generating.../
62
68
  log.info(line)
63
69
  when line =~ /Configuration file:|Source:|Destination:/
64
70
  log.debug(line)
65
- when line =~ /Incremental|Auto-regeneration/
71
+ when line =~ /Incremental build: disabled.|Auto-regeneration/
66
72
  print ''
67
73
  else
68
74
  log.debug line
69
75
  end
70
76
  end
71
- exit_status = thr.value
77
+ thr.value
72
78
  }
73
79
 
74
80
  end
@@ -82,12 +88,12 @@ module SiteHook
82
88
  @build_dest = build_dest
83
89
  @log = logger
84
90
  @options = options
85
- instance = self::Build.new
91
+ instance = self::Build.new(options)
86
92
  meths = [instance.do_grab_version, instance.do_pull, instance.do_build]
87
93
  begin
88
94
  meths.each do |m|
89
95
  @log.debug("Running #{m}")
90
- instance.method(m).call
96
+ instance.send(m)
91
97
  @log.debug("Ran #{m}")
92
98
  end
93
99
  return {message: 'success', status: 0}
@@ -1,3 +1,3 @@
1
1
  module SiteHook
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -6,38 +6,30 @@
6
6
  # -> Copyright (c) 2018 Ken Spencer
7
7
  # -> License: MIT
8
8
  ##########
9
-
9
+ require 'site_hook/persist'
10
+ require 'site_hook/const'
10
11
  require 'sinatra'
11
12
 
12
13
  module SiteHook
13
14
  class Webhook < Sinatra::Base
14
- HOOKLOG = SiteHook::HookLogger::HookLog.new(SiteHook::Logs.log_levels['hook']).log
15
- BUILDLOG = SiteHook::HookLogger::BuildLog.new(SiteHook::Logs.log_levels['build']).log
16
- APPLOG = SiteHook::HookLogger::AppLog.new(SiteHook::Logs.log_levels['app']).log
17
- JPHRC = YAML.load_file(Pathname(Dir.home).join('.jph', 'config'))
18
- def self.set_bind(host, port, config)
19
- self.set port: port
20
- self.set bind: host
21
- if config == '_config.yml'
22
- SiteHook.set_options(:BUILD_CONFIG, '_config.yml')
23
- else
24
- SiteHook.set_options(:BUILD_CONFIG, config)
25
- end
26
15
 
27
- end
28
16
  set server: %w[thin]
29
17
  set quiet: true
30
18
  set raise_errors: true
31
19
  set views: Pathname(SiteHook::Paths.lib_dir).join('site_hook', 'views')
32
- set :public_folder, Pathname(SiteHook::Paths.lib_dir).join('site_hook', 'static')
33
- use SassHandler
20
+ set :public_folder, Pathname(SiteHook::Paths.lib_dir).join('site_hook', 'assets')
34
21
  use CoffeeHandler
22
+ def self.set_options(host, port)
23
+ self.set bind: host.to_s
24
+ self.set port: port.to_i
25
+ end
35
26
 
36
- #
27
+ #
37
28
  # @param [String] body JSON String of body
38
29
  # @param [String] sig Signature or token from git service
39
30
  # @param [String] secret User-defined verification token
40
31
  # @param [Boolean] plaintext Whether the verification is plaintext
32
+ # @param [String] service service name
41
33
  def self.verified?(body, sig, secret, plaintext:, service:)
42
34
  if plaintext
43
35
  sig == secret
@@ -53,57 +45,60 @@ module SiteHook
53
45
  APPLOG.debug "Secret verified: #{sig} === #{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, body)}"
54
46
  true
55
47
  end
48
+ else
49
+ # This shouldn't happen
56
50
  end
57
51
 
58
52
  end
59
53
  end
60
54
 
55
+ CONTENT_TYPE = 'Content-Type'
61
56
  get '/' do
62
- halt 403, { 'Content-Type' => 'text/html' }, '<h1>See <a href="/webhooks/">here</a> for the active webhooks</h1>'
57
+ halt 403, {CONTENT_TYPE => 'text/html'}, '<h1>See <a href="/webhooks/">here</a> for the active webhooks</h1>'
63
58
  end
64
59
 
60
+ APPLICATION_JSON = 'application/json'
65
61
  get '/webhooks.json', provides: :json do
66
- content_type 'application/json'
62
+ content_type APPLICATION_JSON
67
63
  public_projects = JPHRC['projects'].select do |_project, hsh|
68
- (hsh.fetch('private', nil) == false) || hsh.fetch('private', nil).nil?
64
+ !hsh.fetch('private')
69
65
  end
70
- result = {}
66
+ result = {}
71
67
  public_projects.each do |project, hsh|
72
68
  result[project] = {}
73
69
  hsh.delete('hookpass')
74
70
  result[project].merge!(hsh)
75
71
  end
76
- headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
72
+ headers CONTENT_TYPE => APPLICATION_JSON, 'Accept' => APPLICATION_JSON
77
73
  json result, layout: false
78
74
  end
79
75
 
80
76
  get '/webhooks/?' do
81
- haml :webhooks, locals: { 'projects' => JPHRC['projects'] }
77
+ haml :webhooks, locals: {'projects' => JPHRC['projects']}
82
78
  end
83
79
 
84
80
  get '/webhook/*' do
85
81
  if params[:splat]
86
82
  pass
87
83
  else
88
- halt 405, { 'Content-Type' => 'application/json' }, { message: 'GET not allowed' }.to_json
84
+ halt 405, {CONTENT_TYPE => APPLICATION_JSON}, {message: 'GET not allowed'}.to_json
89
85
  end
90
86
  end
91
87
  post '/webhook/:hook_name/?' do
92
88
  service = nil
93
89
  request.body.rewind
94
90
  req_body = request.body.read
95
- js = RecursiveOpenStruct.new(JSON.parse(req_body))
91
+ js = RecursiveOpenStruct.new(JSON.parse(req_body))
96
92
 
97
93
  projects = JPHRC['projects']
98
- begin
99
- project = projects.fetch(params[:hook_name])
100
- rescue KeyError => e
101
- halt 404, { 'Content-Type' => 'application/json' }, { message: 'no such project', status: 1 }.to_json
94
+ project = projects.fetch(params[:hook_name], nil)
95
+ if project.nil?
96
+ halt 404, {CONTENT_TYPE => APPLICATION_JSON}, {message: 'no such project', status: 1}.to_json
102
97
  end
103
98
  plaintext = false
104
99
  signature = nil
105
- event = nil
106
- gogs = request.env.fetch('HTTP_X_GOGS_EVENT', nil)
100
+ event = nil
101
+ gogs = request.env.fetch('HTTP_X_GOGS_EVENT', nil)
107
102
  unless gogs.nil?
108
103
  event = 'push' if gogs == 'push'
109
104
  end
@@ -116,27 +111,25 @@ module SiteHook
116
111
  event = 'push' if gitlab == 'push'
117
112
  end
118
113
 
119
- events = { 'github' => github, 'gitlab' => gitlab, 'gogs' => gogs }
114
+ events = {'github' => github, 'gitlab' => gitlab, 'gogs' => gogs}
120
115
  if events['github'] && events['gogs']
121
116
  events['github'] = nil
122
117
  end
123
118
  events_m_e = events.values.one?
124
119
  case events_m_e
125
120
  when true
126
- event = 'push'
121
+ event = 'push'
127
122
  service = events.select { |_key, value| value }.keys.first
128
123
  when false
129
- halt 400, { 'Content-Type': 'application/json' }, { message: 'events are mutually exclusive', status: 'failure' }.to_json
124
+ halt 400, {CONTENT_TYPE: APPLICATION_JSON}, {message: 'events are mutually exclusive', status: 'failure'}.to_json
130
125
 
131
126
  else
132
127
  halt 400,
133
- { 'Content-Type': 'application/json' },
128
+ {CONTENT_TYPE: APPLICATION_JSON},
134
129
  'status': 'failure', 'message': 'something weird happened'
135
130
  end
136
- if event != 'push'
137
- if event.nil?
138
- halt 400, { 'Content-Type': 'application/json' }, { message: 'no event header' }.to_json
139
- end
131
+ if event != 'push' && event.nil?
132
+ halt 400, {CONTENT_TYPE: APPLICATION_JSON}, {message: 'no event header'}.to_json
140
133
  end
141
134
  case service
142
135
  when 'gitlab'
@@ -149,34 +142,36 @@ module SiteHook
149
142
  when 'gogs'
150
143
  signature = request.env.fetch('HTTP_X_GOGS_SIGNATURE', '')
151
144
  plaintext = false
145
+ else
146
+ # This shouldn't happen
152
147
  end
153
148
  if Webhook.verified?(req_body.to_s, signature, project['hookpass'], plaintext: plaintext, service: service)
154
149
  BUILDLOG.info 'Building...'
155
150
  begin
156
- jekyllbuild = SiteHook::Senders::Jekyll.build(project['src'], project['dst'], BUILDLOG, options: {config: SiteHook::BUILD_CONFIG})
157
- jekyll_status = jekyllbuild
151
+ jekyll_status = SiteHook::Senders::Jekyll.build(project['src'], project['dst'], BUILDLOG, options: {config: project['config']})
158
152
  case jekyll_status
159
153
 
160
154
  when 0
161
155
  status 200
162
- headers 'Content-Type' => 'application/json'
163
- body { { 'status': 'success' }.to_json }
156
+ headers CONTENT_TYPE => APPLICATION_JSON
157
+ body { {'status': 'success'}.to_json }
164
158
  when -1, -2, -3
165
- halt 400, { 'Content-Type' => 'application/json' }, { 'status': 'exception', error: jekyll_status.fetch(:message).to_s }
166
-
159
+ halt 400, {CONTENT_TYPE => APPLICATION_JSON}, {'status': 'exception', error: jekyll_status.fetch(:message).to_s}
160
+ else
161
+ # This shouldn't happen
167
162
  end
168
163
 
169
164
  rescue => e
170
- halt 500, { 'Content-Type' => 'application/json' }, { 'status': 'exception', error: e.to_s}
165
+ halt 500, {CONTENT_TYPE => APPLICATION_JSON}, {'status': 'exception', error: e.to_s}
171
166
 
172
167
  end
173
168
 
174
169
  else
175
- halt 403, { 'Content-Type' => 'application/json' }, { message: 'incorrect secret', 'status': 'failure' }.to_json
170
+ halt 403, {CONTENT_TYPE => APPLICATION_JSON}, {message: 'incorrect secret', 'status': 'failure'}.to_json
176
171
  end
177
172
  end
178
173
  post '/webhook/?' do
179
- halt 403, { 'Content-Type' => 'application/json' }, { message: 'pick a hook', error: 'root webhook hit', 'status': 'failure' }.to_json
174
+ halt 403, {CONTENT_TYPE => APPLICATION_JSON}, {message: 'pick a hook', error: 'root webhook hit', 'status': 'failure'}.to_json
180
175
  end
181
176
  end
182
177
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  'tutorial_uri' => 'https://iotaspencer.me/projects/site_hook/'
22
22
  }
23
23
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
- f.match(%r{^(spec)/})
24
+ f.match(%r{^(tests)/})
25
25
  end
26
26
  spec.bindir = 'bin'
27
27
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -34,12 +34,14 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency 'paint', '~> 2.0'
35
35
  spec.add_runtime_dependency 'random_password', '~> 0.1.1'
36
36
  spec.add_runtime_dependency 'recursive-open-struct', '~> 1.1'
37
- spec.add_runtime_dependency 'sass', '~> 3.5'
37
+ spec.add_runtime_dependency 'redis', '~> 4.1.0'
38
38
  spec.add_runtime_dependency 'sinatra', '~> 2.0.2', '>= 2.0.5'
39
39
  spec.add_runtime_dependency 'sinatra-contrib', '~> 2.0', '>= 2.0.5'
40
40
  spec.add_runtime_dependency 'thin', '~> 1.7'
41
- spec.add_runtime_dependency 'thor', '~> 0.20.3'
41
+ spec.add_runtime_dependency 'gli', '~> 2.18.0'
42
42
  spec.add_development_dependency 'bundler', '~> 1.16'
43
43
  spec.add_development_dependency 'rake', '~> 10.0'
44
- spec.add_development_dependency 'rspec', '~> 3.0'
44
+ spec.add_development_dependency 'minitest', '~> 5.11.3'
45
+
46
+ spec.post_install_message
45
47
  end
@@ -0,0 +1,4 @@
1
+ sonar.projectKey=ElectroCode-Gems_site_hook
2
+ sonar.organization=electrocode-gems
3
+ sonar.sources=./lib
4
+ sonar.projectBaseDir=/home/ken/everygit/site_hook
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.8.0
4
+ version: 0.8.1
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-02-01 00:00:00.000000000 Z
11
+ date: 2019-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,19 +129,19 @@ dependencies:
129
129
  - !ruby/object:Gem::Version
130
130
  version: '1.1'
131
131
  - !ruby/object:Gem::Dependency
132
- name: sass
132
+ name: redis
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '3.5'
137
+ version: 4.1.0
138
138
  type: :runtime
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '3.5'
144
+ version: 4.1.0
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: sinatra
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -197,19 +197,19 @@ dependencies:
197
197
  - !ruby/object:Gem::Version
198
198
  version: '1.7'
199
199
  - !ruby/object:Gem::Dependency
200
- name: thor
200
+ name: gli
201
201
  requirement: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - "~>"
204
204
  - !ruby/object:Gem::Version
205
- version: 0.20.3
205
+ version: 2.18.0
206
206
  type: :runtime
207
207
  prerelease: false
208
208
  version_requirements: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - "~>"
211
211
  - !ruby/object:Gem::Version
212
- version: 0.20.3
212
+ version: 2.18.0
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: bundler
215
215
  requirement: !ruby/object:Gem::Requirement
@@ -239,19 +239,19 @@ dependencies:
239
239
  - !ruby/object:Gem::Version
240
240
  version: '10.0'
241
241
  - !ruby/object:Gem::Dependency
242
- name: rspec
242
+ name: minitest
243
243
  requirement: !ruby/object:Gem::Requirement
244
244
  requirements:
245
245
  - - "~>"
246
246
  - !ruby/object:Gem::Version
247
- version: '3.0'
247
+ version: 5.11.3
248
248
  type: :development
249
249
  prerelease: false
250
250
  version_requirements: !ruby/object:Gem::Requirement
251
251
  requirements:
252
252
  - - "~>"
253
253
  - !ruby/object:Gem::Version
254
- version: '3.0'
254
+ version: 5.11.3
255
255
  description:
256
256
  email:
257
257
  - me@iotaspencer.me
@@ -274,22 +274,33 @@ files:
274
274
  - bin/console
275
275
  - bin/site_hook
276
276
  - lib/site_hook.rb
277
+ - lib/site_hook/assets/css/styles.css
277
278
  - lib/site_hook/cli.rb
278
- - lib/site_hook/config_class.rb
279
- - lib/site_hook/debug_class.rb
279
+ - lib/site_hook/commands/config_class.rb
280
+ - lib/site_hook/commands/debug_class.rb
281
+ - lib/site_hook/commands/server_class.rb
282
+ - lib/site_hook/config.rb
283
+ - lib/site_hook/config_sections.rb
284
+ - lib/site_hook/config_sections/cli.rb
285
+ - lib/site_hook/config_sections/log_levels.rb
286
+ - lib/site_hook/config_sections/projects.rb
287
+ - lib/site_hook/const.rb
288
+ - lib/site_hook/deprecate.rb
289
+ - lib/site_hook/exceptions.rb
280
290
  - lib/site_hook/gem.rb
281
291
  - lib/site_hook/log.rb
282
292
  - lib/site_hook/logger.rb
283
293
  - lib/site_hook/paths.rb
294
+ - lib/site_hook/persist.rb
295
+ - lib/site_hook/prompts/gen_config.rb
284
296
  - lib/site_hook/sender.rb
285
- - lib/site_hook/server_class.rb
286
297
  - lib/site_hook/spinner.rb
287
- - lib/site_hook/static/sass/styles.scss
288
298
  - lib/site_hook/version.rb
289
299
  - lib/site_hook/views/layout.haml
290
300
  - lib/site_hook/views/webhooks.haml
291
301
  - lib/site_hook/webhook.rb
292
302
  - site_hook.gemspec
303
+ - sonar-project.properties
293
304
  homepage: https://iotaspencer.me/projects/site_hook/
294
305
  licenses:
295
306
  - MIT
@@ -1,92 +0,0 @@
1
- require 'thor'
2
- require 'highline'
3
- require 'random_password'
4
- require 'yaml'
5
- require 'recursive-open-struct'
6
- module SiteHook
7
- class FileExistsError < Exception
8
- end
9
-
10
- # *ConfigClass*
11
- #
12
- # Holds all of the commands for the config subcommand
13
- class ConfigClass < Thor
14
-
15
- desc 'gen [options]', "Generate a example config file if one doesn't exist"
16
- # rubocop:disable Metrics/AbcSize
17
- def gen
18
- yaml = [
19
- '# fatal, error, warn, info, debug',
20
- 'log_levels:',
21
- ' hook: info',
22
- ' build: info',
23
- ' git: info',
24
- ' app: info',
25
- 'projects:',
26
- ' PROJECT.NAME: # Use the name you put as your webhook url',
27
- ' # https://jekyllhook.example.com/webhook/PROJECT.NAME',
28
- " src: /path/2/site/source # Directory you 'git pull' into",
29
- ' dst: /path/2/destination/ # The web root will be this folder',
30
- " host: git*.com # The git service you're using for vcs",
31
- ' repo: USER/REPO # The repo path on the git service',
32
- ' hookpass: SOMERANDOMSTRING # Gitlab-Token or GitHub secret, etc.',
33
- ' private: true/false # hidden from the public list',
34
- ''
35
- ]
36
- jphrc = SiteHook::Paths.config
37
- if jphrc.exist?
38
- puts "#{jphrc} exists. Will not overwrite."
39
- else
40
- File.open(jphrc, 'w') do |f|
41
- yaml.each do |line|
42
- f.puts line
43
- end
44
- end
45
- say "Created #{jphrc}"
46
- say "You can now edit #{jphrc} and add your projects."
47
- end
48
- end
49
- desc 'gen-project [options]', 'generates a project block'
50
- def gen_project
51
- hl = HighLine.new
52
- hl.say "First What's the name of the project?"
53
- project_name = hl.ask('> ')
54
-
55
- hl.say "What's the source path? e.g. /home/#{ENV['USER']}/sites/site.tld"
56
- source_path = hl.ask('> ')
57
-
58
- hl.say 'Where is the web root? e.g. /var/www/sites/site.tld'
59
- dest_path = hl.ask('> ')
60
-
61
- hl.say 'The next things are for the public webhook list.'
62
- hl.say "\n"
63
- hl.say "\n"
64
- hl.say "What's the hostname of the git service? e.g. github.com,"
65
- hl.say "gitlab.com, git.domain.tld"
66
- git_host = hl.ask('> ')
67
-
68
- hl.say "What's the repo path? e.g. UserName/SiteName, UserName/site, etc."
69
- repo_path = hl.ask('> ')
70
-
71
- hl.say 'Is this repo allowed to be shown publically?'
72
- is_private = hl.agree('> ', true) ? true : false
73
-
74
- hl.say "Generating a hook password for you. If this one isn't wanted"
75
- hl.say 'then just change it afterwards.'
76
- hook_pass = RandomPassword.new(length: 20, symbols: 0).generate
77
- hl.say 'Done.'
78
- hl.say 'Outputting...'
79
- tpl = [
80
- " #{project_name}:",
81
- " src: #{source_path}",
82
- " dst: #{dest_path}",
83
- " hookpass: #{hook_pass}",
84
- " host: #{git_host}",
85
- " repo: #{repo_path}",
86
- " private: #{is_private}"
87
- ]
88
- puts tpl
89
- end
90
- end
91
- end
92
- # rubocop:enable Metrics/AbcSize
@@ -1,29 +0,0 @@
1
- ##########
2
- # -> File: /home/ken/RubymineProjects/site_hook/lib/site_hook/config_class.1.rb
3
- # -> Project: site_hook
4
- # -> Author: Ken Spencer <me@iotaspencer.me>
5
- # -> Last Modified: 1/10/2018 21:45:36
6
- # -> Copyright (c) 2018 Ken Spencer
7
- # -> License: MIT
8
- ##########
9
- require 'thor'
10
- module SiteHook
11
- autoload :Webhook, 'site_hook/webhook'
12
- JPHRC = YAML.load_file(Pathname(Dir.home).join('.jph', 'config'))
13
- # *ServerClass*
14
- #
15
- # Holds all of the commands for the config subcommand
16
- class ServerClass < Thor
17
- method_option(:log_levels, type: :hash, banner: 'LEVELS', default: SiteHook::Logs.log_levels)
18
- method_option :host, type: :string, banner: 'BINDHOST', default: JPHRC.fetch('host', '127.0.0.1')
19
- method_option :port, type: :string, banner: 'BINDPORT', default: JPHRC.fetch('port', 9090)
20
- method_option :config, type: :string, banner: 'CONFIGFILE', default: '_config.yml'
21
- desc 'listen', 'Start SiteHook'
22
- def listen
23
- SiteHook.mklogdir unless SiteHook::Paths.logs.exist?
24
- SiteHook::Webhook.set_options(options[:host], options[:port], options[:config])
25
- SiteHook::Webhook.run!
26
- end
27
- end
28
- end
29
- # rubocop:enable Metrics/AbcSize