github_changelog_generator 1.15.0 → 1.16.3

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -54
  3. data/Rakefile +1 -1
  4. data/lib/github_changelog_generator/argv_parser.rb +225 -0
  5. data/lib/github_changelog_generator/generator/entry.rb +10 -10
  6. data/lib/github_changelog_generator/generator/generator.rb +41 -19
  7. data/lib/github_changelog_generator/generator/generator_fetcher.rb +5 -9
  8. data/lib/github_changelog_generator/generator/generator_processor.rb +23 -20
  9. data/lib/github_changelog_generator/generator/generator_tags.rb +15 -9
  10. data/lib/github_changelog_generator/generator/section.rb +27 -7
  11. data/lib/github_changelog_generator/helper.rb +1 -1
  12. data/lib/github_changelog_generator/octo_fetcher.rb +190 -126
  13. data/lib/github_changelog_generator/options.rb +4 -0
  14. data/lib/github_changelog_generator/parser.rb +70 -248
  15. data/lib/github_changelog_generator/parser_file.rb +29 -14
  16. data/lib/github_changelog_generator/reader.rb +2 -2
  17. data/lib/github_changelog_generator/ssl_certs/cacert.pem +851 -1680
  18. data/lib/github_changelog_generator/task.rb +3 -2
  19. data/lib/github_changelog_generator/version.rb +1 -1
  20. data/man/git-generate-changelog.1 +46 -34
  21. data/man/git-generate-changelog.1.html +39 -31
  22. data/man/git-generate-changelog.html +19 -19
  23. data/man/git-generate-changelog.md +39 -31
  24. data/spec/files/config_example +5 -0
  25. data/spec/spec_helper.rb +1 -1
  26. data/spec/unit/generator/entry_spec.rb +37 -31
  27. data/spec/unit/generator/generator_processor_spec.rb +99 -44
  28. data/spec/unit/generator/generator_spec.rb +47 -0
  29. data/spec/unit/generator/generator_tags_spec.rb +46 -3
  30. data/spec/unit/generator/section_spec.rb +34 -0
  31. data/spec/unit/octo_fetcher_spec.rb +45 -2
  32. data/spec/unit/parser_spec.rb +50 -0
  33. metadata +45 -9
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "github_changelog_generator/generator/generator"
4
+
5
+ RSpec.describe GitHubChangelogGenerator::Generator do
6
+ let(:header) { "# Changelog" }
7
+ let(:generator) { described_class.new({ header: header }) }
8
+ let(:content) do
9
+ <<~'BASE'
10
+ ## [1.3.10](https://github.com/xxx/yyy/tree/1.3.10) (2015-03-18)
11
+
12
+ [Full Changelog](https://github.com/xxx/yyy/compare/1.3.9...1.3.10)
13
+
14
+ **Fixed bugs:**
15
+
16
+
17
+ BASE
18
+ end
19
+ let(:footer) do
20
+ <<~CREDIT
21
+ \\* *This Changelog was automatically generated \
22
+ by [github_changelog_generator]\
23
+ (https://github.com/github-changelog-generator/github-changelog-generator)*
24
+ CREDIT
25
+ end
26
+
27
+ context "when the given base file has previously appended template messages" do
28
+ describe "#remove_old_fixed_string" do
29
+ it "removes old template headers and footers" do
30
+ log = +"#{header}\n\n#{header}\n#{header}#{content}\n\n#{footer}\n#{footer}#{footer}"
31
+
32
+ expect(generator.send(:remove_old_fixed_string, log)).to eq content
33
+ end
34
+ end
35
+ end
36
+
37
+ context "when plain contents string was given" do
38
+ describe "#insert_fixed_string" do
39
+ it "append template messages at header and footer" do
40
+ log = String.new(content)
41
+ ans = "#{header}\n\n#{content}\n\n#{footer}"
42
+
43
+ expect(generator.send(:insert_fixed_string, log)).to eq ans
44
+ end
45
+ end
46
+ end
47
+ end
@@ -13,6 +13,33 @@ describe GitHubChangelogGenerator::Generator do
13
13
  end
14
14
  end
15
15
 
16
+ describe "#detect_link_tag_time" do
17
+ let(:newer_tag) { nil }
18
+
19
+ let(:default_options) { GitHubChangelogGenerator::Parser.default_options.merge(verbose: false) }
20
+ let(:options) do
21
+ {
22
+ future_release: "2.0.0"
23
+ }
24
+ end
25
+ let(:generator) { described_class.new(default_options.merge(options)) }
26
+
27
+ subject do
28
+ generator.detect_link_tag_time(newer_tag)
29
+ end
30
+
31
+ context "When the local date is not the same as the UTC date" do
32
+ before do
33
+ # 2020-12-27T17:00:00-10:00 is 2020-12-28T03:00:00Z.
34
+ # GitHub API date & time use UTC, so this instant when converted as a
35
+ # date should be 2020-12-28.
36
+ expect(Time).to receive(:new).and_return(Time.new(2020, 12, 27, 17, 0, 0, "-10:00"))
37
+ end
38
+
39
+ it { is_expected.to eq(["2.0.0", "2.0.0", Time.gm(2020, 12, 28, 3)]) }
40
+ end
41
+ end
42
+
16
43
  describe "#tag_section_mapping" do
17
44
  let(:all_tags) { tags_from_strings(%w[8 7 6 5 4 3 2 1]) }
18
45
  let(:sorted_tags) { all_tags }
@@ -57,10 +84,10 @@ describe GitHubChangelogGenerator::Generator do
57
84
  shared_examples_for "a changelog with some exclusions" do
58
85
  let(:expected_mapping) do
59
86
  {
60
- tag_with_name("8") => [tag_with_name("7"), tag_with_name("8")],
61
- tag_with_name("6") => [tag_with_name("5"), tag_with_name("6")],
87
+ tag_with_name("8") => [tag_with_name("6"), tag_with_name("8")],
88
+ tag_with_name("6") => [tag_with_name("4"), tag_with_name("6")],
62
89
  tag_with_name("4") => [tag_with_name("3"), tag_with_name("4")],
63
- tag_with_name("3") => [tag_with_name("2"), tag_with_name("3")],
90
+ tag_with_name("3") => [tag_with_name("1"), tag_with_name("3")],
64
91
  tag_with_name("1") => [nil, tag_with_name("1")]
65
92
  }
66
93
  end
@@ -130,6 +157,22 @@ describe GitHubChangelogGenerator::Generator do
130
157
  end
131
158
  end
132
159
 
160
+ describe "#filter_included_tags_regex" do
161
+ subject { generator.filter_included_tags(tags_from_strings(%w[1 2 3])) }
162
+
163
+ context "with matching regex" do
164
+ let(:generator) { GitHubChangelogGenerator::Generator.new(include_tags_regex: "[23]") }
165
+ it { is_expected.to be_a Array }
166
+ it { is_expected.to match_array(tags_from_strings(%w[2 3])) }
167
+ end
168
+
169
+ context "with non-matching regex" do
170
+ let(:generator) { GitHubChangelogGenerator::Generator.new(include_tags_regex: "[45]") }
171
+ it { is_expected.to be_a Array }
172
+ it { is_expected.to match_array(tags_from_strings(%w[])) }
173
+ end
174
+ end
175
+
133
176
  describe "#filter_excluded_tags" do
134
177
  subject { generator.filter_excluded_tags(tags_from_strings(%w[1 2 3])) }
135
178
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHubChangelogGenerator
4
+ RSpec.describe Section do
5
+ let(:options) { {} }
6
+ subject(:section) { described_class.new(options) }
7
+
8
+ describe "#encapsulate_string" do
9
+ let(:string) { "" }
10
+
11
+ context "with the empty string" do
12
+ it "returns the string" do
13
+ expect(section.send(:encapsulate_string, string)).to eq string
14
+ end
15
+ end
16
+
17
+ context "with a string with an escape-needing character in it" do
18
+ let(:string) { "<Inside> and outside" }
19
+
20
+ it "returns the string escaped" do
21
+ expect(section.send(:encapsulate_string, string)).to eq '\\<Inside\\> and outside'
22
+ end
23
+ end
24
+
25
+ context "with a backticked string with an escape-needing character in it" do
26
+ let(:string) { 'back `\` slash' }
27
+
28
+ it "returns the string" do
29
+ expect(section.send(:encapsulate_string, string)).to eq 'back `\` slash'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -85,6 +85,49 @@ describe GitHubChangelogGenerator::OctoFetcher do
85
85
  end
86
86
  end
87
87
 
88
+ describe "#fetch_tag_shas" do
89
+ let(:commits) do
90
+ [
91
+ { sha: "0", parents: [{ sha: "1" }, { sha: "6" }] },
92
+ { sha: "1", parents: [{ sha: "2" }] },
93
+ { sha: "2", parents: [{ sha: "3" }] },
94
+ { sha: "3", parents: [{ sha: "4" }] },
95
+ { sha: "4", parents: [{ sha: "5" }] },
96
+ { sha: "5", parents: [] },
97
+ { sha: "6", parents: [{ sha: "7" }, { sha: "8" }] },
98
+ { sha: "7", parents: [{ sha: "9" }, { sha: "10" }] },
99
+ { sha: "8", parents: [{ sha: "11" }, { sha: "12" }] },
100
+ { sha: "9", parents: [] },
101
+ { sha: "10", parents: [] },
102
+ { sha: "11", parents: [] },
103
+ { sha: "12", parents: [] }
104
+ ]
105
+ end
106
+
107
+ let(:tag0) { { "name" => "tag-0", "commit" => { "sha" => "0" } } }
108
+ let(:tag1) { { "name" => "tag-1", "commit" => { "sha" => "1" } } }
109
+ let(:tag6) { { "name" => "tag-6", "commit" => { "sha" => "6" } } }
110
+
111
+ before do
112
+ allow(fetcher).to receive(:commits).and_return(commits)
113
+ end
114
+
115
+ it "should find all shas with single parents" do
116
+ fetcher.fetch_tag_shas([tag1])
117
+ expect(tag1["shas_in_tag"]).to eq(Set.new(%w[1 2 3 4 5]))
118
+ end
119
+
120
+ it "should find all shas with multiple parents" do
121
+ fetcher.fetch_tag_shas([tag6])
122
+ expect(tag6["shas_in_tag"]).to eq(Set.new(%w[6 7 8 9 10 11 12]))
123
+ end
124
+
125
+ it "should find all shas with mixed parents" do
126
+ fetcher.fetch_tag_shas([tag0])
127
+ expect(tag0["shas_in_tag"]).to eq(Set.new(%w[0 1 2 3 4 5 6 7 8 9 10 11 12]))
128
+ end
129
+ end
130
+
88
131
  describe "#github_fetch_tags" do
89
132
  context "when wrong token provided", :vcr do
90
133
  let(:options) do
@@ -207,7 +250,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
207
250
 
208
251
  # Convert times to Time
209
252
  expected_issue.each_pair do |k, v|
210
- expected_issue[k] = Time.parse(v) if v.to_s =~ /^2015-/
253
+ expected_issue[k] = Time.parse(v) if v.to_s.start_with?("2015-")
211
254
  end
212
255
 
213
256
  expect(issues.first).to eq(expected_issue)
@@ -269,7 +312,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
269
312
 
270
313
  # Convert times to Time
271
314
  expected_pr.each_pair do |k, v|
272
- expected_pr[k] = Time.parse(v) if v.to_s =~ /^2016-01/
315
+ expected_pr[k] = Time.parse(v) if v.to_s.start_with?("2016-01")
273
316
  end
274
317
 
275
318
  expect(pull_requests.first).to eq(expected_pr)
@@ -1,4 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe GitHubChangelogGenerator::Parser do
4
+ let(:argv) { [] }
5
+
6
+ before do
7
+ # Calling abort will abort the test run, allow calls to abort to not accidentaly get positive falses
8
+ allow(Kernel).to receive(:abort)
9
+ end
10
+
11
+ describe ".parse_options" do
12
+ context "when required arguments are given" do
13
+ let(:argv) { ["--user", "the user", "--project", "the_project"] }
14
+
15
+ it "executes and prints the configuration" do
16
+ expect { described_class.parse_options(argv) }.to output(/config_file=>".github_changelog_generator"/).to_stdout
17
+ end
18
+ end
19
+
20
+ context "when --config-file is overridden to something that is not there" do
21
+ let(:argv) { ["--config-file", "does_not_exist"] }
22
+
23
+ it "aborts the execution" do
24
+ expect(Kernel).to receive(:abort)
25
+ expect { described_class.parse_options(argv) }.to output(/Configure which user and project to work on./).to_stderr
26
+ end
27
+ end
28
+
29
+ context "when an option with incorrect type is given" do
30
+ let(:argv) { ["--max-issues", "X"] }
31
+
32
+ it "aborts the execution with error message from parser" do
33
+ expect(Kernel).to receive(:abort)
34
+ expect { described_class.parse_options(argv) }.to output(/invalid argument: --max-issues X/).to_stderr
35
+ end
36
+ end
37
+
38
+ context "when path to configuration file is given" do
39
+ let(:argv) { ["--config-file", File.join(__dir__, "..", "files", "config_example")] }
40
+
41
+ it "uses the values from the configuration file" do
42
+ expect { described_class.parse_options(argv) }.to output(/spec_project/).to_stdout
43
+ end
44
+ end
45
+
46
+ context "when configuration file and parameters are given" do
47
+ let(:argv) { ["--project", "stronger_project", "--config-file", File.join(__dir__, "..", "files", "config_example")] }
48
+
49
+ it "uses the values from the arguments" do
50
+ expect { described_class.parse_options(argv) }.to output(/stronger_project/).to_stdout
51
+ end
52
+ end
53
+ end
4
54
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_changelog_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.16.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Korolev
8
8
  - Olle Jonsson
9
- autorequire:
9
+ - Marco Ferrari
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2019-10-28 00:00:00.000000000 Z
13
+ date: 2021-05-14 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activesupport
@@ -25,6 +26,34 @@ dependencies:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
27
28
  version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: async
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.25.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.25.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: async-http-faraday
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
28
57
  - !ruby/object:Gem::Dependency
29
58
  name: faraday-http-cache
30
59
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +140,7 @@ dependencies:
111
140
  version: '3.0'
112
141
  description: Changelog generation has never been so easy. Fully automate changelog
113
142
  generation - this gem generate changelog file based on tags, issues and merged pull
114
- requests from Github issue tracker.
143
+ requests from GitHub.
115
144
  email: sky4winder+github_changelog_generator@gmail.com
116
145
  executables:
117
146
  - git-generate-changelog
@@ -125,6 +154,7 @@ files:
125
154
  - bin/git-generate-changelog
126
155
  - bin/github_changelog_generator
127
156
  - lib/github_changelog_generator.rb
157
+ - lib/github_changelog_generator/argv_parser.rb
128
158
  - lib/github_changelog_generator/generator/entry.rb
129
159
  - lib/github_changelog_generator/generator/generator.rb
130
160
  - lib/github_changelog_generator/generator/generator_fetcher.rb
@@ -146,12 +176,15 @@ files:
146
176
  - man/git-generate-changelog.md
147
177
  - spec/files/angular.js.md
148
178
  - spec/files/bundler.md
179
+ - spec/files/config_example
149
180
  - spec/files/github-changelog-generator.md
150
181
  - spec/install_gem_in_bundler.gemfile
151
182
  - spec/spec_helper.rb
152
183
  - spec/unit/generator/entry_spec.rb
153
184
  - spec/unit/generator/generator_processor_spec.rb
185
+ - spec/unit/generator/generator_spec.rb
154
186
  - spec/unit/generator/generator_tags_spec.rb
187
+ - spec/unit/generator/section_spec.rb
155
188
  - spec/unit/octo_fetcher_spec.rb
156
189
  - spec/unit/options_spec.rb
157
190
  - spec/unit/parse_file_spec.rb
@@ -183,7 +216,7 @@ homepage: https://github.com/github-changelog-generator/Github-Changelog-Generat
183
216
  licenses:
184
217
  - MIT
185
218
  metadata: {}
186
- post_install_message:
219
+ post_install_message:
187
220
  rdoc_options: []
188
221
  require_paths:
189
222
  - lib
@@ -191,27 +224,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
224
  requirements:
192
225
  - - ">="
193
226
  - !ruby/object:Gem::Version
194
- version: 2.3.0
227
+ version: 2.5.0
195
228
  required_rubygems_version: !ruby/object:Gem::Requirement
196
229
  requirements:
197
230
  - - ">="
198
231
  - !ruby/object:Gem::Version
199
232
  version: '0'
200
233
  requirements: []
201
- rubygems_version: 3.0.3
202
- signing_key:
234
+ rubygems_version: 3.2.7
235
+ signing_key:
203
236
  specification_version: 4
204
- summary: Script, that automatically generate changelog from your tags, issues, labels
237
+ summary: Script that automatically generates a changelog from your tags, issues, labels
205
238
  and pull requests.
206
239
  test_files:
207
240
  - spec/files/angular.js.md
208
241
  - spec/files/bundler.md
242
+ - spec/files/config_example
209
243
  - spec/files/github-changelog-generator.md
210
244
  - spec/install_gem_in_bundler.gemfile
211
245
  - spec/spec_helper.rb
212
246
  - spec/unit/generator/entry_spec.rb
213
247
  - spec/unit/generator/generator_processor_spec.rb
248
+ - spec/unit/generator/generator_spec.rb
214
249
  - spec/unit/generator/generator_tags_spec.rb
250
+ - spec/unit/generator/section_spec.rb
215
251
  - spec/unit/octo_fetcher_spec.rb
216
252
  - spec/unit/options_spec.rb
217
253
  - spec/unit/parse_file_spec.rb