garaio-changelog 0.0.1.alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create ruby-1.9.3@garaio-changelog
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in garaio-changelog.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ # Garaio Changelog #
2
+
3
+ ## Usage ##
4
+
5
+ $ garaio-changelog v1.0.0..v1.1.0
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ FileList['tasks/**/*.rake'].each { |task| import task }
4
+
5
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'garaio-changelog'
5
+
6
+ options = ChangelogOptions.from_arguments(ARGV)
7
+
8
+ log = Changelog.new(".", options.log_range)
9
+ log.write_to(STDOUT, :format => options.format)
10
+
11
+ rescue LoadError
12
+ puts "ERROR"
13
+ $stderr.puts <<-EOS
14
+ EOS
15
+ exit(1)
16
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "garaio-changelog/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "garaio-changelog"
7
+ s.version = Changelog::VERSION
8
+ s.authors = ['Yves Senn', 'Jonas Baumann', 'Samuel Tonini']
9
+ s.email = ['yves.senn@garaio.com', 'j.baumann@jone.ch', 'samuel.tonini@garaio.com']
10
+ s.homepage = ""
11
+ s.summary = %q{Git Changelog}
12
+ s.description = %q{Convert the git history into a nice Changelog}
13
+
14
+ s.rubyforge_project = "garaio-changelog"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "virtus"
24
+ end
@@ -0,0 +1,3 @@
1
+ require "virtus"
2
+ require "garaio-changelog/changelog"
3
+ require "garaio-changelog/version"
@@ -0,0 +1,24 @@
1
+ require 'garaio-changelog/repository'
2
+ require 'garaio-changelog/pipeline'
3
+ require 'garaio-changelog/formatters/plain'
4
+ require 'garaio-changelog/formatters/console'
5
+ require 'garaio-changelog/changelog_options'
6
+
7
+ class Changelog
8
+
9
+ def initialize(path_to_repository, commit_range)
10
+ @repository = Repository.new(path_to_repository)
11
+ @commit_range = commit_range
12
+ end
13
+
14
+ def write_to(output, options = {})
15
+ repository_commits = @repository.commits(@commit_range)
16
+ @pipeline = Pipeline.default
17
+ processed_commits = @pipeline.call(repository_commits)
18
+
19
+ format = options[:format] || :plain
20
+ formatter = Formatters.const_get(format.to_s.capitalize).new
21
+ formatter.write_to(output, processed_commits)
22
+ end
23
+
24
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'optparse'
3
+ require 'ostruct'
4
+
5
+ class ChangelogOptions
6
+
7
+ def self.from_arguments(arguments)
8
+ options = OpenStruct.new
9
+
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = "Usage: garaio-changelog [COMMIT|RANGE] [options]"
12
+
13
+ opts.separator ""
14
+ opts.separator "Specific options:"
15
+
16
+ opts.on("-f", "--format [plain|console]", "Ausgabe Format.") do |f|
17
+ options.format = f
18
+ end
19
+
20
+ opts.on_tail("-h", "--help", "Zeige diese Ausgabge.") do
21
+ puts opts
22
+ exit
23
+ end
24
+ end
25
+
26
+ opts.order(arguments) {|argument| options.log_range = argument; break}
27
+ opts.parse!(arguments)
28
+
29
+ options
30
+ end
31
+
32
+ end
@@ -0,0 +1,11 @@
1
+ class Commit
2
+ include Virtus::ValueObject
3
+
4
+ attribute :commit_hash, String
5
+ attribute :message, String
6
+ attribute :author, String
7
+ attribute :author_date, DateTime
8
+ attribute :committer, String
9
+ attribute :committer_date, DateTime
10
+
11
+ end
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ module CommitParser
3
+
4
+ def self.format
5
+ mapping.keys.join(seperator)
6
+ end
7
+
8
+ def self.parse(line)
9
+ data = line.split(seperator)
10
+ attributes = Hash[mapping.values.zip(data)]
11
+
12
+ Commit.new(attributes)
13
+ end
14
+
15
+ def self.mapping
16
+ { '%H' => 'commit_hash',
17
+ '%s' => 'message',
18
+ '%an' => 'author',
19
+ '%ai' => 'author_date',
20
+ '%cn' => 'committer',
21
+ '%ci' => 'committer_date'}
22
+ end
23
+ class << self; private :mapping; end
24
+
25
+ def self.seperator
26
+ '☠'
27
+ end
28
+ class << self; private :mapping; end
29
+
30
+ end
@@ -0,0 +1,22 @@
1
+ module Formatters
2
+ class Console
3
+
4
+ def write_to(output, commits)
5
+ commits.each do |commit|
6
+ output << "%s-%s %s %s[%s]%s\n" %
7
+ [colors[:yellow], colors[:end], commit.message,
8
+ colors[:red], commit.author, colors[:end]]
9
+ end
10
+ end
11
+
12
+ def colors
13
+ {
14
+ :red => "\e[31m",
15
+ :yellow => "\e[33m",
16
+ :end => "\e[0m"
17
+ }
18
+ end
19
+ private :colors
20
+
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Formatters
2
+ class Plain
3
+
4
+ def write_to(output, commits)
5
+ commits.each do |commit|
6
+ output << "- %s [%s]\n" % [commit.message, commit.author]
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ class Pipeline
2
+
3
+ def initialize(sections)
4
+ @sections = sections
5
+ end
6
+
7
+ def call(inputs)
8
+ inputs.map do |input|
9
+ @sections.inject(input) { |i, section| section.call(i)}
10
+ end
11
+ end
12
+
13
+ def self.default
14
+ Pipeline.new([])
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'garaio-changelog/commit'
3
+ require "garaio-changelog/commit_parser"
4
+
5
+ class Repository
6
+
7
+ def initialize(path_to_repository, commit_parser = CommitParser)
8
+ @path_to_repository = path_to_repository
9
+ @commit_parser = commit_parser
10
+ end
11
+
12
+ def commits(commit_range)
13
+ output = `cd #{@path_to_repository} && git log --pretty=#{@commit_parser.format} #{commit_range}`.strip
14
+
15
+ output.split("\n").map do |line|
16
+ @commit_parser.parse(line)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ class Changelog
2
+ VERSION = "0.0.1.alpha.1"
3
+ end
@@ -0,0 +1 @@
1
+ example_repo
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'integration/spec_helper'
3
+
4
+ describe "Garaio-Changelog Generator" do
5
+
6
+ let(:path_to_repository) { File.join(File.dirname(__FILE__), 'example_repo') }
7
+
8
+ it 'Akzeptiert die Argumente von Git-Log' do
9
+ output = StringIO.new
10
+ log = Changelog.new(path_to_repository, 'HEAD')
11
+
12
+ log.write_to(output, :format => :plain)
13
+
14
+ output.rewind
15
+ output.readlines.should == ["- README hinzugefügt [Yves Senn]\n",
16
+ "- Administrator-Benutzer hinzugefügt [Yves Senn]\n",
17
+ "- Usability der Benutzermaske optimiert [Yves Senn]\n"]
18
+ end
19
+
20
+ end
@@ -0,0 +1,2 @@
1
+ require 'garaio-changelog'
2
+ require 'rspec'
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'unit/spec_helper'
3
+ require 'garaio-changelog/changelog_options'
4
+
5
+ describe ChangelogOptions do
6
+
7
+ it 'Speichert das ausgewählte Format' do
8
+ argumente = ["-f", "console"]
9
+
10
+ options = ChangelogOptions.from_arguments(argumente)
11
+
12
+ options.format.should == 'console'
13
+ options.log_range.should be_nil
14
+ end
15
+
16
+ it 'Speichert die Commit Range' do
17
+ argumente = ["v1.0.0..v1.1.0", "-f", "console"]
18
+
19
+ options = ChangelogOptions.from_arguments(argumente)
20
+
21
+ options.format.should == 'console'
22
+ options.log_range.should == 'v1.0.0..v1.1.0'
23
+ end
24
+
25
+ end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'unit/spec_helper'
3
+ require "garaio-changelog/changelog"
4
+
5
+ describe Changelog do
6
+
7
+ let(:ziel_repository) { 'pfad/zu/repo' }
8
+ let(:commit_range) { 'release..master' }
9
+ let(:output) { mock }
10
+ let(:processed_commits) { stub }
11
+
12
+ before do
13
+ commits = stub
14
+
15
+ repository = mock
16
+ pipeline = mock
17
+
18
+ Repository.should_receive(:new).with(ziel_repository).and_return(repository)
19
+ repository.should_receive(:commits).with(commit_range).and_return(commits)
20
+ Pipeline.should_receive(:default).and_return(pipeline)
21
+ pipeline.should_receive(:call).with(commits).and_return(processed_commits)
22
+ end
23
+
24
+ subject { Changelog.new(ziel_repository, commit_range) }
25
+
26
+ it "Der PlainFormatter wird per Default verwendet" do
27
+ formatter = mock
28
+ Formatters::Plain.should_receive(:new).and_return(formatter)
29
+ formatter.should_receive(:write_to).with(output, processed_commits)
30
+
31
+ subject.write_to(output)
32
+ end
33
+
34
+ it 'Der Formatter kann angegeben werden' do
35
+ formatter = mock
36
+ Formatters::Console.should_receive(:new).and_return(formatter)
37
+ formatter.should_receive(:write_to).with(output, processed_commits)
38
+
39
+ subject.write_to(output, :format => :console)
40
+ end
41
+
42
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'unit/spec_helper'
3
+ require 'garaio-changelog/commit_parser'
4
+ require 'garaio-changelog/commit'
5
+
6
+ describe CommitParser do
7
+
8
+ it 'Kennt das Log-Format für den git-log Befehl' do
9
+ described_class.format.should == '%H☠%s☠%an☠%ai☠%cn☠%ci'
10
+ end
11
+
12
+ it 'erstellt Commits aus einer Zeile' do
13
+ line = '6a4d545c736c5cb81a53bc9b8ea636cae39b02fe☠README hinzugefügt☠Yves Senn☠2012-03-13 14:15:37 +0100☠Hans Peter☠2013-03-13 14:15:37 +0200'
14
+ described_class.parse(line).should == Commit.new(:commit_hash => '6a4d545c736c5cb81a53bc9b8ea636cae39b02fe',
15
+ :message => 'README hinzugefügt',
16
+ :author => 'Yves Senn',
17
+ :author_date => DateTime.parse('2012-03-13 14:15:37 +0100'),
18
+ :committer => 'Hans Peter',
19
+ :committer_date => DateTime.parse('2013-03-13 14:15:37 +0200'))
20
+ end
21
+
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'unit/spec_helper'
2
+ require 'garaio-changelog/commit'
3
+ require 'garaio-changelog/formatters/console'
4
+
5
+ describe Formatters::Console do
6
+
7
+ it "Schreibt die Commit Nachrichten auf den Output mit Consolen ANSI Formatierung" do
8
+ output = stub
9
+
10
+ output.should_receive(:<<).with("\e[33m-\e[0m README editiert \e[31m[Yves Senn]\e[0m\n")
11
+ output.should_receive(:<<).with("\e[33m-\e[0m Benuztermaske angepasst \e[31m[Hans Peter]\e[0m\n")
12
+
13
+ subject.write_to(output, [Commit.new(:author => 'Yves Senn',
14
+ :message => 'README editiert'),
15
+ Commit.new(:author => 'Hans Peter',
16
+ :message => 'Benuztermaske angepasst')])
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'unit/spec_helper'
2
+ require 'garaio-changelog/commit'
3
+ require 'garaio-changelog/formatters/plain'
4
+
5
+ describe Formatters::Plain do
6
+
7
+ it "Schreibt die Commit Nachrichten auf den Output" do
8
+ output = stub
9
+
10
+ output.should_receive(:<<).with("- README editiert [Yves Senn]\n")
11
+ output.should_receive(:<<).with("- Benuztermaske angepasst [Hans Peter]\n")
12
+
13
+ subject.write_to(output, [Commit.new(:author => 'Yves Senn',
14
+ :message => 'README editiert'),
15
+ Commit.new(:author => 'Hans Peter',
16
+ :message => 'Benuztermaske angepasst')])
17
+
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "garaio-changelog/pipeline"
3
+
4
+ describe Pipeline do
5
+
6
+ let(:erster_abschnitt) { lambda {|i| "Schritt1: #{i}"} }
7
+ let(:zweiter_abschnitt) { lambda {|i| "Schritt2: #{i}"} }
8
+
9
+ subject { described_class.new([erster_abschnitt,
10
+ zweiter_abschnitt]) }
11
+
12
+ it "Jeder Abschnitt der Pipeline erhält als Input den Output des vorgängigen Abschnitts" do
13
+ subject.call(['first', 'second']).should == [ 'Schritt2: Schritt1: first',
14
+ 'Schritt2: Schritt1: second']
15
+ end
16
+
17
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "unit/spec_helper"
3
+ require "garaio-changelog/repository"
4
+ require "garaio-changelog/commit"
5
+
6
+ describe Repository do
7
+
8
+ it "liefert die commits der range" do
9
+ ziel_repository = 'pfad/zu/repo'
10
+ commit_range = 'release..master'
11
+ commit_parser = mock(:format => "'%H☠%an'")
12
+ repo = Repository.new(ziel_repository, commit_parser)
13
+ repo.should_receive(:'`').with("cd pfad/zu/repo && git log --pretty='%H☠%an' release..master").and_return(<<-LOG
14
+ 6a4d545c736c5cb81a53bc9b8ea636cae39b02fe☠Yves Senn
15
+ 2dd1c8412ae4710d20fc5313ccf9e037ec6ca534☠Yves Senn
16
+ ad628eb8365e5339c9c19f557f08192b43d7ca29☠Yves Senn
17
+ LOG
18
+ )
19
+ commit_parser.should_receive(:parse).with('6a4d545c736c5cb81a53bc9b8ea636cae39b02fe☠Yves Senn').and_return('commit1')
20
+ commit_parser.should_receive(:parse).with('2dd1c8412ae4710d20fc5313ccf9e037ec6ca534☠Yves Senn').and_return('commit2')
21
+ commit_parser.should_receive(:parse).with('ad628eb8365e5339c9c19f557f08192b43d7ca29☠Yves Senn').and_return('commit3')
22
+
23
+ repo.commits(commit_range).should == ['commit1', 'commit2', 'commit3']
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ require "virtus"
@@ -0,0 +1,15 @@
1
+ require 'rake/testtask'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ namespace :spec do
6
+ RSpec::Core::RakeTask.new(:unit) do |t|
7
+ t.pattern = "spec/unit/**/*_spec.rb"
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:integration) do |t|
11
+ t.pattern = "spec/integration/**/*_spec.rb"
12
+ end
13
+ end
14
+
15
+ task :spec => ['spec:unit', 'spec:integration']
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: garaio-changelog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha.1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Yves Senn
9
+ - Jonas Baumann
10
+ - Samuel Tonini
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-03-15 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &2168847600 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *2168847600
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: &2168847000 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *2168847000
38
+ description: Convert the git history into a nice Changelog
39
+ email:
40
+ - yves.senn@garaio.com
41
+ - j.baumann@jone.ch
42
+ - samuel.tonini@garaio.com
43
+ executables:
44
+ - garaio-changelog
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rvmrc
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/garaio-changelog
54
+ - garaio-changelog.gemspec
55
+ - lib/garaio-changelog.rb
56
+ - lib/garaio-changelog/changelog.rb
57
+ - lib/garaio-changelog/changelog_options.rb
58
+ - lib/garaio-changelog/commit.rb
59
+ - lib/garaio-changelog/commit_parser.rb
60
+ - lib/garaio-changelog/formatters/console.rb
61
+ - lib/garaio-changelog/formatters/plain.rb
62
+ - lib/garaio-changelog/pipeline.rb
63
+ - lib/garaio-changelog/repository.rb
64
+ - lib/garaio-changelog/version.rb
65
+ - spec/integration/.gitignore
66
+ - spec/integration/changelog_spec.rb
67
+ - spec/integration/spec_helper.rb
68
+ - spec/unit/changelog_options_spec.rb
69
+ - spec/unit/changelog_spec.rb
70
+ - spec/unit/commit_parser_spec.rb
71
+ - spec/unit/formatters/console_spec.rb
72
+ - spec/unit/formatters/plain_spec.rb
73
+ - spec/unit/pipeline_spec.rb
74
+ - spec/unit/repository_spec.rb
75
+ - spec/unit/spec_helper.rb
76
+ - tasks/test.rake
77
+ homepage: ''
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>'
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.1
95
+ requirements: []
96
+ rubyforge_project: garaio-changelog
97
+ rubygems_version: 1.8.10
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Git Changelog
101
+ test_files:
102
+ - spec/integration/.gitignore
103
+ - spec/integration/changelog_spec.rb
104
+ - spec/integration/spec_helper.rb
105
+ - spec/unit/changelog_options_spec.rb
106
+ - spec/unit/changelog_spec.rb
107
+ - spec/unit/commit_parser_spec.rb
108
+ - spec/unit/formatters/console_spec.rb
109
+ - spec/unit/formatters/plain_spec.rb
110
+ - spec/unit/pipeline_spec.rb
111
+ - spec/unit/repository_spec.rb
112
+ - spec/unit/spec_helper.rb