Kategorie wird aus der Message extrahiert #1

Merged
merged 2 commits into from Mar 16, 2012
Jump to file or symbol
Failed to load files and symbols.
+218 −41
Split
@@ -1,7 +1,6 @@
require 'garaio-changelog/repository'
require 'garaio-changelog/pipeline'
-require 'garaio-changelog/formatters/plain'
-require 'garaio-changelog/formatters/console'
+require 'garaio-changelog/formatter'
require 'garaio-changelog/changelog_options'
class Changelog
@@ -8,4 +8,5 @@ class Commit
attribute :committer, String
attribute :committer_date, DateTime
+ attr_accessor :kategorie
@senny

senny Mar 14, 2012

Contributor

damit bin ich nicht zufrieden. Ich denke Daten aus der Bearbeitung sollten sauber abgetrennt werden. Vorschläge?

end
@@ -0,0 +1,21 @@
+class Formatter
+
+ def write_to(output, commits)
+ commits_nach_kategorie_gruppiert = Hash.new {|hash, key| hash[key] = []}
+ commits.each do |commit|
+ commits_nach_kategorie_gruppiert[commit.kategorie] << commit
+ end
+
+ commits_nach_kategorie_gruppiert.each do |kategorie, commits|
+ write_header(output, kategorie.capitalize) if kategorie
+ commits.each do |commit|
+ indent(output, 1) if kategorie
+ write_commit(output, commit)
+ end
+ end
+ end
+
+end
+
+require 'garaio-changelog/formatters/plain'
+require 'garaio-changelog/formatters/console'
@@ -1,18 +1,25 @@
module Formatters
- class Console
+ class Console < Formatter
- def write_to(output, commits)
- commits.each do |commit|
- output << "%s-%s %s %s[%s]%s\n" %
- [colors[:yellow], colors[:end], commit.message,
- colors[:red], commit.author, colors[:end]]
- end
+ def write_header(output, header)
+ output << "%s# %s%s\n" % [colors[:green], header, colors[:end]]
+ end
+
+ def indent(output, level)
+ output << (' ' * level)
+ end
+
+ def write_commit(output, commit)
+ output << "%s-%s %s %s[%s]%s\n" % [colors[:yellow], colors[:end],
+ commit.message,
+ colors[:red], commit.author, colors[:end]]
end
def colors
{
:red => "\e[31m",
:yellow => "\e[33m",
+ :green => "\e[32m",
:end => "\e[0m"
}
end
@@ -1,10 +1,17 @@
module Formatters
- class Plain
+ class Plain < Formatter
- def write_to(output, commits)
- commits.each do |commit|
- output << "- %s [%s]\n" % [commit.message, commit.author]
- end
+ def write_header(output, header)
+ output << "# #{header}\n"
+ end
+
+ def write_commit(output, commit)
+ output << ("- %s [%s]\n" % [commit.message, commit.author])
+
+ end
+
+ def indent(output, level)
+ output << (' ' * level)
end
end
@@ -1,3 +1,5 @@
+require 'garaio-changelog/pipeline/kategorie_extractor'
+
class Pipeline
def initialize(sections)
@@ -6,12 +8,15 @@ def initialize(sections)
def call(inputs)
inputs.map do |input|
- @sections.inject(input) { |i, section| section.call(i)}
- end
+ @sections.inject(input) do |i, section|
+ next unless i
+ section.call(i)
+ end
+ end.compact
end
def self.default
- Pipeline.new([])
+ Pipeline.new([KategorieExtractor.new])
end
end
@@ -0,0 +1,17 @@
+class Pipeline
+ class KategorieExtractor
+
+ def call(commit)
+ case commit.message
+ when /^bugfix/, /^hotfix/, /^fix/
+ commit.kategorie = :bugfix
+ when /^ignore/
+ commit = nil
+ else
+ commit.kategorie = :feature
+ end
+ commit
+ end
+
+ end
+end
@@ -12,9 +12,12 @@
log.write_to(output, :format => :plain)
output.rewind
- output.readlines.should == ["- README hinzugefügt [Yves Senn]\n",
- "- Administrator-Benutzer hinzugefügt [Yves Senn]\n",
- "- Usability der Benutzermaske optimiert [Yves Senn]\n"]
+ output.readlines.should == ["# Bugfix\n",
+ " - hotfix: Nicht jeder kann als Admin einloggen [Yves Senn]\n",
+ "# Feature\n",
+ " - README hinzugefügt [Yves Senn]\n",
+ " - Administrator-Benutzer hinzugefügt [Yves Senn]\n",
+ " - Usability der Benutzermaske optimiert [Yves Senn]\n"]
end
end
@@ -0,0 +1,60 @@
+require 'unit/spec_helper'
+require 'garaio-changelog/commit'
+require 'garaio-changelog/formatter'
+
+describe Formatter do
+
+ let(:formatter_impl_class) do
+ Class.new(Formatter) do
+ def write_header(output, header)
+ output << "#{header}\n"
+ end
+
+ def write_commit(output, commit)
+ output << "COMMIT #{commit.message}\n"
+ end
+
+ def indent(output, level)
+ output << ("\t" * level)
+ end
+ end
+ end
+
+ subject { formatter_impl_class.new }
+
+ it "Schreibt die Commit Nachrichten auf den Output" do
+ output = stub
+
+ output.should_receive(:<<).with("COMMIT 1\n")
+ output.should_receive(:<<).with("COMMIT 2\n")
+
+ subject.write_to(output, [Commit.new(:message => '1'),
+ Commit.new(:message => '2')])
+
+
+ end
+
+ context 'Wenn die Commits kategorisiert sind' do
+ it "Gruppiert die Nachrichten nach Kategorie" do
+ output = stub
+
+ output.should_receive(:<<).with("Feature\n")
+ output.should_receive(:<<).with("\t")
+ output.should_receive(:<<).with("COMMIT 1\n")
+ output.should_receive(:<<).with("\t")
+ output.should_receive(:<<).with("COMMIT 3\n")
+ output.should_receive(:<<).with("Bugfix\n")
+ output.should_receive(:<<).with("\t")
+ output.should_receive(:<<).with("COMMIT 2\n")
+
+ subject.write_to(output, [
+ Commit.new(:kategorie => :feature, :message => '1'),
+ Commit.new(:kategorie => :bugfix, :message => '2'),
+ Commit.new(:kategorie => :feature, :message => '3')
+ ])
+
+
+ end
+ end
+
+end
@@ -1,20 +1,29 @@
+# -*- coding: utf-8 -*-
require 'unit/spec_helper'
require 'garaio-changelog/commit'
-require 'garaio-changelog/formatters/console'
+require 'garaio-changelog/formatter'
describe Formatters::Console do
- it "Schreibt die Commit Nachrichten auf den Output mit Consolen ANSI Formatierung" do
+ it 'Formatiert Titelzeilen Grün' do
+ output = mock
+ output.should_receive(:<<).with("\e[32m# Titelzeile\e[0m\n")
+ subject.write_header(output, 'Titelzeile')
+ end
+
+ it 'Rückt zwei Spaces ein' do
+ output = mock
+ output.should_receive(:<<).with(" ")
+ subject.indent(output, 1)
+ end
+
+ it "Gibt Commit-Nachrichten mit Autor aus + ANSI Farben" do
output = stub
output.should_receive(:<<).with("\e[33m-\e[0m README editiert \e[31m[Yves Senn]\e[0m\n")
- output.should_receive(:<<).with("\e[33m-\e[0m Benuztermaske angepasst \e[31m[Hans Peter]\e[0m\n")
-
- subject.write_to(output, [Commit.new(:author => 'Yves Senn',
- :message => 'README editiert'),
- Commit.new(:author => 'Hans Peter',
- :message => 'Benuztermaske angepasst')])
+ subject.write_commit(output, Commit.new(:author => 'Yves Senn',
+ :message => 'README editiert'))
end
end
@@ -1,21 +1,27 @@
+# -*- coding: utf-8 -*-
require 'unit/spec_helper'
require 'garaio-changelog/commit'
-require 'garaio-changelog/formatters/plain'
+require 'garaio-changelog/formatter'
describe Formatters::Plain do
- it "Schreibt die Commit Nachrichten auf den Output" do
- output = stub
-
- output.should_receive(:<<).with("- README editiert [Yves Senn]\n")
- output.should_receive(:<<).with("- Benuztermaske angepasst [Hans Peter]\n")
-
- subject.write_to(output, [Commit.new(:author => 'Yves Senn',
- :message => 'README editiert'),
- Commit.new(:author => 'Hans Peter',
- :message => 'Benuztermaske angepasst')])
+ it 'Rückt zwei Spaces pro Level ein' do
+ output = mock
+ output.should_receive(:<<).with(' ')
+ subject.indent(output, 2)
+ end
+ it 'Titelzeilen werden mit einem # dargestellt' do
+ output = mock
+ output.should_receive(:<<).with("# Titelzeile\n")
+ subject.write_header(output, 'Titelzeile')
+ end
+ it 'Commits werden mit Nachricht und Autor ausgegeben' do
+ output = mock
+ output.should_receive(:<<).with("- Neue Funktion [Samuel Tonini]\n")
+ subject.write_commit(output, Commit.new(:message => 'Neue Funktion',
+ :author => 'Samuel Tonini'))
end
end
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+require 'garaio-changelog/pipeline/kategorie_extractor'
+
+describe Pipeline::KategorieExtractor do
+
+
+ context 'Feature' do
+ it 'Alle Commits ohne Spezielle Formatierung in der Message' do
+ commit = mock(:message => 'Neue Artikel können hinzugefüt werden')
+ commit.should_receive(:kategorie=).with(:feature)
+ subject.call(commit).should == commit
+ end
+ end
+
+ context 'Bugfix' do
+ it 'beinhaltet Nachrichten mit dem Text "bugfix"' do
+ commit = mock(:message => 'bugfix: Scrollbar wird nicht dargestellt')
+ commit.should_receive(:kategorie=).with(:bugfix)
+ subject.call(commit).should == commit
+ end
+
+ it 'beinhaltet Nachrichten mit dem Text "hotfix"' do
+ commit = mock(:message => 'hotfix: Scrollbar wird nicht dargestellt')
+ commit.should_receive(:kategorie=).with(:bugfix)
+ subject.call(commit).should == commit
+ end
+
+ it 'beinhaltet Nachrichten mit dem Text "fix"' do
+ commit = mock(:message => 'fix: Scrollbar wird nicht dargestellt')
+ commit.should_receive(:kategorie=).with(:bugfix)
+ subject.call(commit).should == commit
+ end
+ end
+
+ context 'Ausgeschlossene' do
+ it 'Nachrichten mit dem Text "ignore" werden ausgeschlossen' do
+ commit = mock(:message => 'ignore: Whitespace angepasst')
+ subject.call(commit).should == nil
+ end
+ end
+
+end
@@ -10,8 +10,8 @@
zweiter_abschnitt]) }
it "Jeder Abschnitt der Pipeline erhält als Input den Output des vorgängigen Abschnitts" do
- subject.call(['first', 'second']).should == [ 'Schritt2: Schritt1: first',
- 'Schritt2: Schritt1: second']
+ subject.call(['first', 'second', nil]).should == [ 'Schritt2: Schritt1: first',
+ 'Schritt2: Schritt1: second']
end
end