Class: GithubOverlays::Git
- Inherits:
-
Object
- Object
- GithubOverlays::Git
- Defined in:
- lib/github_overlays/git.rb
Class Method Summary collapse
- .clone_file(path, user, repo, branch) ⇒ Object
- .overlay_directory(path, user, repo, branch) ⇒ Object
- .overlay_repo(user, repo, branch) ⇒ Object
-
.process_overlays ⇒ Object
Cycle through all configured repositories and overlay.
-
.register_web_hook(user, repo) ⇒ Object
Register our listener on the repo.
Class Method Details
.clone_file(path, user, repo, branch) ⇒ Object
78 79 80 81 |
# File 'lib/github_overlays/git.rb', line 78 def self.clone_file path, user, repo, branch file = github_repo.contents.get(user, repo, path, ref: branch).response.body.content File.open("#{Rails.application.root}/#{path}", "wb") { |f| f.write(Base64.decode64(file)) } end |
.overlay_directory(path, user, repo, branch) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/github_overlays/git.rb', line 65 def self. path, user, repo, branch FileUtils.mkdir_p "#{Rails.application.root}/#{path}" directory_entries = github_repo.contents.get(user, repo, path, ref: branch).response.body directory_entries.each do |entry| if entry.type == 'dir' (entry.path, user, repo, branch) elsif entry.type == 'file' clone_file(entry.path, user, repo, branch) end end end |
.overlay_repo(user, repo, branch) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/github_overlays/git.rb', line 51 def self. user, repo, branch # Get our root entries # root_entries = github_repo.contents.get(user, repo, '/', ref: branch).response.body # We aren't pulling anything out of root. Cycle through directories and overlay # root_entries.each do |entry| if entry.type == 'dir' (entry.path, user, repo, branch) end end end |
.process_overlays ⇒ Object
Cycle through all configured repositories and overlay
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/github_overlays/git.rb', line 10 def self. # If we aren't running in Rails, bail out. This may be some # other request such as rake routes loading the environment # return unless defined?(Rails::Server) # Configure github api configure GithubOverlays.configuration.repositories.each do |repo_config| # Validate repository config raise 'Respository config missing user' if (!repo_config[:user] || repo_config[:user].nil?) raise 'Respository config missing repo' if (!repo_config[:repo] || repo_config[:repo].nil?) branch = repo_config[:branch] || 'master' register_web_hook(repo_config[:user], repo_config[:repo]) (repo_config[:user], repo_config[:repo], branch) end end |
.register_web_hook(user, repo) ⇒ Object
Register our listener on the repo
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/github_overlays/git.rb', line 34 def self.register_web_hook user, repo # Make sure our routes are loaded Rails.application.reload_routes! # Build hook url host = GithubOverlays.configuration.hostname || Socket.gethostname port = GithubOverlays.configuration.host_port || Rails::Server.new.[:Port] uri = GithubOverlays::Engine.routes.url_for({:controller=>"github_overlays/webhooks", :action=>"update", :host => host, :port => port}) # Retrieve current web hooks current_hooks = github_repo.hooks.list(user, repo).response.body if current_hooks.find {|hook| hook.config.url == uri}.nil? #register hook github_repo.hooks.create(user, repo, name: 'web', active: true, config: {:url => uri, :content_type => 'json'}) end end |