knife-changelog 1.4.1 → 1.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac3be8ff1b8cf7b08329253913b46a0ff46f5c1d997093f00e06f2142ee9f236
4
- data.tar.gz: f7ab4788ef5381e77f46ef47f3f54e194f50674e663c2b901109db0755f85ca3
3
+ metadata.gz: 023bd4002b877a917379e771cda46f246bf6bde1da80d980d5398b0e3d020e48
4
+ data.tar.gz: bb6e6831e93c34bc0896313ff01faa0935b371d1b37031213fbb075ede0cc908
5
5
  SHA512:
6
- metadata.gz: b2317057716149eef467ab3ea30d6a34d58515d6dcb8af7b3309e25a238888384f4f0b44f7671df8cbb2d8f656fca1a433a06561866d70de3f5976368e36fcf5
7
- data.tar.gz: f1ce18ea422aef699f9bf9475299b6324bda6bf492197aa066dd61ab2c956235d9983629395bfbc3c85130cc72723eb4c96671fe5a5bddd79b5a49bfc8f4a96e
6
+ metadata.gz: f0a9cb080f54d631f2e7029dcf7aa55c873c39f00f74b932ecb4a4b6f46b4dab2f437e6eb48fb6cec30efcd17dce79a2c98ab584caf0d87ac4d8385d88fce159
7
+ data.tar.gz: c7bcf3f6ef83c9cfcefae5bb7423daa63e2b292cbd8c2c67c72670cf4e6c7c8cab641d8016cca205bf298e76c015dd24575963f8ba122070012606582933b906
@@ -0,0 +1,15 @@
1
+ name: Tests
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ matrix:
8
+ ruby-version: ['2.5', '2.7']
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: ${{ matrix.ruby-version }}
14
+ bundler-cache: true
15
+ - run: bundle exec rake
@@ -0,0 +1,18 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ tags: [ '*' ]
5
+ jobs:
6
+ release:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: 2.7
13
+ - run: |
14
+ install -D -m 600 <(echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}") $HOME/.gem/credentials
15
+ gem build *.gemspec
16
+ gem push *.gem
17
+ env:
18
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
3
- begin
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec)
6
5
 
7
- task :default => :spec
8
- rescue LoadError
9
- end
6
+ task default: :spec
@@ -5,7 +5,7 @@ $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 = '1.4.1'
8
+ spec.version = '1.7.0'
9
9
  spec.authors = ['Gregoire Seux']
10
10
  spec.email = ['kamaradclimber@gmail.com']
11
11
  spec.summary = 'Facilitate access to cookbooks changelog'
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.6'
22
21
  spec.add_development_dependency 'pry'
23
22
  spec.add_development_dependency 'rake'
24
23
  spec.add_development_dependency 'rspec'
@@ -64,7 +64,7 @@ class Chef
64
64
  description: 'Update Berksfile'
65
65
 
66
66
  def run
67
- Log.info config
67
+ Log.info config.to_s
68
68
  if config[:policyfile] && File.exist?(config[:policyfile])
69
69
  puts PolicyChangelog.new(
70
70
  @name_args,
@@ -18,7 +18,7 @@ class KnifeChangelog
18
18
  end
19
19
  end
20
20
 
21
- def initialize(config)
21
+ def initialize(config = {})
22
22
  @tmp_prefix = 'knife-changelog'
23
23
  @config = config
24
24
  @tmp_dirs = []
@@ -177,7 +177,7 @@ class KnifeChangelog
177
177
  if !url.end_with?('.git')
178
178
  url = "#{url}.git"
179
179
  end
180
- location = Location.new(url, guess_version_for(name), 'master')
180
+ location = Location.new(url, guess_version_for(name), 'HEAD')
181
181
  handle_git(name, location)
182
182
  end
183
183
 
@@ -200,7 +200,7 @@ class KnifeChangelog
200
200
  subm_revision.error!
201
201
  revision = subm_revision.stdout.strip.split(' ').first
202
202
  revision.gsub!(/^\+/, '')
203
- loc = Location.new(url, revision, 'master')
203
+ loc = Location.new(url, revision, 'HEAD')
204
204
  handle_git(name, loc)
205
205
  end
206
206
 
@@ -0,0 +1,18 @@
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
@@ -107,14 +107,30 @@ class PolicyChangelog
107
107
  # @param current [String] current cookbook version tag
108
108
  # @param target [String] target cookbook version tag
109
109
  # @return [String] changelog between tags for one cookbook
110
- def git_changelog(source_url, current, target)
110
+ def git_changelog(source_url, current, target, cookbook = nil)
111
111
  dir = Dir.mktmpdir(TMP_PREFIX)
112
112
  repo = Git.clone(source_url, dir)
113
- repo.log.between(git_ref(current, repo), git_ref(target, repo)).map do |commit|
113
+ cookbook_path = cookbook ? git_cookbook_path(repo, cookbook) : '.'
114
+ repo.log.path(cookbook_path).between(git_ref(current, repo, cookbook), git_ref(target, repo, cookbook)).map do |commit|
114
115
  "#{commit.sha[0, 7]} #{commit.message.lines.first.strip}"
115
116
  end.join("\n")
116
117
  end
117
118
 
119
+ # Tries to find the location of a specific cookbook in the given repo
120
+ #
121
+ # @param repo [Git::Base] Git repository object
122
+ # @param cookbook [String] name of the cookbook to search the location
123
+ # @return [String] reative location of the cookbook in the repo
124
+ def git_cookbook_path(repo, cookbook)
125
+ metadata_files = ['metadata.rb', '*/metadata.rb'].flat_map { |location| repo.ls_files(location).keys }
126
+ metadata_path = metadata_files.find do |path|
127
+ path = ::File.join(repo.dir.to_s, path)
128
+ ::Chef::Cookbook::Metadata.new.tap { |m| m.from_file(path) }.name == cookbook
129
+ end
130
+ raise "Impossible to find matching metadata for #{cookbook} in #{repo.remote.url}" unless metadata_path
131
+ ::File.dirname(metadata_path)
132
+ end
133
+
118
134
  # Tries to convert a supermarket tag to a git reference
119
135
  # if there is a difference in formatting between the two.
120
136
  # This is issue is present for the 'java' cookbook.
@@ -122,9 +138,11 @@ class PolicyChangelog
122
138
  #
123
139
  # @param ref [String] version reference
124
140
  # @param repo [Git::Base] Git repository object
141
+ # @param cookbook [String] name of the cookbook to ref against
125
142
  # @return [String]
126
- def git_ref(myref, repo)
143
+ def git_ref(myref, repo, cookbook_name = nil)
127
144
  possible_refs = ['v' + myref, myref]
145
+ possible_refs += possible_refs.map { |ref| "#{cookbook_name}-#{ref}" } if cookbook_name
128
146
  possible_refs += possible_refs.map { |ref| ref.chomp('.0') } if myref[/\.0$/]
129
147
  existing_ref = possible_refs.find do |ref|
130
148
  begin
@@ -162,7 +180,7 @@ class PolicyChangelog
162
180
  output = ["\nChangelog for #{name}: #{data['current_version']}->#{data['target_version']}"]
163
181
  output << '=' * output.first.size
164
182
  output << if data['current_version']
165
- git_changelog(data['source_url'], data['current_version'], data['target_version'])
183
+ git_changelog(data['source_url'], data['current_version'], data['target_version'], name)
166
184
  else
167
185
  'Cookbook was not in the Policyfile.lock.json'
168
186
  end
@@ -214,7 +214,7 @@ RSpec.describe PolicyChangelog do
214
214
  allow(changelog).to receive(:git_ref).with('1.0.0', any_args).and_return('v1.0.0')
215
215
  allow(changelog).to receive(:git_ref).with('1.0.1', any_args).and_return('v1.0.1')
216
216
  allow(changelog).to receive(:correct_tags)
217
- allow(git_repo).to receive_message_chain(:log, :between)
217
+ allow(git_repo).to receive_message_chain(:log, :path, :between)
218
218
  .with('v1.0.0', 'v1.0.1')
219
219
  .and_return([git_commit])
220
220
 
@@ -238,11 +238,16 @@ RSpec.describe PolicyChangelog do
238
238
 
239
239
  context 'when tag invalid and able to correct' do
240
240
  it 'returns correct git tag' do
241
- allow(repo).to receive(:checkout).with(/v1.0/).and_raise(::Git::GitExecuteError)
242
241
  allow(repo).to receive(:checkout).with('1.0.0').and_raise(::Git::GitExecuteError)
243
- allow(repo).to receive(:checkout).with('1.0').and_return(true)
244
242
 
245
- expect(changelog.git_ref('1.0.0', repo)).to eq('1.0')
243
+ 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
+ tags.each do |valid_result|
245
+ allow(repo).to receive(:checkout).with(valid_result).and_return(true)
246
+ tags.reject { |v| v == valid_result }.each do |invalid_result|
247
+ allow(repo).to receive(:checkout).with(invalid_result).and_raise(::Git::GitExecuteError)
248
+ end
249
+ expect(changelog.git_ref('1.0.0', repo, 'cookbook_name')).to eq valid_result
250
+ end
246
251
  end
247
252
  end
248
253
 
@@ -308,7 +313,7 @@ RSpec.describe PolicyChangelog do
308
313
  }
309
314
 
310
315
  allow(changelog).to receive(:git_changelog)
311
- .with(instance_of(String), '4.0.0', '5.0.0')
316
+ .with(instance_of(String), '4.0.0', '5.0.0', 'users')
312
317
  .and_return('e1b971a Add test commit message')
313
318
 
314
319
  output = <<~COMMIT.chomp
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.7.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: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: pry
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -199,9 +185,10 @@ executables: []
199
185
  extensions: []
200
186
  extra_rdoc_files: []
201
187
  files:
188
+ - ".github/workflows/ci.yml"
189
+ - ".github/workflows/release.yml"
202
190
  - ".gitignore"
203
191
  - ".rubocop.yml"
204
- - ".travis.yml"
205
192
  - Gemfile
206
193
  - LICENSE.txt
207
194
  - README.md
@@ -211,6 +198,7 @@ files:
211
198
  - lib/knife/changelog/berksfile.rb
212
199
  - lib/knife/changelog/changelog.rb
213
200
  - lib/knife/changelog/git.rb
201
+ - lib/knife/changelog/git_submodule.rb
214
202
  - lib/knife/changelog/policyfile.rb
215
203
  - resources/Berksfile
216
204
  - resources/Berksfile.lock
@@ -243,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
231
  - !ruby/object:Gem::Version
244
232
  version: '0'
245
233
  requirements: []
246
- rubygems_version: 3.0.3
234
+ rubygems_version: 3.1.6
247
235
  signing_key:
248
236
  specification_version: 4
249
237
  summary: Facilitate access to cookbooks changelog
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- deploy:
5
- provider: rubygems
6
- api_key:
7
- secure: LAM8qxTQa6oxzKiQpWrqRlcE1czmGFj16NSj1FVgZYJLZIfXKdvSpth+DfuCk8mxG1tvDXa3ckfERrzexG3lYGNPGyZH2sjnyt900Evd3Bn8vhv0LXE7cEZb3x/uJ3RHRvKpEDnMsy4gqoVByDLWXWnI9Q/8B4AtzFeTVsTr48g=
8
- gem: knife-changelog
9
- on:
10
- tags: true
11
- repo: criteo/knife-changelog
12
- sudo: false # use docker based infra