Created
February 13, 2012 11:15
-
-
Save gregoriokusowski/1816125 to your computer and use it in GitHub Desktop.
Simple release-notes from your git log ('per-week' approach)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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