overlay 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/overlay.rb +2 -0
- data/lib/overlay/configuration.rb +33 -0
- data/lib/overlay/git.rb +111 -0
- data/lib/overlay/version.rb +1 -1
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ed5b5ecabe7f6db32dcc1d22a27f014e3b7148
|
4
|
+
data.tar.gz: f298741a03ee2625883981d073b4f93045de10d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ae58c5c453d6cb0b3d22a24d0f44c5fb3af5305bae5ea1fb6a6394ed829b67aa08be5077b7093d8a8bf44092ae42cec374ef4579af6fe5f3a4063c5015d47e
|
7
|
+
data.tar.gz: 4c2145676a72cb37da30019f20ba7925a0dd7880d1d75936a56af2f4f4f5b6644f5424472b71fe5bcb9a9166d656efcb2cb05ffb060c7c3d27e24ab84bee3b1a
|
data/lib/overlay.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Overlay
|
2
|
+
VALID_OPTIONS_KEYS = [
|
3
|
+
:site,
|
4
|
+
:endpoint,
|
5
|
+
:repo,
|
6
|
+
:user,
|
7
|
+
:auth,
|
8
|
+
:repositories,
|
9
|
+
:hostname,
|
10
|
+
:host_port
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
class Configuration
|
23
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@site = 'https://github.com'
|
27
|
+
@endpoint = 'https://api.github.com'
|
28
|
+
@repositories = Set.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
GithubRepo = Struct.new(:name, :repo, :branch)
|
33
|
+
end
|
data/lib/overlay/git.rb
ADDED
@@ -0,0 +1,111 @@
|
|
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
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Saarinen
|
@@ -14,16 +14,30 @@ dependencies:
|
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: github_api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
25
32
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec-rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,7 +65,9 @@ files:
|
|
51
65
|
- app/helpers/overlay/application_helper.rb
|
52
66
|
- app/views/layouts/overlay/application.html.erb
|
53
67
|
- config/routes.rb
|
68
|
+
- lib/overlay/configuration.rb
|
54
69
|
- lib/overlay/engine.rb
|
70
|
+
- lib/overlay/git.rb
|
55
71
|
- lib/overlay/version.rb
|
56
72
|
- lib/overlay.rb
|
57
73
|
- lib/tasks/overlay_tasks.rake
|