overlay 0.0.2 → 0.0.4
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/app/controllers/overlay/github_controller.rb +10 -0
- data/config/routes.rb +1 -1
- data/lib/overlay.rb +1 -1
- data/lib/overlay/configuration.rb +3 -2
- data/lib/overlay/github.rb +114 -0
- data/lib/overlay/version.rb +1 -1
- metadata +2 -2
- data/lib/overlay/git.rb +0 -111
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ccbfd578014c00094c8eb7b434a5ca509c75eb
|
4
|
+
data.tar.gz: cdd707ea7987ecbe0ac9cc01a872323408240099
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02ff926a5c3600648642ce92f802b044ed97c0643a7faaf450012b807d8090757e8777b8de9bfbf0f5afb621224edbfd1589020c22867aee499032e8229e9b88
|
7
|
+
data.tar.gz: ad846c7c49712f864bf213857a4690486c07373d496786b97da699199dc762bca5be07334fdfbaf69b99de2e175279d8f3eda88941245091558ed375c510ef4a
|
@@ -3,6 +3,16 @@ require_dependency "overlay/application_controller"
|
|
3
3
|
module Overlay
|
4
4
|
class GithubController < ApplicationController
|
5
5
|
def update
|
6
|
+
Overlay.configuration.repositories.each do |repo_config|
|
7
|
+
next unless repo_config.class == GithubRepo
|
8
|
+
branch = repo_config[:branch] || 'master'
|
9
|
+
if (params[:repository] && params[:webhook])
|
10
|
+
if (params[:repository][:name] == repo_config[:repo]) && (params[:webhook][:ref] == "refs/heads/#{branch}")
|
11
|
+
Overlay::Github.process_overlays
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
render :inline => github_update_url
|
6
16
|
end
|
7
17
|
end
|
8
18
|
end
|
data/config/routes.rb
CHANGED
data/lib/overlay.rb
CHANGED
@@ -7,7 +7,8 @@ module Overlay
|
|
7
7
|
:auth,
|
8
8
|
:repositories,
|
9
9
|
:hostname,
|
10
|
-
:host_port
|
10
|
+
:host_port,
|
11
|
+
:relative_root_url
|
11
12
|
].freeze
|
12
13
|
|
13
14
|
class << self
|
@@ -29,5 +30,5 @@ module Overlay
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
GithubRepo = Struct.new(:
|
33
|
+
GithubRepo = Struct.new(:user, :repo, :branch, :root_path)
|
33
34
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'github_api'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
module Overlay
|
6
|
+
class Github
|
7
|
+
include Overlay::Engine.routes.url_helpers
|
8
|
+
# Cycle through all configured repositories and overlay
|
9
|
+
#
|
10
|
+
def self.process_overlays
|
11
|
+
# If we aren't running in Rails, bail out. This may be some
|
12
|
+
# other request such as rake routes loading the environment
|
13
|
+
#
|
14
|
+
return unless defined?(Rails::Server)
|
15
|
+
|
16
|
+
# Configure github api
|
17
|
+
configure
|
18
|
+
|
19
|
+
Overlay.configuration.repositories.each do |repo_config|
|
20
|
+
next unless repo_config.class == GithubRepo
|
21
|
+
|
22
|
+
# Validate repository config
|
23
|
+
raise 'Respository config missing user' if (!repo_config[:user] || repo_config[:user].nil?)
|
24
|
+
raise 'Respository config missing repo' if (!repo_config[:repo] || repo_config[:repo].nil?)
|
25
|
+
|
26
|
+
repo_config[:branch] ||= 'master'
|
27
|
+
|
28
|
+
register_web_hook(repo_config)
|
29
|
+
|
30
|
+
overlay_repo(repo_config)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Register our listener on the repo
|
35
|
+
#
|
36
|
+
def self.register_web_hook repo_config
|
37
|
+
# Make sure our routes are loaded
|
38
|
+
Rails.application.reload_routes!
|
39
|
+
|
40
|
+
# Build hook url
|
41
|
+
host = config.hostname || Socket.gethostname
|
42
|
+
port = config.host_port || Rails::Server.new.options[:Port]
|
43
|
+
path = Overlay::Engine.routes.url_for({:controller=>"overlay/github", :action=>"update", :only_path => true})
|
44
|
+
uri = ActionDispatch::Http::URL::url_for({:host => host, :port => port, :path => "#{config.relative_root_url}#{path}"})
|
45
|
+
|
46
|
+
# Retrieve current web hooks
|
47
|
+
current_hooks = github_repo.hooks.list(repo_config[:user], repo_config[:repo]).response.body
|
48
|
+
if current_hooks.find {|hook| hook.config.url == uri}.nil?
|
49
|
+
#register hook
|
50
|
+
github_repo.hooks.create(repo_config[:user], repo_config[:repo], name: 'web', active: true, config: {:url => uri, :content_type => 'json'})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.overlay_repo repo_config
|
55
|
+
# Get our root entries
|
56
|
+
#
|
57
|
+
root_entries = github_repo.contents.get(repo_config[:user], repo_config[:repo], '/', ref: repo_config[:branch]).response.body
|
58
|
+
|
59
|
+
# We aren't pulling anything out of root. Cycle through directories and overlay
|
60
|
+
#
|
61
|
+
root_entries.each do |entry|
|
62
|
+
if entry.type == 'dir'
|
63
|
+
overlay_directory(entry.path, repo_config)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.overlay_directory path, repo_config
|
69
|
+
root_path = repo_config[:root_path].empty? ? "#{Rails.application.root}/#{repo_config[:root_path]}" : "#{Rails.application.root}"
|
70
|
+
|
71
|
+
FileUtils.mkdir_p "#{root_path}/#{path}"
|
72
|
+
directory_entries = github_repo.contents.get(repo_config[:user], repo_config[:repo], path, ref: repo_config[:branch]).response.body
|
73
|
+
|
74
|
+
directory_entries.each do |entry|
|
75
|
+
if entry.type == 'dir'
|
76
|
+
overlay_directory(entry.path, repo_config)
|
77
|
+
elsif entry.type == 'file'
|
78
|
+
clone_file(entry.path, repo_config)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.clone_file path, repo_config
|
84
|
+
root_path = repo_config[:root_path].empty? ? "#{Rails.application.root}/#{repo_config[:root_path]}" : "#{Rails.application.root}"
|
85
|
+
|
86
|
+
file = github_repo.contents.get(repo_config[:user], repo_config[:repo], path, ref: repo_config[:branch]).response.body.content
|
87
|
+
File.open("#{root_path}/#{path}", "wb") { |f| f.write(Base64.decode64(file)) }
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def self.github_repo
|
93
|
+
@@github ||= ::Github::Repos.new
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.config
|
97
|
+
@@overlay_config ||= Overlay.configuration
|
98
|
+
end
|
99
|
+
|
100
|
+
# Configure the github api
|
101
|
+
def self.configure
|
102
|
+
# Validate required config
|
103
|
+
raise 'Configuration github_overlays.basic_auth not set' if (!config.auth || config.auth.nil?)
|
104
|
+
|
105
|
+
::Github.configure do |github_config|
|
106
|
+
github_config.endpoint = config.endpoint if config.endpoint
|
107
|
+
github_config.site = config.site if config.site
|
108
|
+
github_config.basic_auth = config.auth
|
109
|
+
github_config.adapter = :net_http
|
110
|
+
github_config.ssl = {:verify => false}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/overlay/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overlay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Saarinen
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- config/routes.rb
|
68
68
|
- lib/overlay/configuration.rb
|
69
69
|
- lib/overlay/engine.rb
|
70
|
-
- lib/overlay/
|
70
|
+
- lib/overlay/github.rb
|
71
71
|
- lib/overlay/version.rb
|
72
72
|
- lib/overlay.rb
|
73
73
|
- lib/tasks/overlay_tasks.rake
|
data/lib/overlay/git.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'github_api'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
module Overlay
|
6
|
-
class Github
|
7
|
-
include Overlay::Engine.routes.url_helpers
|
8
|
-
# Cycle through all configured repositories and overlay
|
9
|
-
#
|
10
|
-
def self.process_overlays
|
11
|
-
# If we aren't running in Rails, bail out. This may be some
|
12
|
-
# other request such as rake routes loading the environment
|
13
|
-
#
|
14
|
-
return unless defined?(Rails::Server)
|
15
|
-
|
16
|
-
# Configure github api
|
17
|
-
configure
|
18
|
-
|
19
|
-
Overlay.configuration.repositories.each do |repo_config|
|
20
|
-
break unless repo_config.class == GithubRepo
|
21
|
-
|
22
|
-
# Validate repository config
|
23
|
-
raise 'Respository config missing user' if (!repo_config[:user] || repo_config[:user].nil?)
|
24
|
-
raise 'Respository config missing repo' if (!repo_config[:repo] || repo_config[:repo].nil?)
|
25
|
-
|
26
|
-
branch = repo_config[:branch] || 'master'
|
27
|
-
|
28
|
-
register_web_hook(repo_config[:user], repo_config[:repo])
|
29
|
-
|
30
|
-
overlay_repo(repo_config[:user], repo_config[:repo], branch)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Register our listener on the repo
|
35
|
-
#
|
36
|
-
def self.register_web_hook user, repo
|
37
|
-
# Make sure our routes are loaded
|
38
|
-
Rails.application.reload_routes!
|
39
|
-
|
40
|
-
# Build hook url
|
41
|
-
host = Overlay.configuration.hostname || Socket.gethostname
|
42
|
-
port = Overlay.configuration.host_port || Rails::Server.new.options[:Port]
|
43
|
-
uri = Overlay::Engine.routes.url_for({:controller=>"github_overlays/webhooks", :action=>"update", :host => host, :port => port})
|
44
|
-
|
45
|
-
# Retrieve current web hooks
|
46
|
-
current_hooks = github_repo.hooks.list(user, repo).response.body
|
47
|
-
if current_hooks.find {|hook| hook.config.url == uri}.nil?
|
48
|
-
#register hook
|
49
|
-
github_repo.hooks.create(user, repo, name: 'web', active: true, config: {:url => uri, :content_type => 'json'})
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.overlay_repo user, repo, branch
|
54
|
-
# Get our root entries
|
55
|
-
#
|
56
|
-
root_entries = github_repo.contents.get(user, repo, '/', ref: branch).response.body
|
57
|
-
|
58
|
-
# We aren't pulling anything out of root. Cycle through directories and overlay
|
59
|
-
#
|
60
|
-
root_entries.each do |entry|
|
61
|
-
if entry.type == 'dir'
|
62
|
-
overlay_directory(entry.path, user, repo, branch)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.overlay_directory path, user, repo, branch
|
68
|
-
FileUtils.mkdir_p "#{Rails.application.root}/#{path}"
|
69
|
-
directory_entries = github_repo.contents.get(user, repo, path, ref: branch).response.body
|
70
|
-
|
71
|
-
directory_entries.each do |entry|
|
72
|
-
if entry.type == 'dir'
|
73
|
-
overlay_directory(entry.path, user, repo, branch)
|
74
|
-
elsif entry.type == 'file'
|
75
|
-
clone_file(entry.path, user, repo, branch)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.clone_file path, user, repo, branch
|
81
|
-
file = github_repo.contents.get(user, repo, path, ref: branch).response.body.content
|
82
|
-
File.open("#{Rails.application.root}/#{path}", "wb") { |f| f.write(Base64.decode64(file)) }
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def self.github_repo
|
88
|
-
@@github ||= Github::Repos.new
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.config
|
92
|
-
@@overlay_config ||= Rails.application.config.github_overlays
|
93
|
-
end
|
94
|
-
|
95
|
-
# Configure the github api
|
96
|
-
def self.configure
|
97
|
-
overlay_config = Overlay.configuration
|
98
|
-
|
99
|
-
# Validate required config
|
100
|
-
raise 'Configuration github_overlays.basic_auth not set' if (!overlay_config.auth || overlay_config.auth.nil?)
|
101
|
-
|
102
|
-
Github.configure do |github_config|
|
103
|
-
github_config.endpoint = overlay_config.endpoint if overlay_config.endpoint
|
104
|
-
github_config.site = overlay_config.site if overlay_config.site
|
105
|
-
github_config.basic_auth = overlay_config.auth
|
106
|
-
github_config.adapter = :net_http
|
107
|
-
github_config.ssl = {:verify => false}
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|