Module: PushHandler
- Extended by:
- PushHandler
- Included in:
- PushHandler
- Defined in:
- lib/push_handler.rb,
lib/push_handler/config.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#configure {|self.config| ... } ⇒ Object
this configure method implementation is taken from github.com/andrew/split/blob/master/lib/split.rb.
- #construct_payload(old_commit, new_commit, ref_name) ⇒ Object
- #send_to_services(old_commit, new_commit, ref_name) ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/push_handler.rb', line 11 def config @config end |
Instance Method Details
#configure {|self.config| ... } ⇒ Object
this configure method implementation is taken from github.com/andrew/split/blob/master/lib/split.rb
15 16 17 18 |
# File 'lib/push_handler.rb', line 15 def configure self.config ||= Config.new yield(self.config) end |
#construct_payload(old_commit, new_commit, ref_name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
# File 'lib/push_handler.rb', line 33 def construct_payload(old_commit, new_commit, ref_name) hash_to_return = Hash.new({}) hash_to_return = { 'after' => new_commit, 'before' => old_commit, 'ref' => ref_name } hash_to_return['repository'] = { 'url' => config.repo['url'], 'name' => config.repo['name'], 'owner' => config.repo['owner'] } repo = Grit::Repo.new(config.repo['working_dir']) commits = Grit::Commit.find_all( repo, "#{old_commit}..#{new_commit}", :'no-merges' => true ).reverse unless commits.empty? hash_to_return['pusher'] = { 'name' => commits.first..name } hash_to_return['commits'] = commits.collect do |commit| Hash.new.tap do |commit_hash| commit_hash['distinct'] = true commit_hash['id'] = commit.sha commit_hash['message'] = commit. commit_hash['url'] = config.commit_url % commit.sha commit_hash['author'] = { 'name' => commit..name, 'email' => commit..email } # accomodate the odd formatting they have in their timestamp = commit..gmtime.strftime('%FT%T%z') commit_hash['timestamp'] = [0..-3] + ':' + [-2..-1] # figure out what, if any files should be added to the # removed, added, or modified arrays commit_hash['removed'] = [] commit_hash['added'] = [] commit_hash['modified'] = [] commit.diffs.each do |diff| commit_hash['removed'] << diff.a_path if diff.deleted_file commit_hash['added'] << diff.b_path if diff.new_file commit_hash['modified'] << diff.a_path if !diff.new_file && !diff.deleted_file end end end end hash_to_return end |
#send_to_services(old_commit, new_commit, ref_name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/push_handler.rb', line 20 def send_to_services(old_commit, new_commit, ref_name) payload = construct_payload(old_commit, new_commit, ref_name) config.services['data'].each_pair do |service, data| puts Net::HTTP.post_form( URI.parse(config.services['url'] + '/' + service + '/push'), { 'data' => data.to_json, 'payload' => payload.to_json } ).body end end |