Class: Overlay::Github
- Inherits:
-
Object
- Object
- Overlay::Github
- Includes:
- Singleton
- Defined in:
- lib/overlay/github.rb
Instance Attribute Summary collapse
-
#subscribed_configs ⇒ Object
Returns the value of attribute subscribed_configs.
Instance Method Summary collapse
-
#initialize ⇒ Github
constructor
A new instance of Github.
-
#process_hook(hook, repo_config) ⇒ Object
Take a hook hash and process each changelist.
-
#process_overlays ⇒ Object
Cycle through all configured repositories and overlay This function should be called only at initialization time as it causes a full overlay to be run.
Constructor Details
#initialize ⇒ Github
Returns a new instance of Github.
21 22 23 24 25 |
# File 'lib/overlay/github.rb', line 21 def initialize @subscribed_configs = [] @master_pid = $$ @current_subscribers = {} end |
Instance Attribute Details
#subscribed_configs ⇒ Object
Returns the value of attribute subscribed_configs.
19 20 21 |
# File 'lib/overlay/github.rb', line 19 def subscribed_configs @subscribed_configs end |
Instance Method Details
#process_hook(hook, repo_config) ⇒ Object
Take a hook hash and process each changelist. For every file updated, clone it back to us.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/overlay/github.rb', line 50 def process_hook hook, repo_config # Grab the commit array commits = hook['commits'] # We don't care if there aren't commits return if commits.nil? commits.each do |commit| # There will be three entries in each commit with file paths: added, removed, and modified. unless commit['added'].nil? added_files = commit['added'] added_files.each do |file| # Do we care? if my_file?(file, repo_config) Rails.logger.info "Overlay found added file in hook: #{file}" # Make sure that the directory is in place FileUtils.mkdir_p(destination_path(File.dirname(file), repo_config)) clone_file(file, repo_config) end end end unless commit['modified'].nil? modified_files = commit['modified'] modified_files.each do |file| # Do we care? if my_file?(file, repo_config) Rails.logger.info "Overlay found modified file in hook: #{file}" clone_file(file, repo_config) end end end unless commit['removed'].nil? removed_files = commit['removed'] removed_files.each do |file| # Do we care? if my_file?(file, repo_config) Rails.logger.info "Overlay found deleted file in hook: #{file}" File.delete(destination_path(file, repo_config)) end end end end # Call post hook code repo_config.post_hook end |
#process_overlays ⇒ Object
Cycle through all configured repositories and overlay This function should be called only at initialization time as it causes a full overlay to be run
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/overlay/github.rb', line 30 def Overlay.configuration.repositories.each do |repo_config| next unless repo_config.class == GithubRepo # Register this server's endpoint as a webhook or subscribe # to a redis pub/sub if repo_config.use_publisher publisher_subscribe(repo_config) else register_web_hook(repo_config) end # Now that all the set-up is done, fork a process # to overlay the repo. fork_it(:overlay_repo, repo_config) end end |