site_hook 0.4.0 → 0.5.0
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/lib/site_hook.rb +63 -6
- data/lib/site_hook/cli.rb +10 -1
- data/lib/site_hook/config_class.rb +30 -7
- data/lib/site_hook/static/sass/styles.scss +9 -0
- data/lib/site_hook/version.rb +1 -1
- data/lib/site_hook/views/layout.haml +24 -0
- data/lib/site_hook/views/webhooks.haml +6 -0
- data/site_hook.gemspec +2 -0
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b91ef665dece23dcb7dbc74835e8615686fca06f
|
4
|
+
data.tar.gz: cac8dd89fd31b748136a4ea995b1477cd90a7cdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8ba7d33d2b7a819f1d3ac2a3fc91640ed548165659372631deece7b23c956beeb3d7592415c84901012578e78b3052bbf8f66a52201c6f607e864a04f4c0d66
|
7
|
+
data.tar.gz: eb7cde1074571eebb5c96dd673f079cdadf1cc4161fb00c165c90df9a02a4aff20462ce108ee6b49388a0f8aa9dc844eebafbac690f44f1cd5e73c59d19c41d5
|
data/.gitignore
CHANGED
data/lib/site_hook.rb
CHANGED
@@ -4,10 +4,40 @@ require 'site_hook/logger'
|
|
4
4
|
require 'recursive-open-struct'
|
5
5
|
require 'site_hook/cli'
|
6
6
|
require 'sinatra'
|
7
|
+
require 'haml'
|
8
|
+
require 'sass'
|
7
9
|
require 'json'
|
10
|
+
require 'sinatra/json'
|
8
11
|
require 'yaml'
|
9
12
|
|
10
13
|
module SiteHook
|
14
|
+
module Gem
|
15
|
+
class Info
|
16
|
+
def self.name
|
17
|
+
'site_hook'
|
18
|
+
end
|
19
|
+
def self.constant_name
|
20
|
+
'SiteHook'
|
21
|
+
end
|
22
|
+
def self.author
|
23
|
+
%q(Ken Spencer <me@iotaspencer.me>)
|
24
|
+
end
|
25
|
+
end
|
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
|
+
class CoffeeHandler < Sinatra::Base
|
35
|
+
set :views, Pathname(app_file).dirname.join('site_hook', 'static', 'coffee').to_s
|
36
|
+
get '/js/*.js' do
|
37
|
+
filename = params[:splat].first
|
38
|
+
coffee filename.to_sym
|
39
|
+
end
|
40
|
+
end
|
11
41
|
class Webhook < Sinatra::Base
|
12
42
|
HOOKLOG = SiteHook::HookLogger::HookLog.new(SiteHook.log_levels['hook']).log
|
13
43
|
BUILDLOG = SiteHook::HookLogger::BuildLog.new(SiteHook.log_levels['build']).log
|
@@ -18,7 +48,9 @@ module SiteHook
|
|
18
48
|
set server: %w(thin)
|
19
49
|
set quiet: true
|
20
50
|
set raise_errors: true
|
21
|
-
|
51
|
+
set views: Pathname(app_file).dirname.join('site_hook', 'views')
|
52
|
+
set :public_folder, Pathname(app_file).dirname.join('site_hook', 'static')
|
53
|
+
use SassHandler
|
22
54
|
# @param [String] body JSON String of body
|
23
55
|
# @param [String] sig Signature or token from git service
|
24
56
|
# @param [String] secret User-defined verification token
|
@@ -39,12 +71,38 @@ module SiteHook
|
|
39
71
|
end
|
40
72
|
|
41
73
|
get '/' do
|
42
|
-
halt 403, {'Content-Type' => '
|
74
|
+
halt 403, {'Content-Type' => 'text/html'}, "<h1>See <a href=\"/webhooks/\">here</a> for the active webhooks</h1>"
|
43
75
|
end
|
44
|
-
|
45
|
-
|
76
|
+
|
77
|
+
get '/webhooks.json', provides: :json do
|
78
|
+
content_type 'application/json'
|
79
|
+
public_projects = JPHRC['projects'].select do |project, hsh|
|
80
|
+
hsh.fetch('private', nil) == false or hsh.fetch('private', nil).nil?
|
81
|
+
end
|
82
|
+
result = {}
|
83
|
+
public_projects.each do |project, hsh|
|
84
|
+
result[project] = {}
|
85
|
+
hsh.delete('hookpass')
|
86
|
+
result[project].merge!(hsh)
|
87
|
+
end
|
88
|
+
headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
|
89
|
+
json result, layout: false
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
get '/webhooks/?' do
|
94
|
+
haml :webhooks, locals: {'projects' => JPHRC['projects']}
|
95
|
+
end
|
96
|
+
|
97
|
+
get '/webhook/*' do
|
98
|
+
if params[:splat]
|
99
|
+
pass
|
100
|
+
else
|
101
|
+
halt 405, {'Content-Type' => 'application/json'}, {message: 'GET not allowed'}.to_json
|
102
|
+
end
|
103
|
+
|
46
104
|
end
|
47
|
-
post '/webhook/:hook_name' do
|
105
|
+
post '/webhook/:hook_name/?' do
|
48
106
|
request.body.rewind
|
49
107
|
req_body = request.body.read
|
50
108
|
js = RecursiveOpenStruct.new(JSON.parse(req_body))
|
@@ -58,7 +116,6 @@ module SiteHook
|
|
58
116
|
plaintext = false
|
59
117
|
signature = nil
|
60
118
|
event = request.env.fetch('HTTP_X_GITLAB_EVENT', nil) || request.env.fetch('HTTP_X_GITHUB_EVENT', nil)
|
61
|
-
APPLOG.info event.inspect
|
62
119
|
if event != 'push'
|
63
120
|
if event.nil?
|
64
121
|
halt 400, {'Content-Type' => 'application/json'}, {message: 'no event header'}.to_json
|
data/lib/site_hook/cli.rb
CHANGED
@@ -28,7 +28,16 @@ module SiteHook
|
|
28
28
|
# Prints version string
|
29
29
|
# @return [NilClass] nil
|
30
30
|
def __print_version
|
31
|
-
puts SiteHook::VERSION
|
31
|
+
puts "Version: v#{SiteHook::VERSION}"
|
32
|
+
end
|
33
|
+
|
34
|
+
map %w(--gem-info --info --about) => :__gem_info
|
35
|
+
desc '--gem-info, --info, --about', 'Print info on the gem.'
|
36
|
+
def __gem_info
|
37
|
+
say "Gem Name: #{SiteHook::Gem::Info.name}"
|
38
|
+
say "Gem Constant: #{SiteHook::Gem::Info.constant_name}"
|
39
|
+
say "Gem Author: #{SiteHook::Gem::Info.author}"
|
40
|
+
say "Gem Version: v#{SiteHook::VERSION}"
|
32
41
|
end
|
33
42
|
|
34
43
|
method_option(:log_levels, type: :hash, banner: 'LEVELS', default: SiteHook.log_levels)
|
@@ -2,6 +2,8 @@ require 'thor'
|
|
2
2
|
require 'yaml'
|
3
3
|
require 'recursive-open-struct'
|
4
4
|
module SiteHook
|
5
|
+
class FileExistsError < Exception
|
6
|
+
end
|
5
7
|
class ConfigClass < Thor
|
6
8
|
YML = open(Pathname(Dir.home).join('.jph-rc'), 'r')
|
7
9
|
|
@@ -10,11 +12,9 @@ module SiteHook
|
|
10
12
|
def list
|
11
13
|
puts YML.read
|
12
14
|
end
|
13
|
-
method_option
|
15
|
+
method_option :file, type: :boolean, banner: 'FILE', default: false, aliases: %w(-f)
|
14
16
|
desc 'gen [options]', "Generate a example config file if one doesn't exist"
|
15
17
|
def gen
|
16
|
-
#return if Pathname(Dir.home).join('.jph-rc').exist?
|
17
|
-
|
18
18
|
yaml = [
|
19
19
|
"# fatal, error, warn, info, debug",
|
20
20
|
"log_levels:",
|
@@ -25,13 +25,36 @@ module SiteHook
|
|
25
25
|
"projects:",
|
26
26
|
" PROJECT.NAME: # Use the name you put as your webhook url",
|
27
27
|
" # https://jekyllhook.example.com/webhook/PROJECT.NAME",
|
28
|
-
" src: /path/
|
29
|
-
" dst: /path/
|
30
|
-
"
|
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",
|
31
34
|
"",
|
32
35
|
]
|
36
|
+
if options[:file]
|
37
|
+
jphrc = Pathname(Dir.home).join('.jph-rc')
|
38
|
+
begin
|
39
|
+
if jphrc.exist?
|
40
|
+
raise SiteHook::FileExistsError "#{jphrc} exists. Will not overwrite."
|
41
|
+
else
|
42
|
+
open(jphrc, 'w') do |f|
|
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."
|
49
|
+
end
|
50
|
+
rescue SiteHook::FileExistsError => e
|
51
|
+
puts e
|
52
|
+
end
|
53
|
+
|
54
|
+
else
|
55
|
+
puts yaml
|
56
|
+
end
|
33
57
|
|
34
|
-
puts yaml
|
35
58
|
end
|
36
59
|
end
|
37
60
|
end
|
data/lib/site_hook/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{charset: "utf-8"}
|
5
|
+
%meta{name: "viewport", content: "width=device-width, initial-scale=1, shrink-to-fit=yes"}
|
6
|
+
%link{rel: "stylesheet", href: "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css", integrity: "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm", crossorigin: "anonymous"}
|
7
|
+
%link{rel: "stylesheet", href: "/css/styles.css"}
|
8
|
+
|
9
|
+
%title Hello, world!
|
10
|
+
%body.bg-dark
|
11
|
+
%header.d-flex
|
12
|
+
%h1.text.light.d-flex.mx-auto Webhooks
|
13
|
+
|
14
|
+
#content.wrapper.card.bg-dark
|
15
|
+
=yield
|
16
|
+
%footer.container-fluid
|
17
|
+
%p.d-flex.justify-content-end.text-light
|
18
|
+
Powered by
|
19
|
+
%a{href: "https://iotaspencer.me/projects/site_hook"} #{" SiteHook "}
|
20
|
+
v#{SiteHook::VERSION}
|
21
|
+
|
22
|
+
%script{src: "https://code.jquery.com/jquery-3.2.1.slim.min.js", integrity: "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN", crossorigin: "anonymous"}
|
23
|
+
%script{src: "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js", integrity: "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q", crossorigin: "anonymous"}
|
24
|
+
%script{src: "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js", integrity: "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl", crossorigin: "anonymous"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#webhook-list.list-group
|
2
|
+
- projects.each do |name, hsh|
|
3
|
+
- if hsh.fetch('private', nil).nil? or hsh.fetch('private', nil)
|
4
|
+
%a{id: "#{hsh['repo'].sub(/\./, '-').sub(/\//, '-')}", class: "list-group-item",href: "https://#{hsh['host']}/#{hsh['repo']}"}
|
5
|
+
#{name}
|
6
|
+
%span{class: "badge badge-pill badge-dark"} https://#{hsh['host']}/#{hsh['repo']}
|
data/site_hook.gemspec
CHANGED
@@ -35,6 +35,8 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_runtime_dependency 'thin', '~> 1.7'
|
36
36
|
spec.add_runtime_dependency 'activesupport', '~> 5.1'
|
37
37
|
spec.add_runtime_dependency 'recursive-open-struct', '~> 1.1'
|
38
|
+
spec.add_runtime_dependency 'haml', '~> 5.0'
|
39
|
+
spec.add_runtime_dependency 'sass', '~> 3.5'
|
38
40
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
41
|
spec.add_development_dependency 'rake', '~> 10.0'
|
40
42
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
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-03-
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -150,6 +150,34 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '1.1'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: haml
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '5.0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '5.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: sass
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '3.5'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '3.5'
|
153
181
|
- !ruby/object:Gem::Dependency
|
154
182
|
name: bundler
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,7 +246,10 @@ files:
|
|
218
246
|
- lib/site_hook/logger.rb
|
219
247
|
- lib/site_hook/sender.rb
|
220
248
|
- lib/site_hook/spinner.rb
|
249
|
+
- lib/site_hook/static/sass/styles.scss
|
221
250
|
- lib/site_hook/version.rb
|
251
|
+
- lib/site_hook/views/layout.haml
|
252
|
+
- lib/site_hook/views/webhooks.haml
|
222
253
|
- site_hook.gemspec
|
223
254
|
homepage: https://iotaspencer.me/projects/site_hook/
|
224
255
|
licenses:
|