Skip to content

Commit

Permalink
Support for setting 'changeset' for git/hg modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pegasd committed Oct 5, 2017
1 parent 840e99b commit ed9c7b7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Support for setting `changeset` for git/hg modules.

### Changed
- Color of `matched` output status changed to bright white so that other statuses stand out better.

Expand Down
23 changes: 11 additions & 12 deletions lib/puppetfile_editor/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ def initialize(title, args = nil)
def set(param, newvalue, force = false)
case @type
when :hg, :git
if !force && (@params.key?(:branch) || @params.key?(:ref))
if !force && !([:branch, :ref, :changeset] & @params.keys).empty?
set_message("kept at (#{full_version})", :wont_upgrade)
elsif !%w[branch tag ref].include? param
set_message("only 'branch', 'tag', and 'ref' are supported for '#{@type}' modules.", :unsupported)
elsif !%w[branch tag ref changeset].include? param
set_message("only 'branch', 'tag', 'ref', and 'changeset' are supported for '#{@type}' modules.", :unsupported)
else
set_message("updated (#{full_version} to #{param}: #{newvalue}", :updated)
@params.delete :branch
@params.delete :tag
@params.delete :ref
@params.delete :changeset
@params[param.to_sym] = newvalue
calculate_indent
end
Expand All @@ -63,7 +64,7 @@ def merge_with(mod, force = false)
case @type
when :hg, :git
new = mod.params.reject { |param, _| param.eql? @type }
if !force && new.keys == [:tag] && (!([:branch, :ref, :changeset] & @params.keys).empty?)
if !force && new.keys == [:tag] && !([:branch, :ref, :changeset] & @params.keys).empty?
set_message("kept at #{full_version}", :wont_upgrade)
return
end
Expand All @@ -78,7 +79,7 @@ def merge_with(mod, force = false)
calculate_indent
when :forge
unless force
if mod.params.nil? or mod.params.is_a? Symbol
if mod.params.nil? || mod.params.is_a?(Symbol)
set_message("won't upgrade to #{mod.full_version}", :wont_upgrade)
return
end
Expand All @@ -102,10 +103,10 @@ def dump
output.push "mod '#{full_title}'"
@params.each do |param_name, param_value|
value = if param_value == :latest
':latest'
else
"'#{param_value}'"
end
':latest'
else
"'#{param_value}'"
end
param = "#{param_name}:".ljust(@indent)
output.push " #{param} #{value}"
end
Expand Down Expand Up @@ -133,14 +134,12 @@ def full_version
when :forge
return @params[:version] if @params.key? :version
nil
else
nil
end
end

def set_message(message, status)
@message = message
@status = status
@status = status
end

private
Expand Down
51 changes: 39 additions & 12 deletions spec/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,54 @@
end

describe '#set' do

#
# Git
#

it 'updates tag of git module' do
m = described_class.new('apt', git: 'https://github.com/puppetlabs/puppetlabs-apt', tag: '4.1.0')
m.set('tag', '4.2.0')
expect(m.params[:tag]).to eq('4.2.0')
end

it 'does not update branched git module (without force)' do
m = described_class.new('apt', git: 'url', branch: 'special')
m.set('tag', '0.1.1')
expect(m.params[:tag]).to be_nil
expect(m.params[:branch]).to eq('special')
end

it 'overrides branch with tag for git module (with force)' do
m = described_class.new('apt', git: 'url', branch: 'special')
m.set('tag', '0.1.1', true)
expect(m.params[:tag]).to eq('0.1.1')
expect(m.params[:branch]).to be_nil
end

#
# Mercurial
#

it 'rewrites tag with branch for hg module' do
m = described_class.new('accounts', hg: 'https://hg.mycompany.net/puppet/accounts', tag: '0.10.0')
m.set('branch', 'default')
expect(m.params[:tag]).to be_nil
expect(m.params[:branch]).to eq('default')
end

it 'updates forge module version' do
m = described_class.new('KyleAnderson/consul', '2.1.0')
m.set('version', '2.2.0')
expect(m.params[:version]).to eq('2.2.0')
end

it 'does not update branched hg module (without force)' do
m = described_class.new('apt', hg: 'url', branch: 'special')
m.set('tag', '0.1.1')
expect(m.params[:tag]).to be_nil
expect(m.params[:branch]).to eq('special')
end

it 'does not update branched git module (without force)' do
m = described_class.new('apt', git: 'url', branch: 'special')
it 'does not update specific changeset of a hg module (without force)' do
m = described_class.new('apt', hg: 'url', changeset: '12345678')
m.set('tag', '0.1.1')
expect(m.params[:tag]).to be_nil
expect(m.params[:branch]).to eq('special')
expect(m.params[:changeset]).to eq('12345678')
end

it 'overrides branch with tag for hg module (with force)' do
Expand All @@ -75,11 +92,21 @@
expect(m.params[:branch]).to be_nil
end

it 'overrides branch with tag for git module (with force)' do
m = described_class.new('apt', git: 'url', branch: 'special')
it 'overrides changeset with tag for hg module (with force)' do
m = described_class.new('apt', hg: 'url', changeset: '12345678')
m.set('tag', '0.1.1', true)
expect(m.params[:tag]).to eq('0.1.1')
expect(m.params[:branch]).to be_nil
expect(m.params[:changeset]).to be_nil
end

#
# Forge
#

it 'updates forge module version' do
m = described_class.new('KyleAnderson/consul', '2.1.0')
m.set('version', '2.2.0')
expect(m.params[:version]).to eq('2.2.0')
end
end

Expand Down

0 comments on commit ed9c7b7

Please sign in to comment.