blammo 0.1.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,2 @@
1
+ ---
2
+ BUNDLE_WITHOUT: ""
@@ -0,0 +1,3 @@
1
+ blammo.gemspec
2
+ changelog.yml
3
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source :rubygems
2
+
3
+ gem 'fancypath'
4
+ gem 'git'
5
+ gem 'tilt'
6
+ gem 'thor'
7
+
8
+ group :development do
9
+ gem 'hirb'
10
+ gem 'jeweler'
11
+ gem 'rake'
12
+ end
13
+
14
+ group :test do
15
+ gem 'rr'
16
+ gem 'rspec'
17
+ end
@@ -0,0 +1,5 @@
1
+ # Blammo
2
+
3
+ *CHANGELOG from Blammo!*
4
+
5
+ Blammo is a tool which automatically generates a changelog by inspecting your git log.
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'lib', 'blammo', 'alone')
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "blammo"
10
+ gem.summary = "CHANGELOG from Blammo."
11
+ gem.description = <<-EOS
12
+ Changelog generator.
13
+ EOS
14
+ gem.email = "josh.bassett@gmail.com"
15
+ gem.homepage = "http://github.com/nullobject/blammo"
16
+ gem.authors = ["Josh Bassett"]
17
+
18
+ unless defined?(Bundler::Definition)
19
+ require 'bundler'
20
+ end
21
+
22
+ bundle = Bundler::Definition.from_gemfile("Gemfile")
23
+ bundle.dependencies.each do |dep|
24
+ if dep.groups.include?(:runtime) || dep.groups.include?(:default) || dep.groups.include?(:production)
25
+ gem.add_dependency(dep.name, dep.requirement.to_s)
26
+ elsif dep.groups.include?(:development) || dep.groups.include?(:test)
27
+ gem.add_development_dependency(dep.name, dep.requirement.to_s)
28
+ end
29
+ end
30
+ end
31
+ Jeweler::GemcutterTasks.new
32
+ rescue LoadError
33
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
34
+ end
35
+
36
+ desc "Launch an IRB session with the environment loaded"
37
+ task :console do
38
+ exec("irb -I lib -r blammo/alone")
39
+ end
40
+
41
+ require 'spec/rake/spectask'
42
+ Spec::Rake::SpecTask.new(:spec) do |spec|
43
+ spec.libs << 'lib' << 'spec'
44
+ spec.spec_files = FileList['spec/**/*_spec.rb']
45
+ end
46
+
47
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
48
+ spec.libs << 'lib' << 'spec'
49
+ spec.pattern = 'spec/**/*_spec.rb'
50
+ spec.rcov = true
51
+ end
52
+
53
+ task :spec => :check_dependencies
54
+
55
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
4
+
5
+ require 'blammo'
6
+
7
+ Blammo::CLI.start
@@ -0,0 +1,2 @@
1
+ require 'blammo/cli'
2
+ require 'blammo/git'
@@ -0,0 +1,24 @@
1
+ rc = "#{ENV['HOME']}/.rubyrc"
2
+ load(rc) if File.exist?(rc)
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'Gemfile')
5
+
6
+ begin
7
+ # Require the preresolved locked set of gems.
8
+ require File.expand_path('../../.bundle/environment', __FILE__)
9
+ rescue LoadError
10
+ # Fallback on doing the resolve at runtime.
11
+ require 'rubygems'
12
+ require 'bundler'
13
+
14
+ Bundler.setup
15
+ end
16
+
17
+ envs = [:default]
18
+ envs << ENV['BLAMMO_ENV'].downcase.to_sym if ENV['BLAMMO_ENV']
19
+ Bundler.require *envs
20
+
21
+ path = File.join(File.expand_path(File.dirname(__FILE__)), '..')
22
+ $:.unshift path
23
+
24
+ require 'blammo'
@@ -0,0 +1,60 @@
1
+ require 'erb'
2
+ require 'fancypath'
3
+ require 'thor'
4
+ require 'tilt'
5
+ require 'yaml'
6
+
7
+ module Blammo
8
+ class CLI < Thor
9
+ CHANGELOG_FILE_NAME = "changelog.yml"
10
+
11
+ desc "generate [PATH]", "Generates a changelog.yml file"
12
+ def generate(repo_path = ".")
13
+ changelog_path = repo_path.to_fancypath.dir / CHANGELOG_FILE_NAME
14
+ releases = changelog_path.exists? ? YAML.load_file(changelog_path) : []
15
+
16
+ last_sha = self.class.find_last_sha(releases)
17
+ commits = Git.commits(repo_path, last_sha)
18
+
19
+ unless commits.empty?
20
+ release = Time.now.strftime("%Y%m%d%H%M%S")
21
+
22
+ releases.unshift(release => commits)
23
+ releases.to_yaml(open(changelog_path, "w"))
24
+ end
25
+
26
+ puts releases.to_yaml
27
+ end
28
+
29
+ desc "render PATH", "Renders the given changelog.yml file"
30
+ def render(path)
31
+ releases = YAML.load_file(path)
32
+
33
+ releases.each do |release_hash|
34
+ release, groups = release_hash.first
35
+ puts release
36
+
37
+ groups.each do |group_hash|
38
+ group, commits = group_hash
39
+ puts " " + group
40
+
41
+ commits.each do |commit_hash|
42
+ sha, message = commit_hash.first
43
+ puts " " + message
44
+ end
45
+ end
46
+ end
47
+
48
+ template = Tilt.new(File.expand_path("../../templates/changelog.markdown.erb", __FILE__))
49
+ puts template.render(nil, :date => Date.today)
50
+ end
51
+
52
+ def self.find_last_sha(releases)
53
+ return if releases.empty?
54
+ release = releases.first
55
+ commits = release.first.last
56
+ commit = commits.detect {|commit| commit.is_a?(Hash)}
57
+ commit ? commit.first.first : nil
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ require 'git'
2
+
3
+ module Blammo
4
+ class Git
5
+ CHUNK_SIZE = 10
6
+
7
+ # Returns commits to the repo in the given path since the given SHA.
8
+ def self.commits(path, last_sha = nil)
9
+ commits = []
10
+ git = ::Git.open(path)
11
+ log = ::Git::Log.new(git, CHUNK_SIZE)
12
+
13
+ log.between(last_sha, "head") if last_sha
14
+
15
+ each_commit(log) do |commit|
16
+ commits << {commit.sha => commit.message}
17
+ end
18
+
19
+ commits
20
+ end
21
+
22
+ private
23
+ def self.each_commit(log, &block)
24
+ chunk = 0
25
+
26
+ begin
27
+ log.skip(chunk * CHUNK_SIZE)
28
+ chunk += 1
29
+
30
+ log.each do |commit|
31
+ yield commit
32
+ end
33
+ end until log.size == 0
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blammo::CLI do
4
+ describe "#generate" do
5
+ it "should generate a changelog" do
6
+ pending
7
+ end
8
+ end
9
+
10
+ describe "#render" do
11
+ it "should generate the changelog" do
12
+ pending
13
+ end
14
+ end
15
+
16
+ describe ".find_last_sha" do
17
+ context "with no releases" do
18
+ it "should return nil" do
19
+ Blammo::CLI.find_last_sha([]).should be_nil
20
+ end
21
+ end
22
+
23
+ context "with a release" do
24
+ before do
25
+ @sha = "3b183d9d1ec270fc63ef54695db1cd2df5d597cf"
26
+ @releases = [
27
+ {"20100424175354" => [
28
+ "foo bar",
29
+ {@sha => "lorem ipsum"}
30
+ ]}
31
+ ]
32
+ end
33
+
34
+ it "should return the SHA of the last commit" do
35
+ Blammo::CLI.find_last_sha(@releases).should == @sha
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blammo::Git do
4
+ before do
5
+ @git = Git.init
6
+ @log = Git::Log.new(@git)
7
+
8
+ stub(Git).open(anything) {@git}
9
+ stub(Git::Log).new(anything, numeric) {@log}
10
+ end
11
+
12
+ describe ".commits" do
13
+ before do
14
+ stub(@log).between.with_any_args
15
+ stub(Blammo::Git).each_commit(anything)
16
+
17
+ @path = "foo/bar"
18
+ Blammo::Git.commits(@path)
19
+ end
20
+
21
+ it "should open the repo at the given path" do
22
+ Git.should have_received.open(@path)
23
+ end
24
+
25
+ it "should open the log" do
26
+ Git::Log.should have_received.new(@git, 10)
27
+ end
28
+
29
+ it "should loop through each commit in the log" do
30
+ Blammo::Git.should have_received.each_commit(@log)
31
+ end
32
+
33
+ it "should not scope the log" do
34
+ @log.should_not have_received.between.with_any_args
35
+ end
36
+
37
+ context "with a SHA" do
38
+ before do
39
+ @sha = "abcd"
40
+ Blammo::Git.commits(@path, @sha)
41
+ end
42
+
43
+ it "should scope the log" do
44
+ @log.should have_received.between(@sha, "head")
45
+ end
46
+ end
47
+ end
48
+
49
+ describe ".each_commit" do
50
+ before do
51
+ @commit = Object.new
52
+ stub(@log).each.yields(@commit)
53
+ end
54
+
55
+ it "should yield each commit in the log" do
56
+ commits = []
57
+ Blammo::Git.each_commit(@log) do |commit|
58
+ commits << commit
59
+ end
60
+ commits.should include(@commit)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ ENV['BLAMMO_ENV'] ||= 'test'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+ require 'blammo/alone'
7
+ require 'rr'
8
+ require 'spec'
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with RR::Adapters::Rspec
12
+ end
@@ -0,0 +1,3 @@
1
+ # CHANGELOG
2
+
3
+ <%= date %>
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blammo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Josh Bassett
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-25 00:00:00 +10:00
18
+ default_executable: blammo
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ segments:
26
+ - 0
27
+ version: "0"
28
+ prerelease: false
29
+ type: :runtime
30
+ name: fancypath
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ requirement: &id002 !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ segments:
38
+ - 0
39
+ version: "0"
40
+ prerelease: false
41
+ type: :runtime
42
+ name: git
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ requirement: &id003 !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ prerelease: false
53
+ type: :runtime
54
+ name: tilt
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ requirement: &id004 !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ prerelease: false
65
+ type: :runtime
66
+ name: thor
67
+ version_requirements: *id004
68
+ - !ruby/object:Gem::Dependency
69
+ requirement: &id005 !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ prerelease: false
77
+ type: :development
78
+ name: hirb
79
+ version_requirements: *id005
80
+ - !ruby/object:Gem::Dependency
81
+ requirement: &id006 !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ prerelease: false
89
+ type: :development
90
+ name: jeweler
91
+ version_requirements: *id006
92
+ - !ruby/object:Gem::Dependency
93
+ requirement: &id007 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ prerelease: false
101
+ type: :development
102
+ name: rake
103
+ version_requirements: *id007
104
+ - !ruby/object:Gem::Dependency
105
+ requirement: &id008 !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ prerelease: false
113
+ type: :development
114
+ name: rr
115
+ version_requirements: *id008
116
+ - !ruby/object:Gem::Dependency
117
+ requirement: &id009 !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ prerelease: false
125
+ type: :development
126
+ name: rspec
127
+ version_requirements: *id009
128
+ description: " Changelog generator.\n"
129
+ email: josh.bassett@gmail.com
130
+ executables:
131
+ - blammo
132
+ extensions: []
133
+
134
+ extra_rdoc_files:
135
+ - README.md
136
+ files:
137
+ - .bundle/config
138
+ - .gitignore
139
+ - Gemfile
140
+ - README.md
141
+ - Rakefile
142
+ - VERSION
143
+ - bin/blammo
144
+ - lib/blammo.rb
145
+ - lib/blammo/alone.rb
146
+ - lib/blammo/cli.rb
147
+ - lib/blammo/git.rb
148
+ - spec/blammo/cli_spec.rb
149
+ - spec/blammo/git_spec.rb
150
+ - spec/spec.opts
151
+ - spec/spec_helper.rb
152
+ - templates/changelog.markdown.erb
153
+ has_rdoc: true
154
+ homepage: http://github.com/nullobject/blammo
155
+ licenses: []
156
+
157
+ post_install_message:
158
+ rdoc_options:
159
+ - --charset=UTF-8
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ segments:
167
+ - 0
168
+ version: "0"
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.3.6
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: CHANGELOG from Blammo.
183
+ test_files:
184
+ - spec/blammo/cli_spec.rb
185
+ - spec/blammo/git_spec.rb
186
+ - spec/spec_helper.rb