conventional-changelog 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0dba23ec731da9e6232f288559d0e9ef5985c94
4
- data.tar.gz: 589d787a3d640e259ee87e2bb349248cc3301c8a
3
+ metadata.gz: 82e232d316b2991fe1ab21738840de315b4947d2
4
+ data.tar.gz: 2c1cf594ac555f73d854a05aa42cc35f4a29e598
5
5
  SHA512:
6
- metadata.gz: 1d33fcf2c24912cfe6c5b011221ebf5e8e87c2dc22aa25d4fe1bb0dbab8dfcdfdf0992b7cabf065298dea628e435628b54a2da01eed7e8fdd44787be42007344
7
- data.tar.gz: fdc03d6823f5abb87ac7f29852670c19c73cb393bd2783b26d03ea38b5edcc75b7896a470ed1efe4595821fcc6f68f04d0e23ab9b4ec2beb45df47b7f0574229
6
+ metadata.gz: 030486a4cd67efcf2551c4ddfd9a32fa3d59b0994798ca45a402a0bb1b125cd9887df81f276bc72b08c4d731fa3ab2240b9532c67a9db916e89aa41dfca6f38c
7
+ data.tar.gz: 235950400c1240ee2c29fa5f5b5393e485b1b3fc9bb6a53e5e34c9d35cde6725babadf4675c7c8a4ef9587b952df42f30dd2a4e68231c3b4f271c710ca0d5d66
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ addons:
2
+ code_climate:
3
+ repo_token: 70c8e7caf52d56ab9ea35d2d9f30c4ab28431647b05d35edbe889eaec8803056
4
+ language: ruby
5
+ rvm:
6
+ - "2.1.5"
7
+ - "2.2.1"
8
+ script: bundle exec rake spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ <a name="1.0.0"></a>
2
+ ### 1.0.0 (2015-03-28)
3
+
4
+
5
+ #### Features
6
+
7
+ * **api**
8
+ * Generator#generate! generates a changelog programatically ([9738c30](/../../commit/9738c30))
9
+
10
+ * **bin**
11
+ * add a conventional-changelog binary ([af6be02](/../../commit/af6be02))
12
+
13
+
14
+
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/dcrec1/conventional-changelog-ruby.svg?branch=master)](https://travis-ci.org/dcrec1/conventional-changelog-ruby)
2
+ [![Code Climate](https://codeclimate.com/github/dcrec1/conventional-changelog-ruby/badges/gpa.svg)](https://codeclimate.com/github/dcrec1/conventional-changelog-ruby)
3
+ [![Test Coverage](https://codeclimate.com/github/dcrec1/conventional-changelog-ruby/badges/coverage.svg)](https://codeclimate.com/github/dcrec1/conventional-changelog-ruby)
4
+
1
5
  # Conventional::Changelog
2
6
 
3
7
  Generates a CHANGELOG.md file from Git metadata using the AngularJS commit conventions.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'conventional_changelog'
4
- ConventionalChangelog::Generator.new.generate!
4
+ require 'conventional_changelog/cli'
5
+ ConventionalChangelog::CLI.execute ARGV
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'conventional_changelog'
4
+ require 'conventional_changelog/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "conventional-changelog"
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", ">= 3.2"
24
24
  spec.add_development_dependency "fakefs"
25
+ spec.add_development_dependency "codeclimate-test-reporter"
25
26
  end
@@ -1,6 +1,9 @@
1
1
  require "conventional_changelog/generator"
2
2
  require "conventional_changelog/git"
3
+ require "conventional_changelog/version"
4
+ require "conventional_changelog/writer"
5
+ require "conventional_changelog/by_date_writer"
6
+ require "conventional_changelog/by_version_writer"
3
7
 
4
8
  module ConventionalChangelog
5
- VERSION = "1.0.0"
6
9
  end
@@ -0,0 +1,19 @@
1
+ module ConventionalChangelog
2
+ class ByDateWriter < Writer
3
+ private
4
+
5
+ def filter_key
6
+ :since_date
7
+ end
8
+
9
+ def write_new_lines(options)
10
+ commits.group_by { |commit| commit[:date] }.sort.reverse.each do |date, commits|
11
+ write_section commits, date
12
+ end
13
+ end
14
+
15
+ def version_header_title(id)
16
+ id
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module ConventionalChangelog
2
+ class ByVersionWriter < Writer
3
+ private
4
+
5
+ def filter_key
6
+ :since_version
7
+ end
8
+
9
+ def write_new_lines(options)
10
+ write_section commits, options[:version]
11
+ end
12
+
13
+ def version_header_title(id)
14
+ "#{id} (#{commits[0][:date]})"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module ConventionalChangelog
2
+ class CLI
3
+ def self.execute(params)
4
+ Generator.new.generate! parse(params)
5
+ end
6
+
7
+ private
8
+ def self.parse(params)
9
+ Hash[*params.map { |param| param.split("=") }.map { |key, value| [key.to_sym, value] }.flatten]
10
+ end
11
+ end
12
+ end
@@ -1,49 +1,13 @@
1
1
  module ConventionalChangelog
2
2
  class Generator
3
- def generate!
4
- File.open("CHANGELOG.md", "w") do |file|
5
- write_new_lines_to file
6
- file.puts previous_body
7
- end
3
+ def generate!(options = {})
4
+ writer(options).new("CHANGELOG.md").write! options
8
5
  end
9
6
 
10
7
  private
11
8
 
12
- def write_new_lines_to(f)
13
- Git.commits(since: last_date).group_by { |commit| commit[:date] }.sort.reverse.each do |date, commits|
14
- f.puts version_header(date)
15
- append_changes f, commits, "feat", "Features"
16
- append_changes f, commits, "fix", "Bug Fixes"
17
- end
18
- end
19
-
20
- def last_date
21
- previous_body == "" ? nil : previous_body.split("\n")[0].to_s.match(/"(.*)"/)[1]
22
- end
23
-
24
- def previous_body
25
- @previous_body ||= File.open("CHANGELOG.md", "a+").read
26
- end
27
-
28
- def version_header(date)
29
- <<-HEADER
30
- <a name="#{date}"></a>
31
- ### #{date}
32
-
33
-
34
- HEADER
35
- end
36
-
37
- def append_changes(f, commits, type, title)
38
- unless (type_commits = commits.select { |commit| commit[:type] == type }).empty?
39
- f.puts "#### #{title}", ""
40
- type_commits.group_by { |commit| commit[:component] }.each do |component, commits|
41
- f.puts "* **#{component}**"
42
- commits.each { |commit| f.puts " * #{commit[:change]} (#{commit[:id]})" }
43
- f.puts ""
44
- end
45
- f.puts ""
46
- end
9
+ def writer(options)
10
+ options[:version] ? ByVersionWriter : ByDateWriter
47
11
  end
48
12
  end
49
13
  end
@@ -2,15 +2,21 @@ module ConventionalChangelog
2
2
  class Git
3
3
  DELIMITER = "/////"
4
4
 
5
- def self.commits(since:)
6
- log.split("\n").map { |commit| commit.split DELIMITER }.select { |commit| since.nil? or commit[1] > since }.map do |commit|
5
+ def self.commits(options)
6
+ log(options).split("\n").map { |commit| commit.split DELIMITER }.select { |commit| options[:since_date].nil? or commit[1] > options[:since_date] }.map do |commit|
7
7
  comment = commit[2].match(/(.*)\((.*)\): (.*)/)
8
8
  { id: commit[0], date: commit[1], type: comment[1], component: comment[2], change: comment[3] }
9
9
  end
10
10
  end
11
11
 
12
- def self.log
13
- `git log --pretty=format:'%h#{DELIMITER}%ad#{DELIMITER}%s%x09' --date=short --grep='^(feat|fix)\\(' -E`
12
+ private
13
+
14
+ def self.log(options)
15
+ `git log --pretty=format:'%h#{DELIMITER}%ad#{DELIMITER}%s%x09' --date=short --grep='^(feat|fix)\\(' -E #{version_filter(options)}`
16
+ end
17
+
18
+ def self.version_filter(options)
19
+ options[:since_version] ? "#{options[:since_version]}..HEAD" : ""
14
20
  end
15
21
  end
16
22
  end
@@ -0,0 +1,3 @@
1
+ module ConventionalChangelog
2
+ VERSION = "1.1.0"
3
+ end
@@ -0,0 +1,50 @@
1
+ module ConventionalChangelog
2
+ class Writer < File
3
+ def initialize(file_name)
4
+ @previous_body = File.open(file_name, "a+").read
5
+ super file_name, "w"
6
+ end
7
+
8
+ def write!(options)
9
+ write_new_lines options
10
+ self.puts @previous_body
11
+ end
12
+
13
+ private
14
+
15
+ def version_header(id)
16
+ <<-HEADER
17
+ <a name="#{id}"></a>
18
+ ### #{version_header_title(id)}
19
+
20
+
21
+ HEADER
22
+ end
23
+
24
+ def commits
25
+ @commits ||= Git.commits filter_key => last_id
26
+ end
27
+
28
+ def append_changes(commits, type, title)
29
+ unless (type_commits = commits.select { |commit| commit[:type] == type }).empty?
30
+ puts "#### #{title}", ""
31
+ type_commits.group_by { |commit| commit[:component] }.each do |component, commits|
32
+ puts "* **#{component}**"
33
+ commits.each { |commit| puts " * #{commit[:change]} ([#{commit[:id]}](/../../commit/#{commit[:id]}))" }
34
+ puts ""
35
+ end
36
+ puts ""
37
+ end
38
+ end
39
+
40
+ def write_section(commits, id)
41
+ puts version_header(id)
42
+ append_changes commits, "feat", "Features"
43
+ append_changes commits, "fix", "Bug Fixes"
44
+ end
45
+
46
+ def last_id
47
+ @previous_body.to_s == "" ? nil : @previous_body.split("\n")[0].to_s.match(/"(.*)"/)[1]
48
+ end
49
+ end
50
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'conventional_changelog/cli'
3
+
4
+ describe ConventionalChangelog::CLI do
5
+ describe ".execute" do
6
+ it 'runs clean' do
7
+ expect { ConventionalChangelog::CLI.execute [] }.to_not raise_exception
8
+ end
9
+
10
+ context "with empty arguments" do
11
+ it 'generates a changelog' do
12
+ expect_any_instance_of(ConventionalChangelog::Generator).to receive(:generate!).with({})
13
+ ConventionalChangelog::CLI.execute []
14
+ end
15
+ end
16
+
17
+ context "with version=x.y.z" do
18
+ it 'generates a changelog with the version' do
19
+ expect_any_instance_of(ConventionalChangelog::Generator).to receive(:generate!).with version: "x.y.z"
20
+ ConventionalChangelog::CLI.execute ["version=x.y.z"]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe ConventionalChangelog::Generator do
4
4
  describe "#generate!" do
5
+ before :each do
6
+ FileUtils.rm "CHANGELOG.md", force: true
7
+ end
8
+
9
+ it 'runs clean' do
10
+ expect { subject.generate! }.to_not raise_exception
11
+ end
12
+
5
13
  context "with no commits" do
6
14
  before :each do
7
15
  allow(ConventionalChangelog::Git).to receive(:log).and_return ""
@@ -15,19 +23,22 @@ describe ConventionalChangelog::Generator do
15
23
 
16
24
  context "with multiple commits" do
17
25
  before :each do
18
- log = <<-LOG
26
+ allow(ConventionalChangelog::Git).to receive(:log).and_return log
27
+ end
28
+
29
+ context "without a version param" do
30
+ let(:log) do <<-LOG
19
31
  4303fd4/////2015-03-30/////feat(admin): increase reports ranges
20
32
  4303fd5/////2015-03-30/////fix(api): fix annoying bug
21
33
  4303fd6/////2015-03-28/////feat(api): add cool service
22
34
  4303fd7/////2015-03-28/////feat(api): add cool feature
23
35
  4303fd8/////2015-03-28/////feat(admin): add page to manage users
24
- LOG
25
- allow(ConventionalChangelog::Git).to receive(:log).and_return log
26
- end
36
+ LOG
37
+ end
27
38
 
28
- it 'parses simple lines into dates' do
29
- subject.generate!
30
- body = <<-BODY
39
+ it 'parses simple lines into dates' do
40
+ subject.generate!
41
+ body = <<-BODY
31
42
  <a name="2015-03-30"></a>
32
43
  ### 2015-03-30
33
44
 
@@ -35,13 +46,13 @@ describe ConventionalChangelog::Generator do
35
46
  #### Features
36
47
 
37
48
  * **admin**
38
- * increase reports ranges (4303fd4)
49
+ * increase reports ranges ([4303fd4](/../../commit/4303fd4))
39
50
 
40
51
 
41
52
  #### Bug Fixes
42
53
 
43
54
  * **api**
44
- * fix annoying bug (4303fd5)
55
+ * fix annoying bug ([4303fd5](/../../commit/4303fd5))
45
56
 
46
57
 
47
58
  <a name="2015-03-28"></a>
@@ -51,20 +62,20 @@ describe ConventionalChangelog::Generator do
51
62
  #### Features
52
63
 
53
64
  * **api**
54
- * add cool service (4303fd6)
55
- * add cool feature (4303fd7)
65
+ * add cool service ([4303fd6](/../../commit/4303fd6))
66
+ * add cool feature ([4303fd7](/../../commit/4303fd7))
56
67
 
57
68
  * **admin**
58
- * add page to manage users (4303fd8)
69
+ * add page to manage users ([4303fd8](/../../commit/4303fd8))
59
70
 
60
71
 
61
72
 
62
- BODY
63
- expect(File.open("CHANGELOG.md").read).to eql body
64
- end
73
+ BODY
74
+ expect(File.open("CHANGELOG.md").read).to eql body
75
+ end
65
76
 
66
- it 'preserves previous changes' do
67
- previous_body = <<-BODY
77
+ it 'preserves previous changes' do
78
+ previous_body = <<-BODY
68
79
  <a name="2015-03-28"></a>
69
80
  ### 2015-03-28
70
81
 
@@ -72,15 +83,14 @@ describe ConventionalChangelog::Generator do
72
83
  #### Features
73
84
 
74
85
  * **api**
75
- * add cool service (4303fd6)
86
+ * add cool service modified (4303fd6)
76
87
  * add cool feature (4303fd7)
77
88
 
78
89
  * **admin**
79
90
  * add page to manage users (4303fd8)
80
-
81
- BODY
82
- File.open("CHANGELOG.md", "w") { |f| f.puts previous_body }
83
- body = <<-BODY
91
+ BODY
92
+ File.open("CHANGELOG.md", "w") { |f| f.puts previous_body }
93
+ body = <<-BODY
84
94
  <a name="2015-03-30"></a>
85
95
  ### 2015-03-30
86
96
 
@@ -88,20 +98,67 @@ describe ConventionalChangelog::Generator do
88
98
  #### Features
89
99
 
90
100
  * **admin**
91
- * increase reports ranges (4303fd4)
101
+ * increase reports ranges ([4303fd4](/../../commit/4303fd4))
92
102
 
93
103
 
94
104
  #### Bug Fixes
95
105
 
96
106
  * **api**
97
- * fix annoying bug (4303fd5)
107
+ * fix annoying bug ([4303fd5](/../../commit/4303fd5))
98
108
 
99
109
 
100
110
  #{previous_body}
111
+ BODY
112
+ subject.generate!
113
+ expect(File.open("CHANGELOG.md").read + "\n").to eql body
114
+ end
115
+ end
101
116
 
102
- BODY
103
- subject.generate!
104
- expect(File.open("CHANGELOG.md").read).to eql body
117
+ context "with a version param" do
118
+ let(:log) do <<-LOG
119
+ 4303fd4/////2015-03-30/////feat(admin): increase reports ranges
120
+ 4303fd5/////2015-03-29/////fix(api): fix annoying bug
121
+ LOG
122
+ end
123
+
124
+ it 'preserves previous changes' do
125
+ previous_body = <<-BODY
126
+ <a name="0.1.0"></a>
127
+ ### 0.1.0 (2015-03-28)
128
+
129
+
130
+ #### Features
131
+
132
+ * **api**
133
+ * add cool service (4303fd6)
134
+ * add cool feature (4303fd7)
135
+
136
+ * **admin**
137
+ * add page to manage users (4303fd8)
138
+ BODY
139
+ File.open("CHANGELOG.md", "w") { |f| f.puts previous_body }
140
+ body = <<-BODY
141
+ <a name="0.2.0"></a>
142
+ ### 0.2.0 (2015-03-30)
143
+
144
+
145
+ #### Features
146
+
147
+ * **admin**
148
+ * increase reports ranges ([4303fd4](/../../commit/4303fd4))
149
+
150
+
151
+ #### Bug Fixes
152
+
153
+ * **api**
154
+ * fix annoying bug ([4303fd5](/../../commit/4303fd5))
155
+
156
+
157
+ #{previous_body}
158
+ BODY
159
+ subject.generate! version: '0.2.0'
160
+ expect(File.open("CHANGELOG.md").read + "\n").to eql body
161
+ end
105
162
  end
106
163
  end
107
164
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,10 @@
1
- require 'conventional_changelog'
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
2
3
  require 'pp'
3
4
  require 'fakefs'
4
- FakeFS.activate!
5
+ require 'conventional_changelog'
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:all) { FakeFS.activate! }
9
+ config.after(:all) { FakeFS.deactivate! }
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conventional-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Carrion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-28 00:00:00.000000000 Z
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: ''
70
84
  email:
71
85
  - dc.rec1@gmail.com
@@ -75,6 +89,8 @@ extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
91
  - ".gitignore"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
78
94
  - Gemfile
79
95
  - LICENSE.txt
80
96
  - README.md
@@ -82,8 +98,14 @@ files:
82
98
  - bin/conventional-changelog
83
99
  - conventional-changelog.gemspec
84
100
  - lib/conventional_changelog.rb
101
+ - lib/conventional_changelog/by_date_writer.rb
102
+ - lib/conventional_changelog/by_version_writer.rb
103
+ - lib/conventional_changelog/cli.rb
85
104
  - lib/conventional_changelog/generator.rb
86
105
  - lib/conventional_changelog/git.rb
106
+ - lib/conventional_changelog/version.rb
107
+ - lib/conventional_changelog/writer.rb
108
+ - spec/cli_spec.rb
87
109
  - spec/generator_spec.rb
88
110
  - spec/spec_helper.rb
89
111
  homepage: ''
@@ -111,5 +133,6 @@ signing_key:
111
133
  specification_version: 4
112
134
  summary: Ruby binary to generate a conventional changelog — Edit
113
135
  test_files:
136
+ - spec/cli_spec.rb
114
137
  - spec/generator_spec.rb
115
138
  - spec/spec_helper.rb