conventional-changelog 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2071ea87d3cc1351bb5af23371ce7ccf983095d0
4
- data.tar.gz: 6c997b3a58da55c0ef8772a7432a7e476eb33a2a
3
+ metadata.gz: 470a4542202d03873d709b99b17756870ea1212b
4
+ data.tar.gz: f973c13c72acf9924f91744cc14bf45b587d2570
5
5
  SHA512:
6
- metadata.gz: 8fc529d5b97c661e9bd46c87d656fe37924773990ae1237d0609537d00de1e884df01416932c46f4f18ab5e310c4c054df9fabd8fe685af2f607e4c8a3db4815
7
- data.tar.gz: 666eed3f55e4d2f1933084913f198c0403a3727ba209909075d8a52231a2b107839b0079004321a65f34319203e67ba0560b2c4219340cdeb5cf20380cea9fce
6
+ metadata.gz: c182521b6cac8bc178533abf433e8a3865defeea93eea428c0aa4846ff1530a330b1b75e1f14e875a1bc58e0dd6aa9c12b85af0be1d02a0ecd39c680baefa2cb
7
+ data.tar.gz: bf95c198fe4ffaa162293ff636a56d688e834a4c149bbcd5f66da2b9c265b764ff649602f8cfb5210e982f1ec03d92d4e27c024bd87ed5898422e19d5c3a6e5b
@@ -22,5 +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
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.1"
26
26
  end
@@ -6,7 +6,7 @@ module ConventionalChangelog
6
6
  :since_date
7
7
  end
8
8
 
9
- def write_new_lines(options)
9
+ def build_new_lines(options)
10
10
  commits.group_by { |commit| commit[:date] }.sort.reverse_each do |date, commits|
11
11
  write_section commits, date
12
12
  end
@@ -6,7 +6,7 @@ module ConventionalChangelog
6
6
  :since_version
7
7
  end
8
8
 
9
- def write_new_lines(options)
9
+ def build_new_lines(options)
10
10
  write_section commits, options[:version]
11
11
  end
12
12
 
@@ -1,3 +1,5 @@
1
+ require 'open3'
2
+
1
3
  module ConventionalChangelog
2
4
  class Git
3
5
  DELIMITER = "/////"
@@ -11,7 +13,18 @@ module ConventionalChangelog
11
13
  end
12
14
 
13
15
  def self.log(options)
14
- `git log --pretty=format:"%h#{DELIMITER}%ad#{DELIMITER}%s%x09" --date=short --grep="^(feat|fix)(\\(.*\\))?:" -E #{version_filter(options)}`
16
+ output, status = Open3.capture2(%Q{
17
+ git log \
18
+ --pretty=format:"%h#{DELIMITER}%ad#{DELIMITER}%s%x09" --date=short \
19
+ --grep="^(feat|fix)(\\(.*\\))?:" -E \
20
+ #{version_filter(options)}
21
+ })
22
+
23
+ if status.success?
24
+ output
25
+ else
26
+ raise "Can't load Git commits, check your arguments"
27
+ end
15
28
  end
16
29
 
17
30
  def self.version_filter(options)
@@ -1,3 +1,3 @@
1
1
  module ConventionalChangelog
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -1,13 +1,34 @@
1
+ require 'stringio'
2
+
1
3
  module ConventionalChangelog
4
+
5
+ class LastReleaseNotFound < StandardError
6
+ MESSAGE = <<-EOM
7
+ Could not determine last tag or release date from existing CHANGELOG.md.
8
+ Please specify the last tag (eg. v1.2.3) or release date (eg. 2016-02-14)
9
+ manually by setting the environment variable CONVENTIONAL_CHANGELOG_LAST_RELEASE
10
+ and running the generate command again.
11
+ EOM
12
+
13
+ def initialize message = MESSAGE
14
+ super(message)
15
+ end
16
+ end
17
+
2
18
  class Writer < File
3
19
  def initialize(file_name)
4
- @previous_body = File.open(file_name, "a+").read
5
- super file_name, "w"
20
+ FileUtils.touch file_name
21
+ super file_name, 'r+'
22
+
23
+ @new_body = StringIO.new
24
+ @previous_body = read
6
25
  end
7
26
 
8
27
  def write!(options)
9
- write_new_lines options
10
- self.puts @previous_body
28
+ build_new_lines options
29
+ seek 0
30
+ write @new_body.string
31
+ write @previous_body
11
32
  end
12
33
 
13
34
  private
@@ -27,28 +48,39 @@ module ConventionalChangelog
27
48
 
28
49
  def append_changes(commits, type, title)
29
50
  unless (type_commits = commits.select { |commit| commit[:type] == type }).empty?
30
- puts "#### #{title}", ""
51
+ @new_body.puts "#### #{title}", ""
31
52
  type_commits.group_by { |commit| commit[:component] }.each do |component, component_commits|
32
- puts "* **#{component}**" if component
53
+ @new_body.puts "* **#{component}**" if component
33
54
  component_commits.each { |commit| write_commit commit, component }
34
- puts ""
55
+ @new_body.puts ""
35
56
  end
36
- puts ""
57
+ @new_body.puts ""
37
58
  end
38
59
  end
39
60
 
40
61
  def write_commit(commit, componentized)
41
- puts "#{componentized ? ' ' : ''}* #{commit[:change]} ([#{commit[:id]}](/../../commit/#{commit[:id]}))"
62
+ @new_body.puts "#{componentized ? ' ' : ''}* #{commit[:change]} ([#{commit[:id]}](/../../commit/#{commit[:id]}))"
42
63
  end
43
64
 
44
65
  def write_section(commits, id)
45
- puts version_header(id)
66
+ return if commits.empty?
67
+
68
+ @new_body.puts version_header(id)
46
69
  append_changes commits, "feat", "Features"
47
70
  append_changes commits, "fix", "Bug Fixes"
48
71
  end
49
72
 
50
73
  def last_id
51
- @previous_body.to_s == "" ? nil : @previous_body.split("\n")[0].to_s.match(/"(.*)"/)[1]
74
+ return nil if @previous_body.to_s.length == 0
75
+ matches = @previous_body.split("\n")[0].to_s.match(/"(.*)"/)
76
+
77
+ if matches
78
+ matches[1]
79
+ elsif manually_set_id = ENV['CONVENTIONAL_CHANGELOG_LAST_RELEASE']
80
+ manually_set_id
81
+ else
82
+ raise LastReleaseNotFound.new
83
+ end
52
84
  end
53
85
  end
54
86
  end
@@ -21,7 +21,7 @@ describe ConventionalChangelog::Generator do
21
21
 
22
22
  it 'creates an empty changelog when no commits' do
23
23
  subject.generate!
24
- expect(changelog).to eql "\n"
24
+ expect(changelog).to eql ""
25
25
  end
26
26
  end
27
27
 
@@ -50,7 +50,6 @@ describe ConventionalChangelog::Generator do
50
50
  * increase reports ranges ([4303fd4](/../../commit/4303fd4))
51
51
 
52
52
 
53
-
54
53
  BODY
55
54
  expect(changelog).to eql body
56
55
  end
@@ -106,7 +105,6 @@ describe ConventionalChangelog::Generator do
106
105
  * add page to manage users ([4303fd8](/../../commit/4303fd8))
107
106
 
108
107
 
109
-
110
108
  BODY
111
109
  expect(changelog).to eql body
112
110
  end
@@ -222,12 +220,47 @@ describe ConventionalChangelog::Generator do
222
220
  * fix annoying bug ([4303fd5](/../../commit/4303fd5))
223
221
 
224
222
 
225
-
226
223
  BODY
227
224
  expect(changelog).to eql body
228
225
  end
229
226
  end
230
227
 
231
228
  end
229
+
230
+ context "when the tag or date of the previous release cannot be determined from the existing CHANGELOG" do
231
+ context "when the CONVENTIONAL_CHANGELOG_LAST_RELEASE environment variable is not set" do
232
+ it "raises a helpful error" do
233
+ File.write("CHANGELOG.md", "original")
234
+ expect { subject.generate! version: "v2.0.0" }.to raise_error(ConventionalChangelog::LastReleaseNotFound, /Could not determine last tag or release date/)
235
+ end
236
+ end
237
+
238
+ context "when the CONVENTIONAL_CHANGELOG_LAST_RELEASE environment variable is set" do
239
+ before do
240
+ allow(ENV).to receive(:[]).with('CONVENTIONAL_CHANGELOG_LAST_RELEASE').and_return('v1.2.3')
241
+ allow(ConventionalChangelog::Git).to receive(:log).and_return log
242
+ end
243
+
244
+ let(:log) { "4303fd4/////2015-03-30/////feat: increase reports ranges" }
245
+
246
+ it "uses the value of CONVENTIONAL_CHANGELOG_LAST_RELEASE as the last release id" do
247
+ File.write("CHANGELOG.md", "original")
248
+ expect(ConventionalChangelog::Git).to receive(:commits).with(since_version: 'v1.2.3').and_call_original
249
+ subject.generate! version: "v2.0.0"
250
+ end
251
+ end
252
+ end
253
+
254
+ context "when an error occurs generating the commit log" do
255
+ before do
256
+ allow_any_instance_of(ConventionalChangelog::Writer).to receive(:append_changes).and_raise("an error")
257
+ end
258
+
259
+ it "maintains the original content" do
260
+ File.write("CHANGELOG.md", '<a name="v1.0.0"></a>')
261
+ expect { subject.generate! version: "v2.0.0" }.to raise_error(RuntimeError)
262
+ expect(File.read("CHANGELOG.md")).to eq '<a name="v1.0.0"></a>'
263
+ end
264
+ end
232
265
  end
233
266
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConventionalChangelog::Git do
4
+ subject { ConventionalChangelog::Git }
5
+
6
+ describe ".log" do
7
+ it "returns a log with default options" do
8
+ log = subject.log({})
9
+
10
+ expect(log).to include "feat(bin): add a conventional-changelog binary"
11
+ end
12
+
13
+ it "raises an exception if Git returns an error" do
14
+ expect do
15
+ subject.log({ since_version: 'invalid-branch' })
16
+ end.to raise_exception RuntimeError, "Can't load Git commits, check your arguments"
17
+ end
18
+ end
19
+ 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.2.2
4
+ version: 1.3.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: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: codeclimate-test-reporter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '0.1'
83
83
  description: ''
84
84
  email:
85
85
  - dc.rec1@gmail.com
@@ -107,6 +107,7 @@ files:
107
107
  - lib/conventional_changelog/writer.rb
108
108
  - spec/cli_spec.rb
109
109
  - spec/generator_spec.rb
110
+ - spec/git_spec.rb
110
111
  - spec/spec_helper.rb
111
112
  homepage: https://github.com/dcrec1/conventional-changelog-ruby
112
113
  licenses:
@@ -128,11 +129,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  version: '0'
129
130
  requirements: []
130
131
  rubyforge_project:
131
- rubygems_version: 2.4.5.1
132
+ rubygems_version: 2.6.12
132
133
  signing_key:
133
134
  specification_version: 4
134
135
  summary: Ruby binary to generate a conventional changelog — Edit
135
136
  test_files:
136
137
  - spec/cli_spec.rb
137
138
  - spec/generator_spec.rb
139
+ - spec/git_spec.rb
138
140
  - spec/spec_helper.rb
141
+ has_rdoc: