gog 0.0.2pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.3
5
+ before_script: git clone git://github.com/goglog/gog_test_repo.git spec/gog_test_repo
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'grit'
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ gem 'guard'
10
+ gem 'rspec'
11
+ gem 'guard-rspec'
12
+ gem 'factory_girl', "~> 3.0"
13
+ end
@@ -0,0 +1,13 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^spec/factories/.+\.rb$}) { "spec/" }
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
+ watch(%r{^lib/gog/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch(%r{^lib/gog/(.+)\.rb$}) { |m| "spec/lib/gog/#{m[1]}_spec.rb" }
10
+ watch('spec/spec_helper.rb') { "spec/" }
11
+ end
12
+
13
+
@@ -0,0 +1,52 @@
1
+ [![Build Status](https://secure.travis-ci.org/goglog/gog.png?branch=master)](http://travis-ci.org/goglog/gog)
2
+
3
+ # Gog: The Git Changelog
4
+
5
+ Gog aims to help developers to insert changelog data inside git commits.
6
+ Gog allows to create changelogs based on commit data and tagged commits.
7
+
8
+ ## This is still alpha software !
9
+
10
+ # Syntax
11
+
12
+ They are different ways to create changelog entries:
13
+
14
+ - One line
15
+
16
+ ```
17
+ %Bug fix: Fixing issue #2012
18
+ ```
19
+
20
+ - One line - one word
21
+
22
+ ```
23
+ %Feature Adding a function to jobs
24
+ ```
25
+
26
+ - Long
27
+
28
+ ```
29
+ %%Feature: Adding pluck function to ActiveRecord
30
+ pluck is a function allowing users to select only one column
31
+ of a given model.
32
+ %%
33
+ ```
34
+
35
+ # Tags
36
+ Gog will rely on version tags:
37
+
38
+ ```
39
+ 1.0.0
40
+ 1.0.1
41
+ 1.1.0
42
+ 2.0.0
43
+ ```
44
+
45
+ # Changelog creation
46
+
47
+ To show standard changelog run `gog` in a git repository
48
+
49
+ ```
50
+ gog
51
+ ```
52
+
@@ -0,0 +1,11 @@
1
+ require "rake"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ task :default => [:spec]
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
10
+ # Put spec opts in a file named .rspec in root
11
+ end
data/bin/gog ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'gog'
5
+
6
+ class Gog
7
+
8
+ def self.start(args = ARGV)
9
+ if args.empty?
10
+ $stdout.puts Gog.help
11
+ else
12
+ first_arg = args[0].downcase
13
+ case first_arg
14
+ when "version"
15
+ $stdout.puts Gog.version
16
+ when "log"
17
+ $stdout.puts Gog.log
18
+ end
19
+ end
20
+ end
21
+
22
+ self.start(ARGV)
23
+
24
+ end
@@ -0,0 +1,39 @@
1
+ # General dev help
2
+ You must require the lib folder in order to directly gog binary:
3
+
4
+ ```
5
+ Ruby -Ilib bin/gog version
6
+ alias gogdev='Ruby -Ilib bin/gog'
7
+
8
+ ```
9
+
10
+ # Todo :
11
+
12
+ - Give more info with --help
13
+ - Allow one line multiple words
14
+ - Allow multiline changelogs
15
+
16
+ # Gog test repo
17
+
18
+ A real git repository is necesary for testing purpose. Git submodule is not sufficient, run :
19
+
20
+ ```
21
+ git clone git://github.com/goglog/gog_test_repo.git spec/gog_test_repo
22
+ ```
23
+
24
+ # irb
25
+ Launch irb
26
+
27
+ alter load path
28
+ `$LOAD_PATH << "lib"`
29
+
30
+ require gog
31
+ `require './lib/gog'`
32
+
33
+ # Rubygem deployment
34
+
35
+ - Update version in version.rb
36
+ - Update changelog in version.rb
37
+ - Tag Repository in git
38
+ - `gem build gog.gemspec`
39
+ - `gem push gog-1.X.0.gem`
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/gog/version', __FILE__)
3
+
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'gog'
7
+ s.version = Gog::VERSION
8
+
9
+ s.add_dependency 'grit', '~> 2.5'
10
+ s.add_development_dependency 'bundler', '~> 1.0'
11
+ s.authors = ['Thomas Darde']
12
+ s.description = %q{A git changelog utility}
13
+ s.email = 'gog@rougecardinal.fr'
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
15
+ s.extra_rdoc_files = ['README.md']
16
+ s.files = `git ls-files`.split("\n")
17
+ s.homepage = 'http://github.com/goglog/gog'
18
+ s.rdoc_options = ['--charset=UTF-8']
19
+ s.require_paths = ['lib']
20
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
21
+ s.summary = s.description
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'grit'
2
+ require 'gog/commit'
3
+ require 'gog/log'
4
+
5
+ class Gog
6
+ class << self
7
+ def version
8
+ require 'gog/version'
9
+ "Gog #{Gog::VERSION}"
10
+ end
11
+
12
+ def log
13
+ require 'gog/log'
14
+ Gog::Log.init
15
+ end
16
+
17
+ def help
18
+ "to list a full changelog run:\n gog log"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ class Gog
2
+ class Change
3
+
4
+ attr_accessor :header, :message, :commit
5
+
6
+ def initialize(header, message, commit)
7
+ @header = header
8
+ @message = message
9
+ @commit = commit
10
+ end
11
+
12
+ def closest_tag
13
+ @closest_tag ||= find_closest_tag
14
+ end
15
+
16
+ def to_s
17
+ "#{@header}: #{message}"
18
+ end
19
+
20
+ private
21
+
22
+ def find_closest_tag
23
+ available_tags = Gog::Log.repo_tags
24
+ return if available_tags.empty?
25
+
26
+ available_tags_by_sha = {}
27
+ available_tags.each do |tag|
28
+ available_tags_by_sha[tag.commit.sha] = tag
29
+ end
30
+
31
+ Change.find_tag_in_self_or_parents(self, available_tags_by_sha)
32
+ end
33
+
34
+ def self.find_tag_in_self_or_parents(change, tags)
35
+ tag = tags[change.commit.sha]
36
+ tag || find_tag_in_self_or_parents(change.parents.first, tags)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require 'gog/change'
2
+
3
+ ONE_LINE_ONE_WORD_REGEX = /^\%([^\s]+)\s(.*)$/
4
+
5
+ class Gog
6
+ module Commit
7
+
8
+ def self.extract_changes(commit)
9
+ message = commit.message
10
+ matched = message.scan(ONE_LINE_ONE_WORD_REGEX)
11
+ return [] if matched.empty?
12
+ matched.map do |match|
13
+ Gog::Change.new match[0], match[1], commit
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ require 'grit'
2
+
3
+ class Gog
4
+ module Log
5
+ include Grit
6
+
7
+ @@repo
8
+
9
+ class << self
10
+
11
+
12
+ def init(repo = Grit::Repo.new("."))
13
+ @@repo = repo
14
+ @@changes = @@repo.commits.map do |commit|
15
+ Gog::Commit.extract_changes commit
16
+ end
17
+ @@changes.select! { |change| !change.empty? }
18
+ @@changes.flatten!
19
+ self
20
+ end
21
+
22
+ def changes
23
+ @@changes
24
+ end
25
+
26
+ def changes_by_tag
27
+ tags = Hash.new()
28
+ @@changes.each do |change|
29
+ tag_name = change.closest_tag.name
30
+ tags[tag_name] = [] unless tags[tag_name]
31
+ tags[tag_name] << change
32
+ end
33
+ tags
34
+ end
35
+
36
+ def to_s
37
+ if @@changes.empty?
38
+ 'No changes found. Read https://github.com/goglog/gog for instructions.'
39
+ else
40
+ @@changes.join("\n")
41
+ end
42
+ end
43
+
44
+ def repo_tags
45
+ @@tags ||= @@repo.tags.sort {|a,b| a.name <=> b.name }
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ class Gog
2
+ VERSION = "0.0.2pre"
3
+ end
@@ -0,0 +1,37 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :commit, class: Grit::Commit do
4
+ ignore do
5
+ repo { stubbed_repo }
6
+ id "2"
7
+ parents ["3"]
8
+ tree "4"
9
+ author "Thomeas"
10
+ authored_date Time.now
11
+ committer "Thomas"
12
+ committed_date Time.now
13
+ message ["HEllog "]
14
+ end
15
+
16
+ initialize_with { new(repo, id, parents, tree, author, authored_date, committer, committed_date, message) }
17
+
18
+ factory :commit_with_one_line_change do
19
+ message ["Hello\n%Feature yes"]
20
+ end
21
+
22
+ factory :commit_with_two_one_line_changes do
23
+ message ["Hello\n%Feature yes\n%Feature also yes"]
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+
30
+ def stubbed_repo
31
+ repo = RSpec::Mocks::Mock.new('repo')
32
+ repo.stub(:tags) { [] }
33
+ repo.stub(:commits) { [] }
34
+ Gog::Log.init repo
35
+ repo
36
+ end
37
+
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :repo, class: Grit::Repo do
4
+ ignore do
5
+ path (File.dirname(__FILE__) + '/../gog_test_repo')
6
+ end
7
+
8
+ initialize_with { new(path) }
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Gog::Commit do
4
+
5
+ describe "extract_changes" do
6
+ context "one line" do
7
+ context "no change" do
8
+ let(:commit) { FactoryGirl.build(:commit) }
9
+ it "finds a change" do
10
+ changes = Gog::Commit.extract_changes(commit)
11
+ changes.should be_empty
12
+ end
13
+ end
14
+
15
+ context "one change" do
16
+ let(:commit_with_one_line_change) { FactoryGirl.build(:commit_with_one_line_change) }
17
+ it "finds a change" do
18
+ changes = Gog::Commit.extract_changes(commit_with_one_line_change)
19
+ change = changes.first
20
+ change.header.should eq('Feature')
21
+ change.message.should eq('yes')
22
+ change.commit.sha.should eq('2')
23
+ end
24
+ end
25
+
26
+ context "two changes" do
27
+ let(:commit_with_two_one_line_changes) { FactoryGirl.build(:commit_with_two_one_line_changes) }
28
+ it "finds two changes" do
29
+ changes = Gog::Commit.extract_changes(commit_with_two_one_line_changes)
30
+ changes.size.should eq(2)
31
+ change = changes.last
32
+ change.header.should eq('Feature')
33
+ change.message.should eq('also yes')
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Gog::Log do
4
+
5
+ describe "Showing log" do
6
+ context "stubbed_repos" do
7
+ context "no change" do
8
+ let(:repo) { stubbed_empty_repo }
9
+
10
+ it "shows empty changelog" do
11
+ log = Gog::Log.init repo
12
+ log.to_s.should eq("No changes found. Read https://github.com/goglog/gog for instructions.")
13
+ end
14
+ end
15
+
16
+ context "changes" do
17
+ let(:repo) { stubbed_repo }
18
+
19
+ it "shows empty changelog" do
20
+ log = Gog::Log.init repo
21
+ log.to_s.should eq("Feature: yes\nFeature: also yes")
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ context "real test repo" do
28
+ context "tags" do
29
+ let(:repo) { FactoryGirl.build(:repo) }
30
+
31
+ it "shows first tags" do
32
+ Gog::Log.init repo
33
+ Gog::Log.repo_tags.first.name.should eq('0.0.1'), "Are you sure you cloned the sub repo (see developemnt.md)?"
34
+ Gog::Log.repo_tags[1].name.should eq('0.0.2')
35
+ end
36
+
37
+ it 'finds closest tag for first change' do
38
+ Gog::Log.init repo
39
+ change = Gog::Log.changes.first
40
+ change.closest_tag.name.should eq('0.0.2')
41
+ end
42
+
43
+ it "show changes by tag" do
44
+ changes = %Q%{\"0.0.2\"=>[Enhancement: Readme in md format], \"0.0.1\"=>[Explaining: this repo]}%
45
+ Gog::Log.init repo
46
+ Gog::Log.changes_by_tag.inspect.should eq(changes)
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def stubbed_empty_repo
56
+ repo = double('repo')
57
+ repo.stub(:commits){ [FactoryGirl.build(:commit)] }
58
+ repo
59
+ end
60
+
61
+ def stubbed_repo
62
+ repo = double('repo')
63
+ repo.stub(:commits){ [FactoryGirl.build(:commit_with_two_one_line_changes)] }
64
+ repo
65
+ end
66
+
67
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Gog do
4
+
5
+ describe "version" do
6
+ it "shows version" do
7
+ Gog.version.should eq("Gog #{Gog::VERSION}")
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ $TESTING=true
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
4
+ require 'gog'
5
+
6
+ require 'factory_girl'
7
+ FactoryGirl.find_definitions
8
+
9
+ require 'rspec'
10
+
11
+ RSpec.configure do |config|
12
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2pre
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Darde
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: grit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ description: A git changelog utility
47
+ email: gog@rougecardinal.fr
48
+ executables:
49
+ - gog
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.md
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - .travis.yml
57
+ - Gemfile
58
+ - Guardfile
59
+ - README.md
60
+ - Rakefile
61
+ - bin/gog
62
+ - doc/Development.md
63
+ - gog.gemspec
64
+ - lib/gog.rb
65
+ - lib/gog/change.rb
66
+ - lib/gog/commit.rb
67
+ - lib/gog/log.rb
68
+ - lib/gog/version.rb
69
+ - spec/factories/commit.rb
70
+ - spec/factories/repo.rb
71
+ - spec/lib/gog/commit_spec.rb
72
+ - spec/lib/gog/log_spec.rb
73
+ - spec/lib/gog_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/goglog/gog
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.6
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.24
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: A git changelog utility
100
+ test_files:
101
+ - spec/factories/commit.rb
102
+ - spec/factories/repo.rb
103
+ - spec/lib/gog/commit_spec.rb
104
+ - spec/lib/gog/log_spec.rb
105
+ - spec/lib/gog_spec.rb
106
+ - spec/spec_helper.rb