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 +4 -4
- data/lib/chef/knife/changelog.rb +1 -1
- data/lib/knife/changelog/version.rb +1 -1
- data/lib/policyfile.rb +18 -20
- data/spec/data/{tmp_dir → updated}/Policyfile.lock.json +0 -0
- data/spec/unit/policyfile_spec.rb +9 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c08f818e37b6f6f8dedf0ac339c7f2630eb2274c7d8a2b4972aeb32cb0f33a
|
4
|
+
data.tar.gz: 8c2201411c66858acdad4549da4a4d72cb9f2b90c157b1b4fa584b597ae4eb9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dfadbf13353ae064112f338fd037208318bf875c91007bc59bb366154677bed539066929c1b70c79b1cf572358285234b3eade84345ca09c2bc0c7b6ad8878f
|
7
|
+
data.tar.gz: f7c58bc018fedc0c91a1a745637036741f7990760d9632a7723c9a04f0286ede092bfa910a1d379e8cefe14f545434ff286d87626e4944d7455d724311ddb7cb
|
data/lib/chef/knife/changelog.rb
CHANGED
@@ -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
|
data/lib/policyfile.rb
CHANGED
@@ -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
|
-
|
29
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
#
|
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
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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 =
|
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).
|
189
|
+
updated_cookbooks.deep_merge(sources).map { |name, data| format_output(name, data) }.join("\n")
|
193
190
|
end
|
194
191
|
end
|
192
|
+
|
File without changes
|
@@ -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(:
|
12
|
-
File.join(pf_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(
|
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(
|
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
|
-
|
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.
|
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-
|
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/
|
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/
|
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
|