From bdfd8f83cacff91c7144724d991eafdf3a39e47e Mon Sep 17 00:00:00 2001 From: Emil Loer Date: Tue, 14 Dec 2010 12:00:12 +0100 Subject: [PATCH] limit commit count to three messages --- bin/gitbot | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/gitbot b/bin/gitbot index 31755fe..081f237 100755 --- a/bin/gitbot +++ b/bin/gitbot @@ -1,5 +1,6 @@ #!/usr/bin/env ruby +require "datetime" require "cinch" require "sinatra" require "yaml" @@ -52,10 +53,19 @@ post "/github" do repo = push["repository"]["name"] branch = push["ref"].gsub(/^refs\/heads\//,"") - # TODO: sort commits by timestamp - push["commits"].each do |c| + # sort commits by timestamp + push["commits"].sort! do |a,b| + DateTime.parse(a["timestamp"]) <=> DateTime.parse(b["timestamp"]) + end + + # output first 3 commits + push["commits"][0..2].each do |c| say "\0030#{repo}:\0037 #{branch}\0033 #{c["author"]["name"]}\003 #{c["message"]}" end + if push["commits"].length-2 > 0 + say "\0030#{repo}:\0037 #{branch}\003 ... and #{push["commits"].length-2} more" + end + push.inspect end