def git_commits(input, branch)
      data = input.split("\n").map do |l|
        l.split
      end.find do |l|
        l[2] =~ /\Arefs\/heads\/#{branch}\z/
      end

      return if data.nil?

      null_rev = '0' * 40
      from_rev, to_rev, _ = data
      if to_rev == null_rev # delete branch
        "Someone deleted branch #{branch}."
      else
        repo_name = File.basename(Dir.getwd)
        revs = if from_rev == null_rev  # new branch
                 to_rev
               else
                 "#{from_rev}..#{to_rev}"
               end
        `git rev-list #{revs}`.split("\n").map do |rev|
          `git log -n 1 #{rev}`
        end.reverse.map do |msg|
          lines = msg.split("\n")
          commit = lines[0].split(' ')[1][0..13]
          author = if lines[1] =~ /Author: ([^<]+)\s*<([^>]+)>/
                     name = $1.strip
                     email = $2.strip
                     name = name.empty? ? email.split("@").first : name
                     "[#{name}](mailto:#{email})"
                   else
                     lines[1]
                   end
          time = lines[2]
          msg = lines[3..-1]
          <<-MURMUR
Author: #{author}
#{msg.join("\n").strip}
commit #rev-#{commit} (#{repo_name})
#{time}
MURMUR
        end
      end
    end
def git_commits(input, branch)
      data = input.split("\n").map do |l|
        l.split
      end.find do |l|
        l[2] =~ /\Arefs\/heads\/#{branch}\z/
      end

      return if data.nil?

      null_rev = '0' * 40
      from_rev, to_rev, _ = data
      if to_rev == null_rev # delete branch
        "Someone deleted branch #{branch}."
      else
        repo_name = File.basename(Dir.getwd)
        revs = if from_rev == null_rev  # new branch
                 to_rev
               else
                 "#{from_rev}..#{to_rev}"
               end
        `git rev-list #{revs}`.split("\n").map do |rev|
          `git log -n 1 #{rev}`
        end.reverse.map do |msg|
          lines = msg.split("\n")
          commit = lines[0].split(' ')[1][0..13]
          author = if lines[1] =~ /Author: ([^<]+)\s*<([^>]+)>/
                     name = $1.strip
                     email = $2.strip
                     name = name.empty? ? email.split("@").first : name
                     "[#{name}](mailto:#{email})"
                   else
                     lines[1]
                   end
          time = lines[2]
          msg = lines[3..-1]
          <<-MURMUR
Author: #{author}
#{msg.join("\n").strip}
commit #rev-#{commit} (#{repo_name})
#{time}
MURMUR
        end
      end
    end
input: git post receive stdin string
 branch: git branch