Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. jfrench revised this gist Jul 15, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion push-to-integrity-post-receive
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ require 'json'
    POST_RECEIVE_URL = 'http://hostname:8910/repository-name/push'

    old_head, new_head, ref = STDIN.gets.split
    revision_text = `git rev-list --format=medium #{new_head} ^#{old_head}`
    revision_text = `git rev-list --no-merges --pretty #{new_head} ^#{old_head}`
    revisions = []
    revision_text.split( /\n/ ).each_slice( 6 ) { |s|
    sha1 = s[0][ /commit (\w+)/, 1 ]
  2. Pistos created this gist Apr 8, 2009.
    48 changes: 48 additions & 0 deletions push-to-integrity-post-receive
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #!/usr/bin/env ruby19

    require 'net/http'
    require 'uri'
    require 'json'

    # EDIT POST_RECEIVE_URL
    POST_RECEIVE_URL = 'http://hostname:8910/repository-name/push'

    old_head, new_head, ref = STDIN.gets.split
    revision_text = `git rev-list --format=medium #{new_head} ^#{old_head}`
    revisions = []
    revision_text.split( /\n/ ).each_slice( 6 ) { |s|
    sha1 = s[0][ /commit (\w+)/, 1 ]
    s[1] =~ /Author: (\w+) <(.+?)>/
    author_name, author_email = $1, $2
    timestamp = s[2][ /Date: +(.+?) -0/, 1 ]
    message = s[4..-1].join.strip

    revisions << {
    'id' => sha1,
    'author' => {
    'email' => author_email,
    'name' => author_name,
    },
    'message' => message,
    'timestamp' => timestamp,
    }

    }

    if revisions.empty?
    exit 0
    end

    payload = {
    'payload' => {
    "ref" => ref,
    "commits" => revisions,
    }.to_json
    }


    if pid = fork
    Process.detach pid
    else
    Net::HTTP.post_form( URI.parse( POST_RECEIVE_URL ), payload )
    end