Method: Overlay::Github#process_hook

Defined in:
lib/overlay/github.rb

#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