Skip to content

Instantly share code, notes, and snippets.

@gregoriokusowski
Created February 13, 2012 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregoriokusowski/1816125 to your computer and use it in GitHub Desktop.
Save gregoriokusowski/1816125 to your computer and use it in GitHub Desktop.
Simple release-notes from your git log ('per-week' approach)
# usage: (after download this file to your repo folder)
# $ cd git_repo
# $ ruby git_log.rb >> release_notes.txt
require 'time'
class Commit
def rows
@rows ||= []
end
def date
@date ||= (Time.parse(@rows.detect{ |r| r.start_with? 'Date: ' }[5..-1].strip).to_date)
end
def content
@content ||= @rows.reject do |row|
row.strip == '' or row.start_with? 'Author: ' or row.start_with? 'Date: ' or row.start_with? 'commit '
end
end
def valid?
@rows.size > 3
end
end
class Reader
def initialize
@commits = []
end
def start
%x[git log].split("\n").inject([]) do |commits, line|
if line.start_with? 'commit'
@commits << Commit.new
end
@commits.last.rows << line
end
end
def sort
@commits.sort! do |one, another|
one.date <=> another.date
end
end
def result
@commits
end
end
class Printer
def initialize(commits)
@commits = commits
@last_date = nil
@last_week = nil
end
def go
@commits.each do |commit|
if @last_week != commit.date.cweek
@last_date = commit.date
@last_week = commit.date.cweek
puts "Semana: #{@last_week}. Data: #{@last_date.strftime '%d/%m/%Y'}"
end
commit.content.each do |c|
puts " - - - #{c}"
end
end
end
end
Printer.new(Reader.new.tap(&:start).tap(&:sort).result).go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment