gog 0.0.2pre → 0.0.3pre

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.
data/README.md CHANGED
@@ -6,6 +6,10 @@ Gog aims to help developers to insert changelog data inside git commits.
6
6
  Gog allows to create changelogs based on commit data and tagged commits.
7
7
 
8
8
  ## This is still alpha software !
9
+ - You can help !
10
+ - Better tag managemnt
11
+ - Adding a config file to the engine
12
+ - just ask by sending a email via github
9
13
 
10
14
  # Syntax
11
15
 
@@ -9,8 +9,8 @@ class Gog
9
9
  @commit = commit
10
10
  end
11
11
 
12
- def closest_tag
13
- @closest_tag ||= find_closest_tag
12
+ def closest_parent_tag_name
13
+ @closest_parent_tag_name ||= find_closest_parent_tag_name
14
14
  end
15
15
 
16
16
  def to_s
@@ -19,7 +19,7 @@ class Gog
19
19
 
20
20
  private
21
21
 
22
- def find_closest_tag
22
+ def find_closest_parent_tag_name
23
23
  available_tags = Gog::Log.repo_tags
24
24
  return if available_tags.empty?
25
25
 
@@ -28,13 +28,16 @@ class Gog
28
28
  available_tags_by_sha[tag.commit.sha] = tag
29
29
  end
30
30
 
31
- Change.find_tag_in_self_or_parents(self, available_tags_by_sha)
31
+ Change.find_tag_name_in_self_or_parents(self.commit.parents, available_tags_by_sha)
32
32
  end
33
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)
34
+ def self.find_tag_name_in_self_or_parents(commits, tags)
35
+ return '0.0.0' if commits.empty?
36
+ commit = commits.first
37
+ tag = tags[commit.sha]
38
+ tag ? tag.name : find_tag_name_in_self_or_parents(commit.parents, tags)
37
39
  end
38
-
40
+
41
+
39
42
  end
40
43
  end
@@ -9,9 +9,9 @@ class Gog
9
9
  class << self
10
10
 
11
11
 
12
- def init(repo = Grit::Repo.new("."))
12
+ def init(repo = Grit::Repo.new('.'))
13
13
  @@repo = repo
14
- @@changes = @@repo.commits.map do |commit|
14
+ @@changes = @@repo.commits('master', 30).map do |commit|
15
15
  Gog::Commit.extract_changes commit
16
16
  end
17
17
  @@changes.select! { |change| !change.empty? }
@@ -24,11 +24,21 @@ class Gog
24
24
  end
25
25
 
26
26
  def changes_by_tag
27
- tags = Hash.new()
27
+ reversed_tags = Hash.new {|h,k| h[k] = [] }
28
+ tags = Hash.new
29
+ # Grouping changes by parent tags (impossible in the other way with Grit)
28
30
  @@changes.each do |change|
29
- tag_name = change.closest_tag.name
30
- tags[tag_name] = [] unless tags[tag_name]
31
- tags[tag_name] << change
31
+ tag_name = change.closest_parent_tag_name
32
+ reversed_tags[tag_name] << change
33
+ end
34
+
35
+ # Reversing tag array
36
+ tags_array = reversed_tags.to_a
37
+ tags_array.each_with_index do |tag_and_changes, index|
38
+ tag = tag_and_changes[0]
39
+ tag_changes = tag_and_changes[1]
40
+ new_tag = index > 0 ? tags_array[index - 1][0] : 'Unreleased'
41
+ tags[new_tag] = changes_sorted_by_header(tag_changes)
32
42
  end
33
43
  tags
34
44
  end
@@ -37,8 +47,16 @@ class Gog
37
47
  if @@changes.empty?
38
48
  'No changes found. Read https://github.com/goglog/gog for instructions.'
39
49
  else
40
- @@changes.join("\n")
50
+ @@changes.join "\n"
51
+ end
52
+ end
53
+
54
+ def changes_sorted_by_header(changes)
55
+ sorted_changes = Hash.new {|h,k| h[k] = [] }
56
+ changes.each do |change|
57
+ sorted_changes[change.header] << change
41
58
  end
59
+ sorted_changes
42
60
  end
43
61
 
44
62
  def repo_tags
@@ -1,3 +1,3 @@
1
1
  class Gog
2
- VERSION = "0.0.2pre"
2
+ VERSION = "0.0.3pre"
3
3
  end
@@ -37,11 +37,11 @@ describe Gog::Log do
37
37
  it 'finds closest tag for first change' do
38
38
  Gog::Log.init repo
39
39
  change = Gog::Log.changes.first
40
- change.closest_tag.name.should eq('0.0.2')
40
+ change.closest_parent_tag_name.should eq('0.0.3')
41
41
  end
42
42
 
43
43
  it "show changes by tag" do
44
- changes = %Q%{\"0.0.2\"=>[Enhancement: Readme in md format], \"0.0.1\"=>[Explaining: this repo]}%
44
+ changes = %Q%{\"Unreleased\"=>{\"Feature\"=>[Feature: Unreleased change]}, \"0.0.3\"=>{\"Feature\"=>[Feature: Le changement c'est maintenant !., Feature: Needed change.]}, \"0.0.2\"=>{\"Enhancement\"=>[Enhancement: Readme in md format]}, \"0.0.1\"=>{\"Explaining\"=>[Explaining: this repo]}}%
45
45
  Gog::Log.init repo
46
46
  Gog::Log.changes_by_tag.inspect.should eq(changes)
47
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2pre
4
+ version: 0.0.3pre
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-05 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grit