github_changelog_generator 1.15.2 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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)
metadata CHANGED
@@ -1,16 +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.2
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Korolev
8
8
  - Olle Jonsson
9
9
  - Marco Ferrari
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-04-07 00:00:00.000000000 Z
13
+ date: 2021-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -26,6 +26,34 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
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'
29
57
  - !ruby/object:Gem::Dependency
30
58
  name: faraday-http-cache
31
59
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +180,9 @@ files:
152
180
  - spec/spec_helper.rb
153
181
  - spec/unit/generator/entry_spec.rb
154
182
  - spec/unit/generator/generator_processor_spec.rb
183
+ - spec/unit/generator/generator_spec.rb
155
184
  - spec/unit/generator/generator_tags_spec.rb
185
+ - spec/unit/generator/section_spec.rb
156
186
  - spec/unit/octo_fetcher_spec.rb
157
187
  - spec/unit/options_spec.rb
158
188
  - spec/unit/parse_file_spec.rb
@@ -184,7 +214,7 @@ homepage: https://github.com/github-changelog-generator/Github-Changelog-Generat
184
214
  licenses:
185
215
  - MIT
186
216
  metadata: {}
187
- post_install_message:
217
+ post_install_message:
188
218
  rdoc_options: []
189
219
  require_paths:
190
220
  - lib
@@ -192,15 +222,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
222
  requirements:
193
223
  - - ">="
194
224
  - !ruby/object:Gem::Version
195
- version: 2.3.0
225
+ version: 2.5.0
196
226
  required_rubygems_version: !ruby/object:Gem::Requirement
197
227
  requirements:
198
228
  - - ">="
199
229
  - !ruby/object:Gem::Version
200
230
  version: '0'
201
231
  requirements: []
202
- rubygems_version: 3.1.2
203
- signing_key:
232
+ rubygems_version: 3.2.7
233
+ signing_key:
204
234
  specification_version: 4
205
235
  summary: Script, that automatically generate changelog from your tags, issues, labels
206
236
  and pull requests.
@@ -212,7 +242,9 @@ test_files:
212
242
  - spec/spec_helper.rb
213
243
  - spec/unit/generator/entry_spec.rb
214
244
  - spec/unit/generator/generator_processor_spec.rb
245
+ - spec/unit/generator/generator_spec.rb
215
246
  - spec/unit/generator/generator_tags_spec.rb
247
+ - spec/unit/generator/section_spec.rb
216
248
  - spec/unit/octo_fetcher_spec.rb
217
249
  - spec/unit/options_spec.rb
218
250
  - spec/unit/parse_file_spec.rb