knife-changelog 2.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/release.yml +1 -1
- data/Gemfile +0 -2
- data/README.md +1 -1
- data/knife-changelog.gemspec +5 -4
- data/lib/chef/knife/changelog.rb +5 -46
- data/lib/knife/changelog/policyfile.rb +26 -29
- data/spec/spec_helper.rb +1 -2
- data/spec/unit/policyfile_spec.rb +6 -35
- metadata +9 -35
- data/lib/knife/changelog/berksfile.rb +0 -68
- data/lib/knife/changelog/changelog.rb +0 -267
- data/lib/knife/changelog/git.rb +0 -46
- data/lib/knife/changelog/git_submodule.rb +0 -18
- data/resources/Berksfile +0 -4
- data/resources/Berksfile.lock +0 -9
- data/spec/data/Berksfile +0 -9
- data/spec/data/Berksfile.lock +0 -11
- data/spec/unit/changelog_spec.rb +0 -125
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0b9795c192f99c99cdab392807817812147b4d9482d6b1f5190c8adbac732cd
|
4
|
+
data.tar.gz: bf4fd4b3232690bf0b2f2fb7fd63fd1d829f3f5846a78a0a0c0e9a87b7971cb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ab22310ec4ec7f07b53e8070450b1c86d5893315f9eaf9c65dc5dc74b568419feef48d3762d4df8c839cea8e3871f862ef9a6f659bbe304d64ee180b21e2e1
|
7
|
+
data.tar.gz: 0e24cc98ac6f6c8681a966cb25d92be0a027209cd1498d086788bd9e488a49134b6fc5db7ab3b5606fc3f6668c10755c12f9c914e3d6e679dfc7eab060d2cd7c
|
data/.github/workflows/ci.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Options:
|
|
15
15
|
- generate changelogs for some supermarket hosted cookbooks
|
16
16
|
- generate changelogs for all git located cookbooks
|
17
17
|
|
18
|
-
This plugin works in policyfile style repositories
|
18
|
+
This plugin works in policyfile style repositories
|
19
19
|
|
20
20
|
## Todos
|
21
21
|
|
data/knife-changelog.gemspec
CHANGED
@@ -5,14 +5,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'knife-changelog'
|
8
|
-
spec.version = '
|
8
|
+
spec.version = '4.1.0'
|
9
9
|
spec.authors = ['Gregoire Seux']
|
10
10
|
spec.email = ['kamaradclimber@gmail.com']
|
11
11
|
spec.summary = 'Facilitate access to cookbooks changelog'
|
12
12
|
spec.description = ''
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/criteo/knife-changelog'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
+
spec.required_ruby_version = '>= 3.0'
|
17
|
+
|
16
18
|
spec.files = `git ls-files -z`.split("\x0")
|
17
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
@@ -24,11 +26,10 @@ Gem::Specification.new do |spec|
|
|
24
26
|
spec.add_development_dependency 'rubocop'
|
25
27
|
spec.add_development_dependency 'webmock'
|
26
28
|
|
27
|
-
spec.add_dependency 'berkshelf'
|
28
|
-
spec.add_dependency 'chef'
|
29
29
|
spec.add_dependency 'chef-cli'
|
30
30
|
spec.add_dependency 'deep_merge'
|
31
31
|
spec.add_dependency 'git'
|
32
|
+
spec.add_dependency 'knife'
|
32
33
|
spec.add_dependency 'mixlib-shellout'
|
33
34
|
spec.add_dependency 'rest-client'
|
34
35
|
end
|
data/lib/chef/knife/changelog.rb
CHANGED
@@ -9,39 +9,9 @@ class Chef
|
|
9
9
|
banner 'knife changelog COOKBOOK [COOKBOOK ...]'
|
10
10
|
|
11
11
|
deps do
|
12
|
-
require 'knife/changelog/changelog'
|
13
|
-
require 'knife/changelog/berksfile'
|
14
|
-
require 'berkshelf'
|
15
12
|
require 'knife/changelog/policyfile'
|
16
13
|
end
|
17
14
|
|
18
|
-
option :linkify,
|
19
|
-
short: '-l',
|
20
|
-
long: '--linkify',
|
21
|
-
description: 'add markdown links where relevant',
|
22
|
-
boolean: true
|
23
|
-
|
24
|
-
option :markdown,
|
25
|
-
short: '-m',
|
26
|
-
long: '--markdown',
|
27
|
-
description: 'use markdown syntax',
|
28
|
-
boolean: true
|
29
|
-
|
30
|
-
option :ignore_changelog_file,
|
31
|
-
long: '--ignore-changelog-file',
|
32
|
-
description: 'Ignore changelog file presence, use git history instead',
|
33
|
-
boolean: true
|
34
|
-
|
35
|
-
option :allow_update_all,
|
36
|
-
long: '--allow-update-all',
|
37
|
-
description: 'If no cookbook given, check all Berksfile',
|
38
|
-
boolean: true,
|
39
|
-
default: true
|
40
|
-
|
41
|
-
option :submodules,
|
42
|
-
long: '--submodules SUBMODULE[,SUBMODULE]',
|
43
|
-
description: 'Submoduless to check for changes as well (comma separated)'
|
44
|
-
|
45
15
|
option :prevent_downgrade,
|
46
16
|
long: '--prevent-downgrade',
|
47
17
|
description: 'Fail if knife-changelog detect a cookbook downgrade',
|
@@ -59,24 +29,13 @@ class Chef
|
|
59
29
|
boolean: true,
|
60
30
|
default: false
|
61
31
|
|
62
|
-
option :update,
|
63
|
-
long: '--update',
|
64
|
-
description: 'Update Berksfile'
|
65
|
-
|
66
32
|
def run
|
67
33
|
Log.info config.to_s
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
).generate_changelog
|
74
|
-
else
|
75
|
-
berksfile = Berkshelf::Berksfile.from_options({})
|
76
|
-
puts KnifeChangelog::Changelog::Berksfile
|
77
|
-
.new(berksfile, config)
|
78
|
-
.run(@name_args)
|
79
|
-
end
|
34
|
+
puts PolicyChangelog.new(
|
35
|
+
@name_args,
|
36
|
+
config[:policyfile],
|
37
|
+
config[:with_dependencies]
|
38
|
+
).generate_changelog(config[:prevent_downgrade])
|
80
39
|
end
|
81
40
|
end
|
82
41
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'chef'
|
4
3
|
require 'chef/knife'
|
5
4
|
require 'chef-cli/command/update'
|
6
5
|
require 'chef-cli/command/install'
|
@@ -29,15 +28,15 @@ class PolicyChangelog
|
|
29
28
|
# Updates the Policyfile.lock to get version differences.
|
30
29
|
#
|
31
30
|
# @return update_dir [String] tmp directory with updated Policyfile.lock
|
32
|
-
def update_policyfile_lock
|
33
|
-
|
34
|
-
FileUtils.cp(File.join(@policyfile_dir, 'Policyfile.lock.json'),
|
31
|
+
def update_policyfile_lock(work_dir: nil)
|
32
|
+
work_dir ||= ::Dir.mktmpdir(TMP_PREFIX)
|
33
|
+
FileUtils.cp(File.join(@policyfile_dir, 'Policyfile.lock.json'), work_dir)
|
35
34
|
installer = ChefCLI::Command::Install.new
|
36
35
|
raise "Cannot install Policyfile lock #{@policyfile_path}" unless installer.run([@policyfile_relative_path]).zero?
|
37
36
|
updater = ChefCLI::Command::Update.new
|
38
37
|
raise "Error updating Policyfile lock #{@policyfile_path}" unless updater.run([@policyfile_path, @cookbooks_to_update].flatten).zero?
|
39
38
|
updated_policyfile_lock = read_policyfile_lock(@policyfile_dir)
|
40
|
-
FileUtils.cp(File.join(
|
39
|
+
FileUtils.cp(File.join(work_dir, 'Policyfile.lock.json'), @policyfile_dir)
|
41
40
|
updated_policyfile_lock
|
42
41
|
end
|
43
42
|
|
@@ -107,9 +106,9 @@ class PolicyChangelog
|
|
107
106
|
# @param current [String] current cookbook version tag
|
108
107
|
# @param target [String] target cookbook version tag
|
109
108
|
# @return [String] changelog between tags for one cookbook
|
110
|
-
def git_changelog(source_url, current, target, cookbook = nil)
|
111
|
-
|
112
|
-
repo = Git.clone(source_url,
|
109
|
+
def git_changelog(source_url, current, target, cookbook = nil, work_dir: nil)
|
110
|
+
repo_dir = ::File.join(work_dir || Dir.mktmpdir(TMP_PREFIX), "git-#{source_url.gsub(/[\/:]+/, '-')}")
|
111
|
+
repo = ::Dir.exist?(repo_dir) ? ::Git.open(repo_dir) : ::Git.clone(source_url, repo_dir)
|
113
112
|
cookbook_path = cookbook ? git_cookbook_path(repo, cookbook) : '.'
|
114
113
|
repo.log.path(cookbook_path).between(git_ref(current, repo, cookbook), git_ref(target, repo, cookbook)).map do |commit|
|
115
114
|
"#{commit.sha[0, 7]} #{commit.message.lines.first.strip}"
|
@@ -147,7 +146,7 @@ class PolicyChangelog
|
|
147
146
|
existing_ref = possible_refs.find do |ref|
|
148
147
|
begin
|
149
148
|
repo.checkout(ref)
|
150
|
-
rescue ::Git::
|
149
|
+
rescue ::Git::Error
|
151
150
|
false
|
152
151
|
end
|
153
152
|
end
|
@@ -176,11 +175,11 @@ class PolicyChangelog
|
|
176
175
|
# @param name [String] cookbook name
|
177
176
|
# @param data [Hash] cookbook versions and source url data
|
178
177
|
# @return [String] formatted changelog
|
179
|
-
def format_output(name, data)
|
178
|
+
def format_output(name, data, work_dir: nil)
|
180
179
|
output = ["\nChangelog for #{name}: #{data['current_version']}->#{data['target_version']}"]
|
181
180
|
output << '=' * output.first.size
|
182
181
|
output << if data['current_version']
|
183
|
-
git_changelog(data['source_url'], data['current_version'], data['target_version'], name)
|
182
|
+
git_changelog(data['source_url'], data['current_version'], data['target_version'], name, work_dir: work_dir)
|
184
183
|
else
|
185
184
|
'Cookbook was not in the Policyfile.lock.json'
|
186
185
|
end
|
@@ -215,33 +214,31 @@ class PolicyChangelog
|
|
215
214
|
#
|
216
215
|
# @return [String] formatted version changelog
|
217
216
|
def generate_changelog(prevent_downgrade: false)
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
generate_changelog_from_versions(changelog_cookbooks)
|
217
|
+
::Dir.mktmpdir(TMP_PREFIX) do |dir|
|
218
|
+
lock_current = read_policyfile_lock(@policyfile_dir)
|
219
|
+
current = versions(lock_current['cookbook_locks'], 'current')
|
220
|
+
lock_target = update_policyfile_lock(work_dir: dir)
|
221
|
+
target = versions(lock_target['cookbook_locks'], 'target')
|
222
|
+
updated_cookbooks = current.deep_merge(target).reject { |_name, data| reject_version_filter(data) }
|
223
|
+
changelog_cookbooks = if @with_dependencies || @cookbooks_to_update.nil?
|
224
|
+
updated_cookbooks
|
225
|
+
else
|
226
|
+
updated_cookbooks.select { |name, _data| @cookbooks_to_update.include?(name) }
|
227
|
+
end
|
228
|
+
validate_downgrade!(updated_cookbooks) if prevent_downgrade
|
229
|
+
generate_changelog_from_versions(changelog_cookbooks, work_dir: dir)
|
230
|
+
end
|
234
231
|
end
|
235
232
|
|
236
233
|
# Generates Policyfile changelog
|
237
234
|
#
|
238
235
|
# @param cookbook_versions. Format is { 'NAME' => { 'current_version' => 'VERSION', 'target_version' => 'VERSION' }
|
239
236
|
# @return [String] formatted version changelog
|
240
|
-
def generate_changelog_from_versions(cookbook_versions)
|
237
|
+
def generate_changelog_from_versions(cookbook_versions, work_dir: nil)
|
241
238
|
lock_current = read_policyfile_lock(@policyfile_dir)
|
242
239
|
sources = cookbook_versions.map do |name, data|
|
243
240
|
[name, get_source_url(lock_current['cookbook_locks'][name]['source_options'])] if data['current_version']
|
244
241
|
end.compact.to_h
|
245
|
-
cookbook_versions.deep_merge(sources).map { |name, data| format_output(name, data) }.join("\n")
|
242
|
+
cookbook_versions.deep_merge(sources).map { |name, data| format_output(name, data, work_dir: work_dir) }.join("\n")
|
246
243
|
end
|
247
244
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -92,35 +92,6 @@ RSpec.describe PolicyChangelog do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
describe '#linkify' do
|
96
|
-
subject { KnifeChangelog::Changelog.new(config) }
|
97
|
-
let(:config) { double('config') }
|
98
|
-
let(:changelog) do
|
99
|
-
['9363423 Leverage criteo-flavor 3.11 to benefit from labels']
|
100
|
-
end
|
101
|
-
context 'when url is gitlab style' do
|
102
|
-
let(:url) { 'https://gitlab.com/chef-cookbooks/criteo-rackguru.git' }
|
103
|
-
|
104
|
-
it 'creates a gitlab style link' do
|
105
|
-
expect(subject.linkify(url, changelog).first).to match(%r{https://gitlab.com/chef-cookbooks/criteo-rackguru/commit/9363423})
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'when url is github style' do
|
110
|
-
let(:url) { 'https://github.com/chef-cookbooks/criteo-rackguru.git' }
|
111
|
-
it 'creates a github style link' do
|
112
|
-
expect(subject.linkify(url, changelog).first).to match(%r{https://github.com/chef-cookbooks/criteo-rackguru/commit/9363423})
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'when url has no known style' do
|
117
|
-
let(:url) { 'https://review.mycompany.com/chef-cookbooks/criteo-rackguru.git' }
|
118
|
-
it 'creates a gerrit style link' do
|
119
|
-
expect(subject.linkify(url, changelog).first).to match(%r{https://review.mycompany.com/#/q/9363423})
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
95
|
describe '#versions' do
|
125
96
|
context 'when type is current' do
|
126
97
|
it 'returns correct current versions' do
|
@@ -229,7 +200,7 @@ RSpec.describe PolicyChangelog do
|
|
229
200
|
|
230
201
|
context 'when tag valid' do
|
231
202
|
it 'returns correct git tag' do
|
232
|
-
allow(repo).to receive(:checkout).with('v1.0.0').and_raise(::Git::
|
203
|
+
allow(repo).to receive(:checkout).with('v1.0.0').and_raise(::Git::Error)
|
233
204
|
allow(repo).to receive(:checkout).with('1.0.0').and_return(true)
|
234
205
|
|
235
206
|
expect(changelog.git_ref('1.0.0', repo)).to eq('1.0.0')
|
@@ -238,13 +209,13 @@ RSpec.describe PolicyChangelog do
|
|
238
209
|
|
239
210
|
context 'when tag invalid and able to correct' do
|
240
211
|
it 'returns correct git tag' do
|
241
|
-
allow(repo).to receive(:checkout).with('1.0.0').and_raise(::Git::
|
212
|
+
allow(repo).to receive(:checkout).with('1.0.0').and_raise(::Git::Error)
|
242
213
|
|
243
214
|
tags = %w[v1.0.0 1.0 v1.0 cookbook_name-1.0.0 cookbook_name-1.0 cookbook_name-v1.0.0 cookbook_name-v1.0]
|
244
215
|
tags.each do |valid_result|
|
245
216
|
allow(repo).to receive(:checkout).with(valid_result).and_return(true)
|
246
217
|
tags.reject { |v| v == valid_result }.each do |invalid_result|
|
247
|
-
allow(repo).to receive(:checkout).with(invalid_result).and_raise(::Git::
|
218
|
+
allow(repo).to receive(:checkout).with(invalid_result).and_raise(::Git::Error)
|
248
219
|
end
|
249
220
|
expect(changelog.git_ref('1.0.0', repo, 'cookbook_name')).to eq valid_result
|
250
221
|
end
|
@@ -254,7 +225,7 @@ RSpec.describe PolicyChangelog do
|
|
254
225
|
context 'when tags invalid and unable to correct' do
|
255
226
|
it 'raises exception' do
|
256
227
|
allow(repo).to receive(:remote).and_return(double('remote', url: 'url.com'))
|
257
|
-
allow(repo).to receive(:checkout).with(any_args).and_raise(::Git::
|
228
|
+
allow(repo).to receive(:checkout).with(any_args).and_raise(::Git::Error)
|
258
229
|
|
259
230
|
expect { changelog.git_ref('1.0.0', repo) }
|
260
231
|
.to raise_error(RuntimeError, /Impossible to find existing/)
|
@@ -297,7 +268,7 @@ RSpec.describe PolicyChangelog do
|
|
297
268
|
end
|
298
269
|
context 'when data is nil' do
|
299
270
|
it 'raises an exception' do
|
300
|
-
expect { changelog.reject_version_filter(nil) }.to raise_error
|
271
|
+
expect { changelog.reject_version_filter(nil) }.to raise_error(RuntimeError)
|
301
272
|
end
|
302
273
|
end
|
303
274
|
end
|
@@ -313,7 +284,7 @@ RSpec.describe PolicyChangelog do
|
|
313
284
|
}
|
314
285
|
|
315
286
|
allow(changelog).to receive(:git_changelog)
|
316
|
-
.with(instance_of(String), '4.0.0', '5.0.0', 'users')
|
287
|
+
.with(instance_of(String), '4.0.0', '5.0.0', 'users', work_dir: nil)
|
317
288
|
.and_return('e1b971a Add test commit message')
|
318
289
|
|
319
290
|
output = <<~COMMIT.chomp
|
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:
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregoire Seux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -81,21 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: chef
|
84
|
+
name: chef-cli
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -109,7 +95,7 @@ dependencies:
|
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: deep_merge
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - ">="
|
@@ -123,7 +109,7 @@ dependencies:
|
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
112
|
+
name: git
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - ">="
|
@@ -137,7 +123,7 @@ dependencies:
|
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
126
|
+
name: knife
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - ">="
|
@@ -195,24 +181,15 @@ files:
|
|
195
181
|
- Rakefile
|
196
182
|
- knife-changelog.gemspec
|
197
183
|
- lib/chef/knife/changelog.rb
|
198
|
-
- lib/knife/changelog/berksfile.rb
|
199
|
-
- lib/knife/changelog/changelog.rb
|
200
|
-
- lib/knife/changelog/git.rb
|
201
|
-
- lib/knife/changelog/git_submodule.rb
|
202
184
|
- lib/knife/changelog/policyfile.rb
|
203
|
-
- resources/Berksfile
|
204
|
-
- resources/Berksfile.lock
|
205
|
-
- spec/data/Berksfile
|
206
|
-
- spec/data/Berksfile.lock
|
207
185
|
- spec/data/Policyfile.lock.json
|
208
186
|
- spec/data/Policyfile.rb
|
209
187
|
- spec/data/Policyfile_git.lock.json
|
210
188
|
- spec/data/Policyfile_git.rb
|
211
189
|
- spec/data/updated/Policyfile.lock.json
|
212
190
|
- spec/spec_helper.rb
|
213
|
-
- spec/unit/changelog_spec.rb
|
214
191
|
- spec/unit/policyfile_spec.rb
|
215
|
-
homepage: https://github.com/
|
192
|
+
homepage: https://github.com/criteo/knife-changelog
|
216
193
|
licenses:
|
217
194
|
- MIT
|
218
195
|
metadata: {}
|
@@ -224,25 +201,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
201
|
requirements:
|
225
202
|
- - ">="
|
226
203
|
- !ruby/object:Gem::Version
|
227
|
-
version: '0'
|
204
|
+
version: '3.0'
|
228
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
206
|
requirements:
|
230
207
|
- - ">="
|
231
208
|
- !ruby/object:Gem::Version
|
232
209
|
version: '0'
|
233
210
|
requirements: []
|
234
|
-
rubygems_version: 3.
|
211
|
+
rubygems_version: 3.3.27
|
235
212
|
signing_key:
|
236
213
|
specification_version: 4
|
237
214
|
summary: Facilitate access to cookbooks changelog
|
238
215
|
test_files:
|
239
|
-
- spec/data/Berksfile
|
240
|
-
- spec/data/Berksfile.lock
|
241
216
|
- spec/data/Policyfile.lock.json
|
242
217
|
- spec/data/Policyfile.rb
|
243
218
|
- spec/data/Policyfile_git.lock.json
|
244
219
|
- spec/data/Policyfile_git.rb
|
245
220
|
- spec/data/updated/Policyfile.lock.json
|
246
221
|
- spec/spec_helper.rb
|
247
|
-
- spec/unit/changelog_spec.rb
|
248
222
|
- spec/unit/policyfile_spec.rb
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'changelog'
|
4
|
-
|
5
|
-
class KnifeChangelog
|
6
|
-
class Changelog
|
7
|
-
class Berksfile < Changelog
|
8
|
-
def initialize(berksfile, config)
|
9
|
-
require 'berkshelf'
|
10
|
-
@locked_versions = berksfile.lockfile.locks
|
11
|
-
@sources = berksfile.sources
|
12
|
-
@berksfile = berksfile
|
13
|
-
super(config)
|
14
|
-
end
|
15
|
-
|
16
|
-
def all_cookbooks
|
17
|
-
@locked_versions.keys
|
18
|
-
end
|
19
|
-
|
20
|
-
def new_cookbook?(name)
|
21
|
-
ck_dep(name).nil?
|
22
|
-
end
|
23
|
-
|
24
|
-
# return true if cookbook is downloaded from supermarket
|
25
|
-
def supermarket?(name)
|
26
|
-
# here is berkshelf "expressive" way to say cookbook
|
27
|
-
# comes from supermarket
|
28
|
-
ck_dep(name).location.is_a?(NilClass)
|
29
|
-
end
|
30
|
-
|
31
|
-
# return true if cookbook is downloaded from git
|
32
|
-
def git?(name)
|
33
|
-
ck_dep(name).location.is_a?(Berkshelf::GitLocation)
|
34
|
-
end
|
35
|
-
|
36
|
-
# return true if cookbook is downloaded from local path
|
37
|
-
def local?(name)
|
38
|
-
ck_dep(name).location.is_a?(Berkshelf::PathLocation)
|
39
|
-
end
|
40
|
-
|
41
|
-
# return a Changelog::Location for this cookbook
|
42
|
-
def git_location(name)
|
43
|
-
raise "#{name} has not a git location" unless git?(name)
|
44
|
-
Location.from_berk_git_location(ck_dep(name).location)
|
45
|
-
end
|
46
|
-
|
47
|
-
# return a list of supermarket uri for a given cookbook
|
48
|
-
# example: [ 'https://supermarket.chef.io' ]
|
49
|
-
def supermarkets_for(_name)
|
50
|
-
@sources.map(&:uri)
|
51
|
-
end
|
52
|
-
|
53
|
-
def guess_version_for(name)
|
54
|
-
@locked_versions[name].locked_version.to_s
|
55
|
-
end
|
56
|
-
|
57
|
-
def update(cookbooks)
|
58
|
-
@berksfile.update(*cookbooks)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def ck_dep(name)
|
64
|
-
@locked_versions[name]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,267 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'chef/log'
|
3
|
-
require 'chef/knife'
|
4
|
-
require 'chef/version_class'
|
5
|
-
require 'rest-client'
|
6
|
-
require 'json'
|
7
|
-
require_relative 'git'
|
8
|
-
|
9
|
-
class KnifeChangelog
|
10
|
-
class Changelog
|
11
|
-
|
12
|
-
Location = Struct.new(:uri, :revision, :rev_parse) do
|
13
|
-
# todo move this method to Changelog::Berkshelf
|
14
|
-
def self.from_berk_git_location(location)
|
15
|
-
Location.new(location.uri,
|
16
|
-
location.revision.strip,
|
17
|
-
location.instance_variable_get(:@rev_parse))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(config = {})
|
22
|
-
@tmp_prefix = 'knife-changelog'
|
23
|
-
@config = config
|
24
|
-
@tmp_dirs = []
|
25
|
-
end
|
26
|
-
|
27
|
-
# returns a list of all cookbooks names
|
28
|
-
def all_cookbooks
|
29
|
-
raise NotImplementedError
|
30
|
-
end
|
31
|
-
|
32
|
-
# return true if cookbook is not already listed as dependency
|
33
|
-
def new_cookbook?(name)
|
34
|
-
raise NotImplementedError
|
35
|
-
end
|
36
|
-
|
37
|
-
# return true if cookbook is downloaded from supermarket
|
38
|
-
def supermarket?(name)
|
39
|
-
raise NotImplementedError
|
40
|
-
end
|
41
|
-
|
42
|
-
# return true if cookbook is downloaded from git
|
43
|
-
def git?(name)
|
44
|
-
raise NotImplementedError
|
45
|
-
end
|
46
|
-
|
47
|
-
# return true if cookbook is downloaded from local path
|
48
|
-
def local?(name)
|
49
|
-
raise NotImplementedError
|
50
|
-
end
|
51
|
-
|
52
|
-
# return a Changelog::Location for a given cookbook
|
53
|
-
def git_location(name)
|
54
|
-
raise NotImplementedError
|
55
|
-
end
|
56
|
-
|
57
|
-
# return a list of supermarket uri for a given cookbook
|
58
|
-
# example: [ 'https://supermarket.chef.io' ]
|
59
|
-
def supermarkets_for(name)
|
60
|
-
raise NotImplementedError
|
61
|
-
end
|
62
|
-
|
63
|
-
# return current locked version for a given cookbook
|
64
|
-
def guess_version_for(name)
|
65
|
-
raise NotImplementedError
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
def run(cookbooks)
|
71
|
-
changelog = []
|
72
|
-
begin
|
73
|
-
if cookbooks.empty? and @config[:allow_update_all]
|
74
|
-
cks = all_cookbooks
|
75
|
-
else
|
76
|
-
cks = cookbooks
|
77
|
-
end
|
78
|
-
changelog += cks.map do |cookbook|
|
79
|
-
Chef::Log.debug "Checking changelog for #{cookbook} (cookbook)"
|
80
|
-
execute cookbook
|
81
|
-
end
|
82
|
-
subs = @config[:submodules] || []
|
83
|
-
subs = subs.split(',') if subs.is_a? String
|
84
|
-
changelog += subs.map do |submodule|
|
85
|
-
Chef::Log.debug "Checking changelog for #{submodule} (submodule)"
|
86
|
-
execute(submodule, true)
|
87
|
-
end
|
88
|
-
update(cks) if @config[:update]
|
89
|
-
ensure
|
90
|
-
clean
|
91
|
-
end
|
92
|
-
changelog.compact.join("\n")
|
93
|
-
end
|
94
|
-
|
95
|
-
def clean
|
96
|
-
@tmp_dirs.each do |dir|
|
97
|
-
FileUtils.rm_rf dir
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def handle_new_cookbook
|
102
|
-
stars = '**' if @config[:markdown]
|
103
|
-
["#{stars}Cookbook was not in the berksfile#{stars}"]
|
104
|
-
end
|
105
|
-
|
106
|
-
def execute(name, submodule = false)
|
107
|
-
version_change, changelog = if submodule
|
108
|
-
handle_submodule(name)
|
109
|
-
elsif new_cookbook?(name)
|
110
|
-
['', handle_new_cookbook]
|
111
|
-
else
|
112
|
-
case true
|
113
|
-
when supermarket?(name)
|
114
|
-
handle_source(name)
|
115
|
-
when git?(name)
|
116
|
-
handle_git(name, git_location(name))
|
117
|
-
when local?(name)
|
118
|
-
Chef::Log.debug "path location are always at the last version"
|
119
|
-
['', '']
|
120
|
-
else
|
121
|
-
raise "Cannot handle #{loc.class} yet"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
format_changelog(name, version_change, changelog)
|
125
|
-
end
|
126
|
-
|
127
|
-
def format_changelog(name, version_change, changelog)
|
128
|
-
if changelog.empty?
|
129
|
-
nil
|
130
|
-
else
|
131
|
-
full = ["Changelog for #{name}: #{version_change}"]
|
132
|
-
full << '=' * full.first.size
|
133
|
-
full << changelog
|
134
|
-
full << ''
|
135
|
-
full.compact.join("\n")
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def get_from_supermarket_sources(name)
|
140
|
-
supermarkets_for(name).map do |uri|
|
141
|
-
begin
|
142
|
-
# TODO: we could call /universe endpoint once
|
143
|
-
# instead of calling /api/v1/cookbooks/ for each cookbook
|
144
|
-
RestClient::Request.execute(
|
145
|
-
url: "#{uri}/api/v1/cookbooks/#{name}",
|
146
|
-
method: :get,
|
147
|
-
verify_ssl: false # TODO make this configurable
|
148
|
-
)
|
149
|
-
rescue => e
|
150
|
-
Chef::Log.debug "Error fetching package from supermarket #{e.class.name} #{e.message}"
|
151
|
-
nil
|
152
|
-
end
|
153
|
-
end
|
154
|
-
.compact
|
155
|
-
.map { |json| JSON.parse(json) }
|
156
|
-
.sort_by { |ck| cookbook_highest_version(ck) }
|
157
|
-
.map { |ck| ck['source_url'] || ck ['external_url'] }
|
158
|
-
.last
|
159
|
-
.tap do |source|
|
160
|
-
raise "Cannot find any changelog source for #{name}" unless source
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def cookbook_highest_version(json)
|
165
|
-
json['versions']
|
166
|
-
.map { |version_url| Chef::Version.new(version_url.gsub(/.*\//, '')) }
|
167
|
-
.sort
|
168
|
-
.last
|
169
|
-
end
|
170
|
-
|
171
|
-
def handle_source(name)
|
172
|
-
url = get_from_supermarket_sources(name)
|
173
|
-
raise "No source found in supermarket for cookbook '#{name}'" unless url
|
174
|
-
Chef::Log.debug("Using #{url} as source url")
|
175
|
-
# Workaround source_url not being written in a clonable way.
|
176
|
-
# github.com/blah/cookbook works but git clone requires github.com/blah/cookbook.git
|
177
|
-
if !url.end_with?('.git')
|
178
|
-
url = "#{url}.git"
|
179
|
-
end
|
180
|
-
location = Location.new(url, guess_version_for(name), 'HEAD')
|
181
|
-
handle_git(name, location)
|
182
|
-
end
|
183
|
-
|
184
|
-
def detect_cur_revision(name, rev, git)
|
185
|
-
unless git.revision_exists?(rev)
|
186
|
-
prefixed_rev = 'v' + rev
|
187
|
-
return prefixed_rev if git.revision_exists?(prefixed_rev)
|
188
|
-
fail "#{rev} is not an existing revision (#{name}), not a tag/commit/branch name."
|
189
|
-
end
|
190
|
-
rev
|
191
|
-
end
|
192
|
-
|
193
|
-
def handle_submodule(name)
|
194
|
-
subm_url = Mixlib::ShellOut.new("git config --list| grep ^submodule | grep ^submodule.#{name}.url")
|
195
|
-
subm_url.run_command
|
196
|
-
subm_url.error!
|
197
|
-
url = subm_url.stdout.lines.first.split('=')[1].chomp
|
198
|
-
subm_revision = Mixlib::ShellOut.new("git submodule status #{name}")
|
199
|
-
subm_revision.run_command
|
200
|
-
subm_revision.error!
|
201
|
-
revision = subm_revision.stdout.strip.split(' ').first
|
202
|
-
revision.gsub!(/^\+/, '')
|
203
|
-
loc = Location.new(url, revision, 'HEAD')
|
204
|
-
handle_git(name, loc)
|
205
|
-
end
|
206
|
-
|
207
|
-
# take cookbook name and Changelog::Location instance
|
208
|
-
def handle_git(name, location)
|
209
|
-
# todo: remove this compat check
|
210
|
-
raise "should be a location" unless location.is_a?(Changelog::Location)
|
211
|
-
git = Git.new(@tmp_prefix, location.uri)
|
212
|
-
@tmp_dirs << git.shallow_clone
|
213
|
-
|
214
|
-
rev_parse = location.rev_parse
|
215
|
-
cur_rev = detect_cur_revision(name, location.revision, git)
|
216
|
-
changelog_file = git.files(rev_parse).find { |line| line =~ /\s(changelog.*$)/i }
|
217
|
-
changelog = if changelog_file and !@config[:ignore_changelog_file]
|
218
|
-
Chef::Log.info "Found changelog file : " + $1
|
219
|
-
generate_from_changelog_file($1, cur_rev, rev_parse, git)
|
220
|
-
end
|
221
|
-
changelog ||= generate_from_git_history(git, location, cur_rev, rev_parse)
|
222
|
-
["#{cur_rev}->#{rev_parse}", changelog]
|
223
|
-
end
|
224
|
-
|
225
|
-
def generate_from_changelog_file(filename, current_rev, rev_parse, git)
|
226
|
-
ch = git.diff(filename, current_rev, rev_parse)
|
227
|
-
.collect { |line| $1.strip if line =~ /^{\+(.*)\+}$/ }.compact
|
228
|
-
.map { |line| line.gsub(/^#+(.*)$/, "\\1\n---")} # replace section by smaller header
|
229
|
-
.select { |line| !(line =~ /^===+/)}.compact # remove header lines
|
230
|
-
ch.empty? ? nil : ch
|
231
|
-
end
|
232
|
-
|
233
|
-
def generate_from_git_history(git, location, current_rev, rev_parse)
|
234
|
-
c = git.log(current_rev, rev_parse)
|
235
|
-
n = https_url(location)
|
236
|
-
c = linkify(n, c) if @config[:linkify] and n
|
237
|
-
c = c.map { |line| "* " + line } if @config[:markdown]
|
238
|
-
c = c.map { |line| line.strip } # clean end of line
|
239
|
-
c
|
240
|
-
end
|
241
|
-
|
242
|
-
GERRIT_REGEXP = %r{^(.*)/[^/]+/[^/]+(?:\.git)$}
|
243
|
-
def linkify(url, changelog)
|
244
|
-
format = case url
|
245
|
-
when /gitlab/, /github/
|
246
|
-
"\\2 (#{url.chomp('.git')}/commit/\\1)"
|
247
|
-
when GERRIT_REGEXP
|
248
|
-
"\\2 (#{::Regexp.last_match(1)}/#/q/\\1)"
|
249
|
-
end
|
250
|
-
format ? changelog.map { |line| line.sub(/^([a-f0-9]+) (.*)$/, format) } : changelog
|
251
|
-
end
|
252
|
-
|
253
|
-
def https_url(location)
|
254
|
-
if location.uri =~ /^\w+:\/\/(.*@)?(.*)(\.git)?/
|
255
|
-
"https://%s" % [ $2 ]
|
256
|
-
else
|
257
|
-
fail "Cannot guess http url from git remote url: #{location.uri}"
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
def short(location)
|
262
|
-
if location.uri =~ /([\w-]+)\/([\w-]+)(\.git)?$/
|
263
|
-
"%s/%s" % [$1,$2]
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
data/lib/knife/changelog/git.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
class KnifeChangelog
|
2
|
-
class Git
|
3
|
-
attr_accessor :tmp_prefix, :uri
|
4
|
-
|
5
|
-
def initialize(tmp_prefix, uri)
|
6
|
-
@tmp_prefix = tmp_prefix
|
7
|
-
@uri = uri
|
8
|
-
end
|
9
|
-
|
10
|
-
def shallow_clone
|
11
|
-
Chef::Log.debug "Cloning #{uri} in #{tmp_prefix}"
|
12
|
-
dir = Dir.mktmpdir(tmp_prefix)
|
13
|
-
clone = Mixlib::ShellOut.new("git clone --bare #{uri} bare-clone", cwd: dir)
|
14
|
-
clone.run_command
|
15
|
-
clone.error!
|
16
|
-
@clone_dir = ::File.join(dir, 'bare-clone')
|
17
|
-
@clone_dir
|
18
|
-
end
|
19
|
-
|
20
|
-
def files(rev_parse)
|
21
|
-
ls_tree = Mixlib::ShellOut.new("git ls-tree -r #{rev_parse}", cwd: @clone_dir)
|
22
|
-
ls_tree.run_command
|
23
|
-
ls_tree.error!
|
24
|
-
ls_tree.stdout.lines.map(&:strip)
|
25
|
-
end
|
26
|
-
|
27
|
-
def diff(filename, current_rev, rev_parse)
|
28
|
-
diff = Mixlib::ShellOut.new("git diff #{current_rev}..#{rev_parse} --word-diff -- #{filename}", cwd: @clone_dir)
|
29
|
-
diff.run_command
|
30
|
-
diff.stdout.lines
|
31
|
-
end
|
32
|
-
|
33
|
-
def log(current_rev, rev_parse)
|
34
|
-
log = Mixlib::ShellOut.new("git log --no-merges --abbrev-commit --pretty=oneline #{current_rev}..#{rev_parse}", cwd: @clone_dir)
|
35
|
-
log.run_command
|
36
|
-
log.stdout.lines
|
37
|
-
end
|
38
|
-
|
39
|
-
def revision_exists?(revision)
|
40
|
-
Chef::Log.debug "Testing existence of #{revision}"
|
41
|
-
revlist = Mixlib::ShellOut.new("git rev-list --quiet #{revision}", cwd: @clone_dir)
|
42
|
-
revlist.run_command
|
43
|
-
!revlist.error?
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'chef/log'
|
3
|
-
require_relative 'changelog'
|
4
|
-
|
5
|
-
class KnifeChangelog
|
6
|
-
class GitSubmodule < Changelog
|
7
|
-
|
8
|
-
def run(submodules)
|
9
|
-
raise ::ArgumentError, "Submodules must be an Array instead of #{submodules.inspect}" unless submodules.is_a?(::Array)
|
10
|
-
submodules.map do |submodule|
|
11
|
-
Chef::Log.debug "Checking changelog for #{submodule} (submodule)"
|
12
|
-
format_changelog(submodule, *handle_submodule(submodule))
|
13
|
-
end.compact.join("\n")
|
14
|
-
ensure
|
15
|
-
clean
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/resources/Berksfile
DELETED
data/resources/Berksfile.lock
DELETED
data/spec/data/Berksfile
DELETED
data/spec/data/Berksfile.lock
DELETED
data/spec/unit/changelog_spec.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'berkshelf'
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
RSpec.shared_examples 'changelog generation' do
|
7
|
-
# this supposes that "changelog" is an instance of KnifeChangelog::Changelog
|
8
|
-
it 'detects basic changelog' do
|
9
|
-
mock_git('second_out_of_date', <<-EOH)
|
10
|
-
aaaaaa commit in second_out_of_date
|
11
|
-
bbbbbb bugfix in second_out_of_date
|
12
|
-
EOH
|
13
|
-
mock_git('outdated1', <<-EOH)
|
14
|
-
aaaaaa commit in outdated1
|
15
|
-
bbbbbb bugfix in outdated1
|
16
|
-
EOH
|
17
|
-
mock_git('uptodate', '')
|
18
|
-
|
19
|
-
changelog_txt = changelog.run(%w[new_cookbook uptodate outdated1 second_out_of_date])
|
20
|
-
expect(changelog_txt).to match(/commit in outdated1/)
|
21
|
-
expect(changelog_txt).to match(/commit in second_out_of_date/)
|
22
|
-
expect(changelog_txt).not_to match(/uptodate/)
|
23
|
-
expect(changelog_txt).to match(/new_cookbook: \n.*\nCookbook was not/)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe KnifeChangelog::Changelog do
|
28
|
-
before(:each) do
|
29
|
-
stub_request(:get, %r{https://mysupermarket.io/api/v1/cookbooks/})
|
30
|
-
.to_return(status: 404, body: '{}')
|
31
|
-
|
32
|
-
mock_supermarket('uptodate', %w[1.0.0])
|
33
|
-
mock_supermarket('outdated1', %w[1.0.0 1.1.0])
|
34
|
-
# TODO: we should make second_out_of_date a git location
|
35
|
-
mock_supermarket('second_out_of_date', %w[1.0.0 1.2.0])
|
36
|
-
|
37
|
-
mock_universe('https://mysupermarket2.io', uptodate: %w[1.0.0], outdated1: %w[1.0.0 1.1.0], second_out_of_date: %w[1.0.0 1.2.0])
|
38
|
-
mock_universe('https://mysupermarket.io', {})
|
39
|
-
end
|
40
|
-
|
41
|
-
def mock_git(name, changelog)
|
42
|
-
expect(KnifeChangelog::Git).to receive(:new)
|
43
|
-
.with(anything, /#{name}(.git|$)/)
|
44
|
-
.and_return(double(name,
|
45
|
-
shallow_clone: '/tmp/randomdir12345',
|
46
|
-
revision_exists?: true,
|
47
|
-
files: [],
|
48
|
-
log: changelog.split("\n")))
|
49
|
-
end
|
50
|
-
|
51
|
-
def mock_supermarket(name, versions)
|
52
|
-
stub_request(:get, %r{https://mysupermarket2.io/api/v1/cookbooks/#{name}})
|
53
|
-
.to_return(status: 200, body: supermarket_versions(name, versions))
|
54
|
-
end
|
55
|
-
|
56
|
-
def supermarket_versions(name, versions)
|
57
|
-
{
|
58
|
-
name: name,
|
59
|
-
maintainer: 'Linus',
|
60
|
-
description: 'small project on the side',
|
61
|
-
category: 'Operating System',
|
62
|
-
source_url: "https://github.com/chef-cookbooks/#{name}",
|
63
|
-
versions: []
|
64
|
-
}.tap do |json|
|
65
|
-
versions.each do |v|
|
66
|
-
json[:versions] << "https://source.io/#{name}/#{v}"
|
67
|
-
end
|
68
|
-
end.to_json
|
69
|
-
end
|
70
|
-
|
71
|
-
def mock_universe(supermarket_url, cookbooks)
|
72
|
-
universe = cookbooks.transform_values do |versions|
|
73
|
-
versions.map do |v|
|
74
|
-
[v, {
|
75
|
-
location_type: 'opscode',
|
76
|
-
location_path: "#{supermarket_url}/api/v1",
|
77
|
-
download_url: "#{supermarket_url}/api/v1/cookbooks/insertnamehere/versions/#{v}/download",
|
78
|
-
dependencies: {}
|
79
|
-
}]
|
80
|
-
end.to_h
|
81
|
-
end
|
82
|
-
stub_request(:get, "#{supermarket_url}/universe")
|
83
|
-
.to_return(status: 200, body: universe.to_json)
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'in Berksfile mode' do
|
87
|
-
let(:berksfile) do
|
88
|
-
Berkshelf::Berksfile.from_options(
|
89
|
-
berksfile: File.join(File.dirname(__FILE__), '../data/Berksfile')
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:options) do
|
94
|
-
{}
|
95
|
-
end
|
96
|
-
|
97
|
-
let(:changelog) do
|
98
|
-
KnifeChangelog::Changelog::Berksfile.new(berksfile, options)
|
99
|
-
end
|
100
|
-
|
101
|
-
include_examples 'changelog generation'
|
102
|
-
|
103
|
-
context 'with --update' do
|
104
|
-
let(:options) do
|
105
|
-
{ update: true }
|
106
|
-
end
|
107
|
-
it 'updates Berksfile' do
|
108
|
-
mock_git('outdated1', <<-EOH)
|
109
|
-
aaaaaa commit in outdated1
|
110
|
-
bbbbbb bugfix in outdated1
|
111
|
-
EOH
|
112
|
-
expect(berksfile).to receive(:update).with('outdated1')
|
113
|
-
changelog.run(%w[outdated1])
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class Hash
|
120
|
-
unless Chef::Version.new(RUBY_VERSION) >= Chef::Version.new('2.4')
|
121
|
-
def transform_values
|
122
|
-
map { |k, v| [k, (yield v)] }.to_h
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|