github_overlays 0.0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +21 -0
- data/app/assets/stylesheets/github_overlays/application.css +13 -0
- data/app/controllers/github_overlays/application_controller.rb +7 -0
- data/app/controllers/github_overlays/webhooks_controller.rb +15 -0
- data/app/helpers/github_overlays/application_helper.rb +4 -0
- data/app/views/layouts/github_overlays/application.html.erb +14 -0
- data/config/routes.rb +4 -0
- data/lib/github_overlays/configuration.rb +31 -0
- data/lib/github_overlays/engine.rb +13 -0
- data/lib/github_overlays/git.rb +109 -0
- data/lib/github_overlays/version.rb +3 -0
- data/lib/github_overlays.rb +9 -0
- data/lib/tasks/github_overlays_tasks.rake +4 -0
- metadata +114 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'GithubOverlays'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_dependency "github_overlays/application_controller"
|
2
|
+
|
3
|
+
module GithubOverlays
|
4
|
+
class WebhooksController < ApplicationController
|
5
|
+
def update
|
6
|
+
GithubOverlays.configuration.repositories.each do |repo_config|
|
7
|
+
branch = repo_config[:branch] || 'master'
|
8
|
+
if (params[:repository][:name] == repo_config[:repo]) && (params[:webhook][:ref] == "refs/heads/#{branch}")
|
9
|
+
GithubOverlays.overlay
|
10
|
+
end
|
11
|
+
end
|
12
|
+
render :nothing => true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>GithubOverlays</title>
|
5
|
+
<%= stylesheet_link_tag "github_overlays/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "github_overlays/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module GithubOverlays
|
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
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'github_api'
|
2
|
+
|
3
|
+
module GithubOverlays
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
isolate_namespace GithubOverlays
|
6
|
+
|
7
|
+
config.after_initialize do |app|
|
8
|
+
# Ensure we can operate mounted in a subdirectory
|
9
|
+
app.config.relative_url_root = Rails.application.config.relative_url_root
|
10
|
+
GithubOverlays.overlay
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'github_api'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
module GithubOverlays
|
6
|
+
class Git
|
7
|
+
include GithubOverlays::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
|
+
GithubOverlays.configuration.repositories.each do |repo_config|
|
20
|
+
# Validate repository config
|
21
|
+
raise 'Respository config missing user' if (!repo_config[:user] || repo_config[:user].nil?)
|
22
|
+
raise 'Respository config missing repo' if (!repo_config[:repo] || repo_config[:repo].nil?)
|
23
|
+
|
24
|
+
branch = repo_config[:branch] || 'master'
|
25
|
+
|
26
|
+
register_web_hook(repo_config[:user], repo_config[:repo])
|
27
|
+
|
28
|
+
overlay_repo(repo_config[:user], repo_config[:repo], branch)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Register our listener on the repo
|
33
|
+
#
|
34
|
+
def self.register_web_hook user, repo
|
35
|
+
# Make sure our routes are loaded
|
36
|
+
Rails.application.reload_routes!
|
37
|
+
|
38
|
+
# Build hook url
|
39
|
+
host = GithubOverlays.configuration.hostname || Socket.gethostname
|
40
|
+
port = GithubOverlays.configuration.host_port || Rails::Server.new.options[:Port]
|
41
|
+
uri = GithubOverlays::Engine.routes.url_for({:controller=>"github_overlays/webhooks", :action=>"update", :host => host, :port => port})
|
42
|
+
|
43
|
+
# Retrieve current web hooks
|
44
|
+
current_hooks = github_repo.hooks.list(user, repo).response.body
|
45
|
+
if current_hooks.find {|hook| hook.config.url == uri}.nil?
|
46
|
+
#register hook
|
47
|
+
github_repo.hooks.create(user, repo, name: 'web', active: true, config: {:url => uri, :content_type => 'json'})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.overlay_repo user, repo, branch
|
52
|
+
# Get our root entries
|
53
|
+
#
|
54
|
+
root_entries = github_repo.contents.get(user, repo, '/', ref: branch).response.body
|
55
|
+
|
56
|
+
# We aren't pulling anything out of root. Cycle through directories and overlay
|
57
|
+
#
|
58
|
+
root_entries.each do |entry|
|
59
|
+
if entry.type == 'dir'
|
60
|
+
overlay_directory(entry.path, user, repo, branch)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.overlay_directory path, user, repo, branch
|
66
|
+
FileUtils.mkdir_p "#{Rails.application.root}/#{path}"
|
67
|
+
directory_entries = github_repo.contents.get(user, repo, path, ref: branch).response.body
|
68
|
+
|
69
|
+
directory_entries.each do |entry|
|
70
|
+
if entry.type == 'dir'
|
71
|
+
overlay_directory(entry.path, user, repo, branch)
|
72
|
+
elsif entry.type == 'file'
|
73
|
+
clone_file(entry.path, user, repo, branch)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.clone_file path, user, repo, branch
|
79
|
+
file = github_repo.contents.get(user, repo, path, ref: branch).response.body.content
|
80
|
+
File.open("#{Rails.application.root}/#{path}", "wb") { |f| f.write(Base64.decode64(file)) }
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def self.github_repo
|
86
|
+
@@github ||= Github::Repos.new
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.config
|
90
|
+
@@overlay_config ||= Rails.application.config.github_overlays
|
91
|
+
end
|
92
|
+
|
93
|
+
# Configure the github api
|
94
|
+
def self.configure
|
95
|
+
overlay_config = GithubOverlays.configuration
|
96
|
+
|
97
|
+
# Validate required config
|
98
|
+
raise 'Configuration github_overlays.basic_auth not set' if (!overlay_config.auth || overlay_config.auth.nil?)
|
99
|
+
|
100
|
+
Github.configure do |github_config|
|
101
|
+
github_config.endpoint = overlay_config.endpoint if overlay_config.endpoint
|
102
|
+
github_config.site = overlay_config.site if overlay_config.site
|
103
|
+
github_config.basic_auth = overlay_config.auth
|
104
|
+
github_config.adapter = :net_http
|
105
|
+
github_config.ssl = {:verify => false}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_overlays
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Saarinen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec-rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: github_api
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Overlay one or more github repositories on a running Rails application
|
63
|
+
email:
|
64
|
+
- saarinen@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- app/assets/stylesheets/github_overlays/application.css
|
70
|
+
- app/controllers/github_overlays/application_controller.rb
|
71
|
+
- app/controllers/github_overlays/webhooks_controller.rb
|
72
|
+
- app/helpers/github_overlays/application_helper.rb
|
73
|
+
- app/views/layouts/github_overlays/application.html.erb
|
74
|
+
- config/routes.rb
|
75
|
+
- lib/github_overlays/configuration.rb
|
76
|
+
- lib/github_overlays/engine.rb
|
77
|
+
- lib/github_overlays/git.rb
|
78
|
+
- lib/github_overlays/version.rb
|
79
|
+
- lib/github_overlays.rb
|
80
|
+
- lib/tasks/github_overlays_tasks.rake
|
81
|
+
- MIT-LICENSE
|
82
|
+
- Rakefile
|
83
|
+
- README.rdoc
|
84
|
+
homepage: http://stevesaarinen.com
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
hash: 3569818938300052084
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: 3569818938300052084
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.25
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: Overlay Github repository on existing Rails application
|
114
|
+
test_files: []
|