site_hook 0.6.4 → 0.6.7
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/.rubocop.yml +12 -0
- data/Gemfile.lock +25 -20
- data/lib/site_hook.rb +48 -44
- data/lib/site_hook/cli.rb +1 -4
- data/lib/site_hook/config_class.rb +73 -41
- data/lib/site_hook/sender.rb +6 -5
- data/lib/site_hook/version.rb +1 -1
- data/lib/site_hook/views/webhooks.haml +2 -2
- data/site_hook.gemspec +10 -8
- metadata +75 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 894eccca5e1a471622a696b1d21dcf7dc5e9e63db95bd231eb8bc5a08c85c9aa
|
|
4
|
+
data.tar.gz: c00227aa2150784d22cfcf96c5d65ad266241437a6c110438607295eddc33a11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5dedcb8d502b4194a02dfb682f57c7dfe3896b0d435a25d504a4bcb7d2ca955d4850685e0ed46c2327d48019f77e8b951563a472fc9ac00c9d40d82202b06994
|
|
7
|
+
data.tar.gz: 5e2c253d3ed5701d98e654c2b709321893b4c489684f0bbc053674ff7524e1ac9de9fdb92105045bedf18e39333c380cb3b31ad2fd1de582e234a5795aed310e
|
data/.rubocop.yml
ADDED
data/Gemfile.lock
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
site_hook (0.5
|
|
4
|
+
site_hook (0.6.5)
|
|
5
5
|
activesupport (~> 5.1)
|
|
6
6
|
git (~> 1.3)
|
|
7
7
|
haml (~> 5.0)
|
|
8
|
+
highline (~> 2.0, >= 2.0.0)
|
|
8
9
|
logging (~> 2.2)
|
|
9
10
|
paint (~> 2.0)
|
|
10
11
|
pry (~> 0.11)
|
|
12
|
+
random_password (~> 0.1.1)
|
|
11
13
|
recursive-open-struct (~> 1.1)
|
|
12
14
|
sass (~> 3.5)
|
|
13
|
-
sinatra (~> 2.0)
|
|
14
|
-
sinatra-contrib (~> 2.0)
|
|
15
|
+
sinatra (~> 2.0, >= 2.0.2)
|
|
16
|
+
sinatra-contrib (~> 2.0, >= 2.0.2)
|
|
15
17
|
thin (~> 1.7)
|
|
16
18
|
thor (~> 0.20)
|
|
17
19
|
|
|
18
20
|
GEM
|
|
19
21
|
remote: https://rubygems.org/
|
|
20
22
|
specs:
|
|
21
|
-
activesupport (5.2.
|
|
23
|
+
activesupport (5.2.1)
|
|
22
24
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
23
25
|
i18n (>= 0.7, < 2)
|
|
24
26
|
minitest (~> 5.1)
|
|
25
27
|
tzinfo (~> 1.1)
|
|
26
|
-
backports (3.11.
|
|
28
|
+
backports (3.11.4)
|
|
27
29
|
coderay (1.1.2)
|
|
28
30
|
concurrent-ruby (1.0.5)
|
|
29
31
|
daemons (1.2.6)
|
|
30
32
|
diff-lcs (1.3)
|
|
31
|
-
eventmachine (1.2.
|
|
32
|
-
ffi (1.9.
|
|
33
|
-
git (1.
|
|
33
|
+
eventmachine (1.2.7)
|
|
34
|
+
ffi (1.9.25)
|
|
35
|
+
git (1.5.0)
|
|
34
36
|
haml (5.0.4)
|
|
35
37
|
temple (>= 0.8.0)
|
|
36
38
|
tilt
|
|
37
|
-
|
|
39
|
+
highline (2.0.0)
|
|
40
|
+
i18n (1.1.0)
|
|
38
41
|
concurrent-ruby (~> 1.0)
|
|
39
42
|
little-plugger (1.1.4)
|
|
40
43
|
logging (2.2.2)
|
|
@@ -43,15 +46,16 @@ GEM
|
|
|
43
46
|
method_source (0.9.0)
|
|
44
47
|
minitest (5.11.3)
|
|
45
48
|
multi_json (1.13.1)
|
|
46
|
-
mustermann (1.0.
|
|
49
|
+
mustermann (1.0.3)
|
|
47
50
|
paint (2.0.1)
|
|
48
51
|
pry (0.11.3)
|
|
49
52
|
coderay (~> 1.1.0)
|
|
50
53
|
method_source (~> 0.9.0)
|
|
51
|
-
rack (2.0.
|
|
52
|
-
rack-protection (2.0.
|
|
54
|
+
rack (2.0.5)
|
|
55
|
+
rack-protection (2.0.4)
|
|
53
56
|
rack
|
|
54
57
|
rake (10.5.0)
|
|
58
|
+
random_password (0.1.1)
|
|
55
59
|
rb-fsevent (0.10.3)
|
|
56
60
|
rb-inotify (0.9.10)
|
|
57
61
|
ffi (>= 0.5.0, < 2)
|
|
@@ -69,22 +73,23 @@ GEM
|
|
|
69
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
70
74
|
rspec-support (~> 3.7.0)
|
|
71
75
|
rspec-support (3.7.1)
|
|
72
|
-
sass (3.
|
|
76
|
+
sass (3.6.0)
|
|
73
77
|
sass-listen (~> 4.0.0)
|
|
74
78
|
sass-listen (4.0.0)
|
|
75
79
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
76
80
|
rb-inotify (~> 0.9, >= 0.9.7)
|
|
77
|
-
sinatra (2.0.
|
|
81
|
+
sinatra (2.0.4)
|
|
78
82
|
mustermann (~> 1.0)
|
|
79
83
|
rack (~> 2.0)
|
|
80
|
-
rack-protection (= 2.0.
|
|
84
|
+
rack-protection (= 2.0.4)
|
|
81
85
|
tilt (~> 2.0)
|
|
82
|
-
sinatra-contrib (2.0.
|
|
83
|
-
|
|
86
|
+
sinatra-contrib (2.0.4)
|
|
87
|
+
activesupport (>= 4.0.0)
|
|
88
|
+
backports (>= 2.8.2)
|
|
84
89
|
multi_json
|
|
85
90
|
mustermann (~> 1.0)
|
|
86
|
-
rack-protection (= 2.0.
|
|
87
|
-
sinatra (= 2.0.
|
|
91
|
+
rack-protection (= 2.0.4)
|
|
92
|
+
sinatra (= 2.0.4)
|
|
88
93
|
tilt (>= 1.3, < 3)
|
|
89
94
|
temple (0.8.0)
|
|
90
95
|
thin (1.7.2)
|
|
@@ -107,4 +112,4 @@ DEPENDENCIES
|
|
|
107
112
|
site_hook!
|
|
108
113
|
|
|
109
114
|
BUNDLED WITH
|
|
110
|
-
1.16.
|
|
115
|
+
1.16.4
|
data/lib/site_hook.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'site_hook/version'
|
|
2
4
|
require 'site_hook/sender'
|
|
3
5
|
require 'site_hook/logger'
|
|
@@ -10,7 +12,9 @@ require 'json'
|
|
|
10
12
|
require 'sinatra/json'
|
|
11
13
|
require 'yaml'
|
|
12
14
|
module SiteHook
|
|
15
|
+
# rubocop:disable Metrics/ClassLength, Metrics/LineLength, MethodLength, BlockLength
|
|
13
16
|
module Gem
|
|
17
|
+
# class Info
|
|
14
18
|
class Info
|
|
15
19
|
def self.name
|
|
16
20
|
'site_hook'
|
|
@@ -21,10 +25,22 @@ module SiteHook
|
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
def self.author
|
|
24
|
-
|
|
28
|
+
'Ken Spencer <me@iotaspencer.me>'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Paths: Paths to gem resources and things
|
|
33
|
+
class Paths
|
|
34
|
+
def self.config
|
|
35
|
+
Pathname(Dir.home).join('.jph', 'config').to_s
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.logs
|
|
39
|
+
Pathname(Dir.home).join('.jph', 'logs')
|
|
25
40
|
end
|
|
26
41
|
end
|
|
27
42
|
end
|
|
43
|
+
# class SassHandler (inherits from Sinatra::Base)
|
|
28
44
|
class SassHandler < Sinatra::Base
|
|
29
45
|
set :views, Pathname(app_file).dirname.join('site_hook', 'static', 'sass').to_s
|
|
30
46
|
get '/css/*.css' do
|
|
@@ -32,6 +48,7 @@ module SiteHook
|
|
|
32
48
|
scss filename.to_sym, cache: false
|
|
33
49
|
end
|
|
34
50
|
end
|
|
51
|
+
# class CoffeeHandler (inherits from Sinatra::Base)
|
|
35
52
|
class CoffeeHandler < Sinatra::Base
|
|
36
53
|
set :views, Pathname(app_file).dirname.join('site_hook', 'static', 'coffee').to_s
|
|
37
54
|
get '/js/*.js' do
|
|
@@ -39,6 +56,7 @@ module SiteHook
|
|
|
39
56
|
coffee filename.to_sym
|
|
40
57
|
end
|
|
41
58
|
end
|
|
59
|
+
# class Webhook (inherits from Sinatra::Base)
|
|
42
60
|
class Webhook < Sinatra::Base
|
|
43
61
|
HOOKLOG = SiteHook::HookLogger::HookLog.new(SiteHook.log_levels['hook']).log
|
|
44
62
|
BUILDLOG = SiteHook::HookLogger::BuildLog.new(SiteHook.log_levels['build']).log
|
|
@@ -46,24 +64,22 @@ module SiteHook
|
|
|
46
64
|
JPHRC = YAML.load_file(Pathname(Dir.home).join('.jph-rc'))
|
|
47
65
|
set port: JPHRC.fetch('port', 9090)
|
|
48
66
|
set bind: '127.0.0.1'
|
|
49
|
-
set server: %w
|
|
67
|
+
set server: %w[thin]
|
|
50
68
|
set quiet: true
|
|
51
69
|
set raise_errors: true
|
|
52
70
|
set views: Pathname(app_file).dirname.join('site_hook', 'views')
|
|
53
71
|
set :public_folder, Pathname(app_file).dirname.join('site_hook', 'static')
|
|
54
72
|
use SassHandler
|
|
55
73
|
use CoffeeHandler
|
|
74
|
+
|
|
75
|
+
#
|
|
56
76
|
# @param [String] body JSON String of body
|
|
57
77
|
# @param [String] sig Signature or token from git service
|
|
58
78
|
# @param [String] secret User-defined verification token
|
|
59
79
|
# @param [Boolean] plaintext Whether the verification is plaintext
|
|
60
|
-
def
|
|
80
|
+
def self.verified?(body, sig, secret, plaintext:, service:)
|
|
61
81
|
if plaintext
|
|
62
|
-
|
|
63
|
-
true
|
|
64
|
-
else
|
|
65
|
-
false
|
|
66
|
-
end
|
|
82
|
+
sig == secret
|
|
67
83
|
else
|
|
68
84
|
case service
|
|
69
85
|
when 'gogs'
|
|
@@ -82,13 +98,13 @@ module SiteHook
|
|
|
82
98
|
end
|
|
83
99
|
|
|
84
100
|
get '/' do
|
|
85
|
-
halt 403, {'Content-Type' => 'text/html'},
|
|
101
|
+
halt 403, { 'Content-Type' => 'text/html' }, '<h1>See <a href="/webhooks/">here</a> for the active webhooks</h1>'
|
|
86
102
|
end
|
|
87
103
|
|
|
88
104
|
get '/webhooks.json', provides: :json do
|
|
89
105
|
content_type 'application/json'
|
|
90
|
-
public_projects = JPHRC['projects'].select do |
|
|
91
|
-
hsh.fetch('private', nil) == false
|
|
106
|
+
public_projects = JPHRC['projects'].select do |_project, hsh|
|
|
107
|
+
(hsh.fetch('private', nil) == false) || hsh.fetch('private', nil).nil?
|
|
92
108
|
end
|
|
93
109
|
result = {}
|
|
94
110
|
public_projects.each do |project, hsh|
|
|
@@ -98,20 +114,18 @@ module SiteHook
|
|
|
98
114
|
end
|
|
99
115
|
headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
|
|
100
116
|
json result, layout: false
|
|
101
|
-
|
|
102
117
|
end
|
|
103
118
|
|
|
104
119
|
get '/webhooks/?' do
|
|
105
|
-
haml :webhooks, locals: {'projects' => JPHRC['projects']}
|
|
120
|
+
haml :webhooks, locals: { 'projects' => JPHRC['projects'] }
|
|
106
121
|
end
|
|
107
122
|
|
|
108
123
|
get '/webhook/*' do
|
|
109
124
|
if params[:splat]
|
|
110
125
|
pass
|
|
111
126
|
else
|
|
112
|
-
halt 405, {'Content-Type' => 'application/json'}, {message: 'GET not allowed'}.to_json
|
|
127
|
+
halt 405, { 'Content-Type' => 'application/json' }, { message: 'GET not allowed' }.to_json
|
|
113
128
|
end
|
|
114
|
-
|
|
115
129
|
end
|
|
116
130
|
post '/webhook/:hook_name/?' do
|
|
117
131
|
service = nil
|
|
@@ -123,48 +137,40 @@ module SiteHook
|
|
|
123
137
|
begin
|
|
124
138
|
project = projects.fetch(params[:hook_name])
|
|
125
139
|
rescue KeyError => e
|
|
126
|
-
halt 404, {'Content-Type' => 'application/json'}, {message: 'no such project', status: 1}.to_json
|
|
140
|
+
halt 404, { 'Content-Type' => 'application/json' }, { message: 'no such project', status: 1 }.to_json
|
|
127
141
|
end
|
|
128
142
|
plaintext = false
|
|
129
143
|
signature = nil
|
|
130
144
|
event = nil
|
|
131
145
|
github = request.env.fetch('HTTP_X_GITHUB_EVENT', nil)
|
|
132
146
|
unless github.nil?
|
|
133
|
-
if github == 'push'
|
|
134
|
-
event = 'push'
|
|
135
|
-
end
|
|
147
|
+
event = 'push' if github == 'push'
|
|
136
148
|
end
|
|
137
149
|
gitlab = request.env.fetch('HTTP_X_GITLAB_EVENT', nil)
|
|
138
150
|
unless gitlab.nil?
|
|
139
|
-
if gitlab == 'push'
|
|
140
|
-
event = 'push'
|
|
141
|
-
end
|
|
151
|
+
event = 'push' if gitlab == 'push'
|
|
142
152
|
end
|
|
143
153
|
gogs = request.env.fetch('HTTP_X_GOGS_EVENT', nil)
|
|
144
154
|
unless gogs.nil?
|
|
145
|
-
if gogs == 'push'
|
|
146
|
-
event = 'push'
|
|
147
|
-
|
|
148
|
-
end
|
|
155
|
+
event = 'push' if gogs == 'push'
|
|
149
156
|
end
|
|
150
|
-
events = {'github' => github, 'gitlab' => gitlab, 'gogs' => gogs
|
|
151
|
-
}
|
|
157
|
+
events = { 'github' => github, 'gitlab' => gitlab, 'gogs' => gogs }
|
|
152
158
|
events_m_e = events.values.one?
|
|
153
159
|
case events_m_e
|
|
154
160
|
when true
|
|
155
161
|
event = 'push'
|
|
156
|
-
service = events.select { |
|
|
162
|
+
service = events.select { |_key, value| value }.keys.first
|
|
157
163
|
when false
|
|
158
|
-
halt 400, {'Content-Type'
|
|
159
|
-
}.to_json
|
|
164
|
+
halt 400, { 'Content-Type': 'application/json' }, { message: 'events are mutually exclusive', status: 'failure' }.to_json
|
|
160
165
|
|
|
161
166
|
else
|
|
162
|
-
halt 400,
|
|
163
|
-
|
|
167
|
+
halt 400,
|
|
168
|
+
{ 'Content-Type': 'application/json' },
|
|
169
|
+
'status': 'failure', 'message': 'something weird happened'
|
|
164
170
|
end
|
|
165
171
|
if event != 'push'
|
|
166
172
|
if event.nil?
|
|
167
|
-
halt 400, {'Content-Type'
|
|
173
|
+
halt 400, { 'Content-Type': 'application/json' }, { message: 'no event header' }.to_json
|
|
168
174
|
end
|
|
169
175
|
end
|
|
170
176
|
case service
|
|
@@ -172,9 +178,7 @@ module SiteHook
|
|
|
172
178
|
signature = request.env.fetch('HTTP_X_GITLAB_TOKEN', '')
|
|
173
179
|
plaintext = true
|
|
174
180
|
when 'github'
|
|
175
|
-
signature = request.env.fetch('HTTP_X_HUB_SIGNATURE', ''
|
|
176
|
-
).sub!(/^sha1=/, ''
|
|
177
|
-
)
|
|
181
|
+
signature = request.env.fetch('HTTP_X_HUB_SIGNATURE', '').sub!(/^sha1=/, '')
|
|
178
182
|
plaintext = false
|
|
179
183
|
|
|
180
184
|
when 'gogs'
|
|
@@ -191,22 +195,22 @@ module SiteHook
|
|
|
191
195
|
when 0
|
|
192
196
|
status 200
|
|
193
197
|
headers 'Content-Type' => 'application/json'
|
|
194
|
-
body { {'status': 'success'}.to_json
|
|
195
|
-
}
|
|
198
|
+
body { { 'status': 'success' }.to_json }
|
|
196
199
|
when -1, -2, -3
|
|
197
200
|
status 400
|
|
198
201
|
headers 'Content-Type' => 'application/json'
|
|
199
|
-
body
|
|
200
|
-
|
|
202
|
+
body do
|
|
203
|
+
{ 'status': 'exception', error: jekyll_status.fetch(:message).to_s }
|
|
204
|
+
end
|
|
201
205
|
end
|
|
202
206
|
|
|
203
207
|
else
|
|
204
|
-
halt 403, {'Content-Type' => 'application/json'}, {message: 'incorrect secret', 'status': 'failure'}.to_json
|
|
208
|
+
halt 403, { 'Content-Type' => 'application/json' }, { message: 'incorrect secret', 'status': 'failure' }.to_json
|
|
205
209
|
end
|
|
206
210
|
end
|
|
207
211
|
post '/webhook/?' do
|
|
208
|
-
halt 403, {'Content-Type' => 'application/json'}, {message: 'pick a hook', error: 'root webhook hit', 'status': 'failure'
|
|
209
|
-
}.to_json
|
|
212
|
+
halt 403, { 'Content-Type' => 'application/json' }, { message: 'pick a hook', error: 'root webhook hit', 'status': 'failure' }.to_json
|
|
210
213
|
end
|
|
211
214
|
end
|
|
215
|
+
# rubocop:enable Metrics/ClassLength, Metrics/LineLength, MethodLength, BlockLength
|
|
212
216
|
end
|
data/lib/site_hook/cli.rb
CHANGED
|
@@ -41,15 +41,12 @@ module SiteHook
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
method_option(:log_levels, type: :hash, banner: 'LEVELS', default: SiteHook.log_levels)
|
|
44
|
-
|
|
45
44
|
desc 'start', 'Start SiteHook'
|
|
46
|
-
|
|
47
45
|
def start
|
|
48
46
|
|
|
49
|
-
SiteHook.mklogdir unless
|
|
47
|
+
SiteHook.mklogdir unless SiteHook::Gem::Paths.logs.exist?
|
|
50
48
|
SiteHook::Webhook.run!
|
|
51
49
|
end
|
|
52
|
-
|
|
53
50
|
desc 'config SUBCOMMAND [OPTIONS]', 'Configure site_hook options'
|
|
54
51
|
subcommand('config', SiteHook::ConfigClass)
|
|
55
52
|
end
|
|
@@ -1,60 +1,92 @@
|
|
|
1
1
|
require 'thor'
|
|
2
|
+
require 'highline'
|
|
3
|
+
require 'random_password'
|
|
2
4
|
require 'yaml'
|
|
3
5
|
require 'recursive-open-struct'
|
|
4
6
|
module SiteHook
|
|
5
7
|
class FileExistsError < Exception
|
|
6
8
|
end
|
|
7
|
-
class ConfigClass < Thor
|
|
8
|
-
YML = open(Pathname(Dir.home).join('.jph-rc'), 'r')
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
# *ConfigClass*
|
|
11
|
+
#
|
|
12
|
+
# Holds all of the commands for the config subcommand
|
|
13
|
+
class ConfigClass < Thor
|
|
11
14
|
|
|
12
|
-
def list
|
|
13
|
-
puts YML.read
|
|
14
|
-
end
|
|
15
|
-
method_option :file, type: :boolean, banner: 'FILE', default: false, aliases: %w(-f)
|
|
16
15
|
desc 'gen [options]', "Generate a example config file if one doesn't exist"
|
|
16
|
+
# rubocop:disable Metrics/AbcSize
|
|
17
17
|
def gen
|
|
18
18
|
yaml = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
35
|
]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
yaml.each do |line|
|
|
44
|
-
f.puts line
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
say "Created #{jphrc}"
|
|
48
|
-
say "You can now edit #{jphrc} and add your projects."
|
|
36
|
+
jphrc = SiteHook::Gem::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
|
|
49
43
|
end
|
|
50
|
-
rescue SiteHook::FileExistsError => e
|
|
51
|
-
puts e
|
|
52
44
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
puts yaml
|
|
45
|
+
say "Created #{jphrc}"
|
|
46
|
+
say "You can now edit #{jphrc} and add your projects."
|
|
56
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('> ')
|
|
57
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
|
|
58
89
|
end
|
|
59
90
|
end
|
|
60
91
|
end
|
|
92
|
+
# rubocop:enable Metrics/AbcSize
|
data/lib/site_hook/sender.rb
CHANGED
|
@@ -25,11 +25,11 @@ module SiteHook
|
|
|
25
25
|
fakelog = SiteHook::HookLogger::FakeLog.new
|
|
26
26
|
reallog = SiteHook::HookLogger::GitLog.new(SiteHook.log_levels['git']).log
|
|
27
27
|
jekyll_source = Jekyll.instance_variable_get('@jekyll_source')
|
|
28
|
-
build_dest = Jekyll.instance_variable_get('@build_dest')
|
|
29
|
-
g = Git.open(jekyll_source, :
|
|
28
|
+
# build_dest = Jekyll.instance_variable_get('@build_dest')
|
|
29
|
+
g = Git.open(jekyll_source, log: fakelog)
|
|
30
30
|
g.pull
|
|
31
31
|
fakelog.entries.each do |level, entries|
|
|
32
|
-
entries.each { |entry| reallog.send(
|
|
32
|
+
entries.each { |entry| reallog.send(level.to_s, entry) }
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ module SiteHook
|
|
|
38
38
|
build_dest = Jekyll.instance_variable_get('@build_dest')
|
|
39
39
|
log = Jekyll.instance_variable_get('@log')
|
|
40
40
|
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}") { |in_io, outerr_io, thr|
|
|
41
|
-
pid = thr.pid
|
|
41
|
+
# pid = thr.pid
|
|
42
42
|
|
|
43
43
|
outerr = outerr_io.read.lines
|
|
44
44
|
outerr.each do |line|
|
|
@@ -49,7 +49,8 @@ module SiteHook
|
|
|
49
49
|
# Destination: /var/www/iotaspencer.me
|
|
50
50
|
# Incremental build: disabled. Enable with --incremental
|
|
51
51
|
# Generating...
|
|
52
|
-
# GitHub Metadata: No GitHub API authentication could be found.
|
|
52
|
+
# GitHub Metadata: No GitHub API authentication could be found.
|
|
53
|
+
# Some fields may be missing or have incorrect data.
|
|
53
54
|
# done in 6.847 seconds.
|
|
54
55
|
# Auto-regeneration: disabled. Use --watch to enable.
|
|
55
56
|
case
|
data/lib/site_hook/version.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#webhook-list.list-group
|
|
2
2
|
- projects.each do |name, hsh|
|
|
3
3
|
- if hsh.fetch('private', nil).nil? or hsh.fetch('private', nil)
|
|
4
|
-
%a{id: "#{hsh['repo'].sub(/\./, '-').sub(/\//, '-')}",
|
|
4
|
+
%a.list-group-item{id: "#{hsh['repo'].sub(/\./, '-').sub(/\//, '-')}", href: "https://#{hsh['host']}/#{hsh['repo']}"}
|
|
5
5
|
#{name}
|
|
6
|
-
%span
|
|
6
|
+
%span.badge.badge-pill.badge-dark "https://#{hsh['host']}/#{hsh['repo']}"
|
data/site_hook.gemspec
CHANGED
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
|
16
16
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
17
17
|
if spec.respond_to?(:metadata)
|
|
18
18
|
spec.metadata['source_uri'] = 'https://github.com/IotaSpencer/site_hook'
|
|
19
|
+
spec.metadata['tutorial'] = 'https://iotaspencer.me/projects/site_hook/'
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
@@ -24,20 +25,21 @@ Gem::Specification.new do |spec|
|
|
|
24
25
|
spec.bindir = 'bin'
|
|
25
26
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
26
27
|
spec.require_paths = ['lib']
|
|
27
|
-
spec.add_runtime_dependency '
|
|
28
|
-
spec.add_runtime_dependency 'sinatra-contrib', '~> 2.0', '>= 2.0.2'
|
|
29
|
-
spec.add_runtime_dependency 'thor', '~> 0.20'
|
|
30
|
-
spec.add_runtime_dependency 'paint', '~> 2.0'
|
|
28
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.1'
|
|
31
29
|
spec.add_runtime_dependency 'git', '~> 1.3'
|
|
30
|
+
spec.add_runtime_dependency 'haml', '~> 5.0'
|
|
31
|
+
spec.add_runtime_dependency 'highline', '~> 2.0', '>= 2.0.0'
|
|
32
32
|
spec.add_runtime_dependency 'logging', '~> 2.2'
|
|
33
|
+
spec.add_runtime_dependency 'paint', '~> 2.0'
|
|
33
34
|
spec.add_runtime_dependency 'pry', '~> 0.11'
|
|
34
|
-
spec.add_runtime_dependency '
|
|
35
|
-
spec.add_runtime_dependency 'activesupport', '~> 5.1'
|
|
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 'haml', '~> 5.0'
|
|
38
37
|
spec.add_runtime_dependency 'sass', '~> 3.5'
|
|
38
|
+
spec.add_runtime_dependency 'sinatra', '~> 2.0', '>= 2.0.2'
|
|
39
|
+
spec.add_runtime_dependency 'sinatra-contrib', '~> 2.0', '>= 2.0.2'
|
|
40
|
+
spec.add_runtime_dependency 'thin', '~> 1.7'
|
|
41
|
+
spec.add_runtime_dependency 'thor', '~> 0.20'
|
|
39
42
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
40
43
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
41
44
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
42
|
-
|
|
43
45
|
end
|
metadata
CHANGED
|
@@ -1,37 +1,59 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: site_hook
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ken Spencer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: activesupport
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
|
|
19
|
+
version: '5.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
21
25
|
- !ruby/object:Gem::Version
|
|
22
|
-
version:
|
|
26
|
+
version: '5.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: git
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.3'
|
|
23
34
|
type: :runtime
|
|
24
35
|
prerelease: false
|
|
25
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
37
|
requirements:
|
|
27
38
|
- - "~>"
|
|
28
39
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '
|
|
30
|
-
|
|
40
|
+
version: '1.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: haml
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
31
46
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
33
55
|
- !ruby/object:Gem::Dependency
|
|
34
|
-
name:
|
|
56
|
+
name: highline
|
|
35
57
|
requirement: !ruby/object:Gem::Requirement
|
|
36
58
|
requirements:
|
|
37
59
|
- - "~>"
|
|
@@ -39,7 +61,7 @@ dependencies:
|
|
|
39
61
|
version: '2.0'
|
|
40
62
|
- - ">="
|
|
41
63
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 2.0.
|
|
64
|
+
version: 2.0.0
|
|
43
65
|
type: :runtime
|
|
44
66
|
prerelease: false
|
|
45
67
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -49,21 +71,21 @@ dependencies:
|
|
|
49
71
|
version: '2.0'
|
|
50
72
|
- - ">="
|
|
51
73
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: 2.0.
|
|
74
|
+
version: 2.0.0
|
|
53
75
|
- !ruby/object:Gem::Dependency
|
|
54
|
-
name:
|
|
76
|
+
name: logging
|
|
55
77
|
requirement: !ruby/object:Gem::Requirement
|
|
56
78
|
requirements:
|
|
57
79
|
- - "~>"
|
|
58
80
|
- !ruby/object:Gem::Version
|
|
59
|
-
version: '
|
|
81
|
+
version: '2.2'
|
|
60
82
|
type: :runtime
|
|
61
83
|
prerelease: false
|
|
62
84
|
version_requirements: !ruby/object:Gem::Requirement
|
|
63
85
|
requirements:
|
|
64
86
|
- - "~>"
|
|
65
87
|
- !ruby/object:Gem::Version
|
|
66
|
-
version: '
|
|
88
|
+
version: '2.2'
|
|
67
89
|
- !ruby/object:Gem::Dependency
|
|
68
90
|
name: paint
|
|
69
91
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -79,117 +101,129 @@ dependencies:
|
|
|
79
101
|
- !ruby/object:Gem::Version
|
|
80
102
|
version: '2.0'
|
|
81
103
|
- !ruby/object:Gem::Dependency
|
|
82
|
-
name:
|
|
104
|
+
name: pry
|
|
83
105
|
requirement: !ruby/object:Gem::Requirement
|
|
84
106
|
requirements:
|
|
85
107
|
- - "~>"
|
|
86
108
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: '
|
|
109
|
+
version: '0.11'
|
|
88
110
|
type: :runtime
|
|
89
111
|
prerelease: false
|
|
90
112
|
version_requirements: !ruby/object:Gem::Requirement
|
|
91
113
|
requirements:
|
|
92
114
|
- - "~>"
|
|
93
115
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: '
|
|
116
|
+
version: '0.11'
|
|
95
117
|
- !ruby/object:Gem::Dependency
|
|
96
|
-
name:
|
|
118
|
+
name: random_password
|
|
97
119
|
requirement: !ruby/object:Gem::Requirement
|
|
98
120
|
requirements:
|
|
99
121
|
- - "~>"
|
|
100
122
|
- !ruby/object:Gem::Version
|
|
101
|
-
version:
|
|
123
|
+
version: 0.1.1
|
|
102
124
|
type: :runtime
|
|
103
125
|
prerelease: false
|
|
104
126
|
version_requirements: !ruby/object:Gem::Requirement
|
|
105
127
|
requirements:
|
|
106
128
|
- - "~>"
|
|
107
129
|
- !ruby/object:Gem::Version
|
|
108
|
-
version:
|
|
130
|
+
version: 0.1.1
|
|
109
131
|
- !ruby/object:Gem::Dependency
|
|
110
|
-
name:
|
|
132
|
+
name: recursive-open-struct
|
|
111
133
|
requirement: !ruby/object:Gem::Requirement
|
|
112
134
|
requirements:
|
|
113
135
|
- - "~>"
|
|
114
136
|
- !ruby/object:Gem::Version
|
|
115
|
-
version: '
|
|
137
|
+
version: '1.1'
|
|
116
138
|
type: :runtime
|
|
117
139
|
prerelease: false
|
|
118
140
|
version_requirements: !ruby/object:Gem::Requirement
|
|
119
141
|
requirements:
|
|
120
142
|
- - "~>"
|
|
121
143
|
- !ruby/object:Gem::Version
|
|
122
|
-
version: '
|
|
144
|
+
version: '1.1'
|
|
123
145
|
- !ruby/object:Gem::Dependency
|
|
124
|
-
name:
|
|
146
|
+
name: sass
|
|
125
147
|
requirement: !ruby/object:Gem::Requirement
|
|
126
148
|
requirements:
|
|
127
149
|
- - "~>"
|
|
128
150
|
- !ruby/object:Gem::Version
|
|
129
|
-
version: '
|
|
151
|
+
version: '3.5'
|
|
130
152
|
type: :runtime
|
|
131
153
|
prerelease: false
|
|
132
154
|
version_requirements: !ruby/object:Gem::Requirement
|
|
133
155
|
requirements:
|
|
134
156
|
- - "~>"
|
|
135
157
|
- !ruby/object:Gem::Version
|
|
136
|
-
version: '
|
|
158
|
+
version: '3.5'
|
|
137
159
|
- !ruby/object:Gem::Dependency
|
|
138
|
-
name:
|
|
160
|
+
name: sinatra
|
|
139
161
|
requirement: !ruby/object:Gem::Requirement
|
|
140
162
|
requirements:
|
|
141
163
|
- - "~>"
|
|
142
164
|
- !ruby/object:Gem::Version
|
|
143
|
-
version: '
|
|
165
|
+
version: '2.0'
|
|
166
|
+
- - ">="
|
|
167
|
+
- !ruby/object:Gem::Version
|
|
168
|
+
version: 2.0.2
|
|
144
169
|
type: :runtime
|
|
145
170
|
prerelease: false
|
|
146
171
|
version_requirements: !ruby/object:Gem::Requirement
|
|
147
172
|
requirements:
|
|
148
173
|
- - "~>"
|
|
149
174
|
- !ruby/object:Gem::Version
|
|
150
|
-
version: '
|
|
175
|
+
version: '2.0'
|
|
176
|
+
- - ">="
|
|
177
|
+
- !ruby/object:Gem::Version
|
|
178
|
+
version: 2.0.2
|
|
151
179
|
- !ruby/object:Gem::Dependency
|
|
152
|
-
name:
|
|
180
|
+
name: sinatra-contrib
|
|
153
181
|
requirement: !ruby/object:Gem::Requirement
|
|
154
182
|
requirements:
|
|
155
183
|
- - "~>"
|
|
156
184
|
- !ruby/object:Gem::Version
|
|
157
|
-
version: '
|
|
185
|
+
version: '2.0'
|
|
186
|
+
- - ">="
|
|
187
|
+
- !ruby/object:Gem::Version
|
|
188
|
+
version: 2.0.2
|
|
158
189
|
type: :runtime
|
|
159
190
|
prerelease: false
|
|
160
191
|
version_requirements: !ruby/object:Gem::Requirement
|
|
161
192
|
requirements:
|
|
162
193
|
- - "~>"
|
|
163
194
|
- !ruby/object:Gem::Version
|
|
164
|
-
version: '
|
|
195
|
+
version: '2.0'
|
|
196
|
+
- - ">="
|
|
197
|
+
- !ruby/object:Gem::Version
|
|
198
|
+
version: 2.0.2
|
|
165
199
|
- !ruby/object:Gem::Dependency
|
|
166
|
-
name:
|
|
200
|
+
name: thin
|
|
167
201
|
requirement: !ruby/object:Gem::Requirement
|
|
168
202
|
requirements:
|
|
169
203
|
- - "~>"
|
|
170
204
|
- !ruby/object:Gem::Version
|
|
171
|
-
version: '
|
|
205
|
+
version: '1.7'
|
|
172
206
|
type: :runtime
|
|
173
207
|
prerelease: false
|
|
174
208
|
version_requirements: !ruby/object:Gem::Requirement
|
|
175
209
|
requirements:
|
|
176
210
|
- - "~>"
|
|
177
211
|
- !ruby/object:Gem::Version
|
|
178
|
-
version: '
|
|
212
|
+
version: '1.7'
|
|
179
213
|
- !ruby/object:Gem::Dependency
|
|
180
|
-
name:
|
|
214
|
+
name: thor
|
|
181
215
|
requirement: !ruby/object:Gem::Requirement
|
|
182
216
|
requirements:
|
|
183
217
|
- - "~>"
|
|
184
218
|
- !ruby/object:Gem::Version
|
|
185
|
-
version: '
|
|
219
|
+
version: '0.20'
|
|
186
220
|
type: :runtime
|
|
187
221
|
prerelease: false
|
|
188
222
|
version_requirements: !ruby/object:Gem::Requirement
|
|
189
223
|
requirements:
|
|
190
224
|
- - "~>"
|
|
191
225
|
- !ruby/object:Gem::Version
|
|
192
|
-
version: '
|
|
226
|
+
version: '0.20'
|
|
193
227
|
- !ruby/object:Gem::Dependency
|
|
194
228
|
name: bundler
|
|
195
229
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -243,6 +277,7 @@ extra_rdoc_files: []
|
|
|
243
277
|
files:
|
|
244
278
|
- ".gitignore"
|
|
245
279
|
- ".rspec"
|
|
280
|
+
- ".rubocop.yml"
|
|
246
281
|
- ".travis.yml"
|
|
247
282
|
- CODE_OF_CONDUCT.md
|
|
248
283
|
- Gemfile
|
|
@@ -268,6 +303,7 @@ licenses:
|
|
|
268
303
|
- MIT
|
|
269
304
|
metadata:
|
|
270
305
|
source_uri: https://github.com/IotaSpencer/site_hook
|
|
306
|
+
tutorial: https://iotaspencer.me/projects/site_hook/
|
|
271
307
|
post_install_message:
|
|
272
308
|
rdoc_options: []
|
|
273
309
|
require_paths:
|