knife-changelog 1.0.7 → 1.0.8

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
  SHA256:
3
- metadata.gz: 69172c86c7b7796d3ec52bc1738688d33dcef55ccdf98d4f171cff25b9ee03a1
4
- data.tar.gz: 94329ddcd6763e6d6ab8d510ce5e06850f93798e026405bf3d114fd51e13a7cf
3
+ metadata.gz: a8c08f818e37b6f6f8dedf0ac339c7f2630eb2274c7d8a2b4972aeb32cb0f33a
4
+ data.tar.gz: 8c2201411c66858acdad4549da4a4d72cb9f2b90c157b1b4fa584b597ae4eb9d
5
5
  SHA512:
6
- metadata.gz: 2eef04a07df70eae15e9d5b8158c5956fb7782e5ad678545d65164b027aacf17e80c17d2efd9100644b46aed638b85f6cdd437f0877a31d7041351d7a8b3f8f6
7
- data.tar.gz: 43a215deba3fae621e9c156acfbc8a0ebb8101a94c15932e355fefbfba6532457fe31f25bd277c9e054bdcd8afcd868270e78ac8155780dee75220d06069bb9a
6
+ metadata.gz: 3dfadbf13353ae064112f338fd037208318bf875c91007bc59bb366154677bed539066929c1b70c79b1cf572358285234b3eade84345ca09c2bc0c7b6ad8878f
7
+ data.tar.gz: f7c58bc018fedc0c91a1a745637036741f7990760d9632a7723c9a04f0286ede092bfa910a1d379e8cefe14f545434ff286d87626e4944d7455d724311ddb7cb
@@ -55,7 +55,7 @@ class Chef
55
55
  def run
56
56
  Log.info config
57
57
  if config[:policyfile] && File.exist?(config[:policyfile])
58
- PolicyChangelog.new(@name_args, config[:policyfile]).generate_changelog
58
+ puts PolicyChangelog.new(@name_args, config[:policyfile]).generate_changelog
59
59
  else
60
60
  berksfile = Berkshelf::Berksfile.from_options({})
61
61
  puts KnifeChangelog::Changelog::Berksfile
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Changelog
3
- VERSION = '1.0.7'.freeze
3
+ VERSION = '1.0.8'.freeze
4
4
  end
5
5
  end
@@ -25,19 +25,13 @@ class PolicyChangelog
25
25
  #
26
26
  # @return update_dir [String] tmp directory with updated Policyfile.lock
27
27
  def update_policyfile_lock
28
- update_dir = Dir.mktmpdir
29
- %w[Policyfile.rb Policyfile.lock.json].each do |file|
30
- FileUtils.cp(
31
- File.join(@policyfile_dir, file),
32
- update_dir
33
- )
34
- end
28
+ backup_dir = Dir.mktmpdir
29
+ FileUtils.cp(File.join(@policyfile_dir, 'Policyfile.lock.json'), backup_dir)
35
30
  updater = ChefDK::Command::Update.new
36
- updater.run([
37
- File.join(update_dir, 'Policyfile.rb'),
38
- @cookbooks_to_update
39
- ].flatten)
40
- update_dir
31
+ updater.run([@policyfile_path, @cookbooks_to_update].flatten)
32
+ updated_policyfile_lock = read_policyfile_lock(@policyfile_dir)
33
+ FileUtils.cp(File.join(backup_dir, 'Policyfile.lock.json'), @policyfile_dir)
34
+ updated_policyfile_lock
41
35
  end
42
36
 
43
37
  # Parses JSON in Policyfile.lock.
@@ -153,15 +147,16 @@ class PolicyChangelog
153
147
  repo.tags.last.name[/^v/] ? 'v' : ''
154
148
  end
155
149
 
156
- # Prints out commit changelog in a nicely formatted way
150
+ # Formats commit changelog to be more readable
157
151
  #
158
152
  # @param name [String] cookbook name
159
153
  # @param data [Hash] cookbook versions and source url data
160
- def print_commit_changelog(name, data)
161
- output = "\nChangelog for #{name}: #{data['current_version']}->#{data['target_version']}"
162
- puts output
163
- puts '=' * output.size
164
- puts git_changelog(data['source_url'], data['current_version'], data['target_version'])
154
+ # @return [String] formatted changelog
155
+ def format_output(name, data)
156
+ output = ["\nChangelog for #{name}: #{data['current_version']}->#{data['target_version']}"]
157
+ output << '=' * output.first.size
158
+ output << git_changelog(data['source_url'], data['current_version'], data['target_version'])
159
+ output.join("\n")
165
160
  end
166
161
 
167
162
  # Filters out cookbooks which are not updated, are not used after update or
@@ -177,11 +172,13 @@ class PolicyChangelog
177
172
  end
178
173
 
179
174
  # Generates Policyfile changelog
175
+ #
176
+ # @return [String] formatted version changelog
180
177
  def generate_changelog
181
178
  lock_current = read_policyfile_lock(@policyfile_dir)
182
179
  current = versions(lock_current['cookbook_locks'], 'current')
183
180
 
184
- lock_target = read_policyfile_lock(update_policyfile_lock)
181
+ lock_target = update_policyfile_lock
185
182
  target = versions(lock_target['cookbook_locks'], 'target')
186
183
 
187
184
  updated_cookbooks = current.deep_merge(target).reject { |_name, data| reject_version_filter(data) }
@@ -189,6 +186,7 @@ class PolicyChangelog
189
186
  updated_cookbooks.each_key do |name|
190
187
  sources[name] = get_source_url(lock_target['cookbook_locks'][name]['source_options'])
191
188
  end
192
- updated_cookbooks.deep_merge(sources).each { |name, data| print_commit_changelog(name, data) }
189
+ updated_cookbooks.deep_merge(sources).map { |name, data| format_output(name, data) }.join("\n")
193
190
  end
194
191
  end
192
+
@@ -8,8 +8,8 @@ RSpec.describe PolicyChangelog do
8
8
  File.expand_path(File.join(File.dirname(__FILE__), '../data'))
9
9
  end
10
10
 
11
- let(:tmp_dir) do
12
- File.join(pf_dir, 'tmp_dir')
11
+ let(:target_dir) do
12
+ File.join(pf_dir, 'updated')
13
13
  end
14
14
 
15
15
  let(:changelog) do
@@ -21,7 +21,7 @@ RSpec.describe PolicyChangelog do
21
21
  end
22
22
 
23
23
  let(:lock_target) do
24
- JSON.parse(File.read(File.join(tmp_dir, 'Policyfile.lock.json')))
24
+ JSON.parse(File.read(File.join(target_dir, 'Policyfile.lock.json')))
25
25
  end
26
26
 
27
27
  let(:current_versions) do
@@ -249,11 +249,15 @@ RSpec.describe PolicyChangelog do
249
249
  context 'when generating a changelog' do
250
250
  it 'detects type for regular tag' do
251
251
  allow(changelog).to receive(:update_policyfile_lock)
252
- .and_return(tmp_dir)
252
+ .and_return(changelog.read_policyfile_lock(target_dir))
253
253
  allow(changelog).to receive(:git_changelog)
254
254
  .and_return('e1b971a Add test commit message')
255
255
 
256
- expect { changelog.generate_changelog }.not_to raise_error(RuntimeError)
256
+ output = "\nChangelog for users: 4.0.0->5.3.1\n" \
257
+ "==================================\n" \
258
+ "e1b971a Add test commit message"
259
+
260
+ expect(changelog.generate_changelog).to eq(output)
257
261
  end
258
262
  end
259
263
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Seux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -219,7 +219,7 @@ files:
219
219
  - spec/data/Berksfile.lock
220
220
  - spec/data/Policyfile.lock.json
221
221
  - spec/data/Policyfile.rb
222
- - spec/data/tmp_dir/Policyfile.lock.json
222
+ - spec/data/updated/Policyfile.lock.json
223
223
  - spec/spec_helper.rb
224
224
  - spec/unit/changelog_spec.rb
225
225
  - spec/unit/policyfile_spec.rb
@@ -252,7 +252,7 @@ test_files:
252
252
  - spec/data/Berksfile.lock
253
253
  - spec/data/Policyfile.lock.json
254
254
  - spec/data/Policyfile.rb
255
- - spec/data/tmp_dir/Policyfile.lock.json
255
+ - spec/data/updated/Policyfile.lock.json
256
256
  - spec/spec_helper.rb
257
257
  - spec/unit/changelog_spec.rb
258
258
  - spec/unit/policyfile_spec.rb