knife-changelog 1.4.2 → 1.5.0

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: cd73707c23a179823ac967479e0ec8de3780d759fb05689e229854281e33a0a8
4
- data.tar.gz: 80bc4745a9c0f39426a6f259d81a46ec13b17680a6601ed5cba2543fb01ed45a
3
+ metadata.gz: ac82fb7552ead5bf08e8d7340883adab40185d5098c60ab3944472b3d51555b8
4
+ data.tar.gz: 22f9713b7df19b7a332a1a275e3a69db6dfa0d9d59abd815d7728c22b6d7c006
5
5
  SHA512:
6
- metadata.gz: f86532a7c3005c3ec488fe090f66d7c779d148b9fed9eccd90a546bb9c465cc09e23df145618771b994171703576235494c81a4b207b4b6de027799b4bd897a1
7
- data.tar.gz: 0f12940e801842989f715b5b0b5be67a6abaaac1d01abfaf3808af42d750beaa7a726fd5d075871094ebda5f044eb6784dd57d68d12c818093130d6b03bb5ab9
6
+ metadata.gz: 64bed7f1436c1d8536d479673d92d7749e7a8e9d16c271f81bbeac380c24b1f305300ff77bd4e17f7698746b2545b7773897923c7cb27dd68f6266f50ae5888a
7
+ data.tar.gz: e7939f44aefd0b409a9e5d2a12f7bdf1cd4ad9671c6ec906b1a650f51aaddb3cd72985ec3f220a5b8f96f532ddd1735d3bf7c9948927ac3905fc2f6dfb8e97c3
@@ -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.2'
8
+ spec.version = '1.5.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'
@@ -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.2
4
+ version: 1.5.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-11-05 00:00:00.000000000 Z
11
+ date: 2021-07-12 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
@@ -243,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
230
  - !ruby/object:Gem::Version
244
231
  version: '0'
245
232
  requirements: []
246
- rubygems_version: 3.0.8
233
+ rubygems_version: 3.1.6
247
234
  signing_key:
248
235
  specification_version: 4
249
236
  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