jnstq (owner)

Revisions

gist: 201660 Download_button fork
public
Public Clone URL: git://gist.github.com/201660.git
Embed All Files: show embed
snippet.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class ConstructBuildRequest
  include HTTParty
 
 
  def initialize(clone_url, *args)
    super
    @clone_url = clone_url
    @oldrev, @newrev, @refname = *args
  end
 
  def commits
    # https://gist.github.com/4d81e30bbc4aac556dec
    revisions = %x{bash -c "git-rev-list --pretty=format:'%H %ai' #{@newrev} ^#{@oldrev}"}.split("\n")
    rev_list = revisions.inject([]) do |list, line|
      if line[0..5] == 'commit'
        list
      else
        list << { :id => line[0..40], :timestamp => line[41..66] }
      end
    end
  end
 
  def payload
    {
      "after" => @oldrev,
      "before" => @newrev,
      "commits" => commits,
      "ref" => @refname,
      "repository" => {
        "name" => "gitpostreceive",
        "clone_url" => @clone_url
      }
    }
  end
 
  def build
    self.class.post('http://localhost:3000/github', :query => { :payload => payload.to_json })
  end
  
  def self.build(*args)
    new(*args).build
  end
end
 
ConstructBuildRequest.build("/path/to/repos", *STDIN.read.split)