modulesync 0.6.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,36 +1,40 @@
1
+ require 'modulesync'
2
+
1
3
  module ModuleSync
2
- module Hook
3
- include Constants
4
+ class Hook
5
+ attr_reader :hook_file, :namespace, :branch, :args
6
+
7
+ def initialize(hook_file, options = [])
8
+ @hook_file = hook_file
9
+ @namespace = options['namespace']
10
+ @branch = options['branch']
11
+ @args = options['hook_args']
12
+ end
4
13
 
5
- def self.activate(args)
6
- repo = args[:configs]
7
- hook_args = ''
8
- hook_args <<= " -n #{args[:namespace]}" if args[:namespace]
9
- hook_args <<= " -b #{args[:branch]}" if args[:branch]
10
- hook = <<EOF
14
+ def content(arguments)
15
+ <<-EOF
11
16
  #!/usr/bin/env bash
12
17
 
13
18
  current_branch=\`git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,'\`
14
19
  git_dir=\`git rev-parse --show-toplevel\`
15
20
  message=\`git log -1 --format=%B\`
16
- msync -m "\$message"#{hook_args}
21
+ msync -m "\$message" #{arguments}
17
22
  EOF
18
- File.open("#{repo}/#{HOOK_FILE}", 'w') do |file|
19
- file.write(hook)
20
- end
21
23
  end
22
24
 
23
- def self.deactivate(repo)
24
- hook_path = "#{repo}/#{HOOK_FILE}"
25
- File.delete(hook_path) if File.exists?(hook_path)
26
- end
25
+ def activate
26
+ hook_args = []
27
+ hook_args << "-n #{namespace}" if namespace
28
+ hook_args << "-b #{branch}" if branch
29
+ hook_args << args if args
27
30
 
28
- def self.hook(command, args)
29
- if (command == 'activate')
30
- activate(args)
31
- else
32
- deactivate(args[:configs])
31
+ File.open(hook_file, 'w') do |file|
32
+ file.write(content(hook_args.join(' ')))
33
33
  end
34
34
  end
35
+
36
+ def deactivate
37
+ File.delete(hook_file) if File.exist?(hook_file)
38
+ end
35
39
  end
36
40
  end
@@ -3,9 +3,8 @@ require 'find'
3
3
 
4
4
  module ModuleSync
5
5
  module Renderer
6
-
7
6
  class ForgeModuleFile
8
- def initialize(configs= {})
7
+ def initialize(configs = {})
9
8
  @configs = configs
10
9
  end
11
10
  end
@@ -18,24 +17,19 @@ module ModuleSync
18
17
  end
19
18
 
20
19
  def self.remove(file)
21
- if File.exists?(file)
22
- File.delete(file)
23
- end
20
+ File.delete(file) if File.exist?(file)
24
21
  end
25
22
 
26
- def self.render(template, configs = {})
27
- ForgeModuleFile.new(configs).render()
23
+ def self.render(_template, configs = {})
24
+ ForgeModuleFile.new(configs).render
28
25
  end
29
26
 
30
27
  def self.sync(template, to_file)
31
28
  path = to_file.rpartition('/').first
32
- if(! path.empty?)
33
- FileUtils.mkdir_p(path)
34
- end
29
+ FileUtils.mkdir_p(path) unless path.empty?
35
30
  File.open(to_file, 'w') do |file|
36
31
  file.write(template)
37
32
  end
38
33
  end
39
-
40
34
  end
41
35
  end
@@ -0,0 +1,41 @@
1
+
2
+ module ModuleSync
3
+ # Encapsulate a configs for a module, providing easy access to its parts
4
+ class Settings
5
+ attr_reader :global_defaults, :defaults, :module_defaults, :module_configs, :additional_settings
6
+
7
+ def initialize(global_defaults, defaults, module_defaults, module_configs, additional_settings)
8
+ @global_defaults = global_defaults
9
+ @defaults = defaults
10
+ @module_defaults = module_defaults
11
+ @module_configs = module_configs
12
+ @additional_settings = additional_settings
13
+ end
14
+
15
+ def build_file_configs(filename)
16
+ global_defaults.merge(defaults[filename] || {}).merge(module_defaults).merge(module_configs[filename] || {}).merge(additional_settings)
17
+ end
18
+
19
+ def managed?(filename)
20
+ Pathname.new(filename).ascend do |v|
21
+ configs = build_file_configs(v.to_s)
22
+ return false if configs['unmanaged']
23
+ end
24
+ true
25
+ end
26
+
27
+ # given a list of existing files in the repo, return everything that we might want to act on
28
+ def managed_files(file_list)
29
+ (file_list | defaults.keys | module_configs.keys).select do |f|
30
+ (f != ModuleSync::GLOBAL_DEFAULTS_KEY) && managed?(f)
31
+ end
32
+ end
33
+
34
+ # returns a list of files that should not be touched
35
+ def unmanaged_files(file_list)
36
+ (file_list | defaults.keys | module_configs.keys).select do |f|
37
+ (f != ModuleSync::GLOBAL_DEFAULTS_KEY) && !managed?(f)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -2,6 +2,9 @@ require 'yaml'
2
2
 
3
3
  module ModuleSync
4
4
  module Util
5
+ def self.symbolize_keys(hash)
6
+ hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
7
+ end
5
8
 
6
9
  def self.parse_config(config_file)
7
10
  if File.exist?(config_file)
@@ -13,12 +16,3 @@ module ModuleSync
13
16
  end
14
17
  end
15
18
  end
16
-
17
- class Hash
18
- #take keys of hash and transform those to a symbols
19
- def self.transform_keys_to_symbols(value)
20
- return value if not value.is_a?(Hash)
21
- hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = Hash.transform_keys_to_symbols(v); memo}
22
- return hash
23
- end
24
- end
@@ -4,23 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'modulesync'
7
- spec.version = '0.6.1'
8
- spec.authors = ['Colleen Murphy']
9
- spec.email = ['colleen@puppetlabs.com']
10
- spec.summary = %q{Puppet Module Synchronizer}
11
- spec.description = %q{Utility to synchronize common files across puppet modules in Github.}
12
- spec.homepage = "http://github.com/puppetlabs/modulesync"
13
- spec.license = "Apache 2"
7
+ spec.version = '0.7.2'
8
+ spec.authors = ['Vox Pupuli']
9
+ spec.email = ['voxpupuli@groups.io']
10
+ spec.summary = 'Puppet Module Synchronizer'
11
+ spec.description = 'Utility to synchronize common files across puppet modules in Github.'
12
+ spec.homepage = 'http://github.com/voxpupuli/modulesync'
13
+ spec.license = 'Apache-2.0'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.6"
21
- spec.add_development_dependency "rake"
22
- spec.add_development_dependency "aruba"
20
+ spec.add_development_dependency 'aruba'
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rubocop'
23
25
 
24
26
  spec.add_runtime_dependency 'git', '~>1.2'
25
27
  spec.add_runtime_dependency 'puppet-blacksmith', '~>3.0'
28
+ spec.add_runtime_dependency 'thor'
26
29
  end
@@ -0,0 +1 @@
1
+ require 'modulesync'
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe ModuleSync::Settings do
4
+ subject do
5
+ ModuleSync::Settings.new(
6
+ {},
7
+ {},
8
+ {},
9
+ { 'Rakefile' => { 'unmanaged' => true },
10
+ :global => { 'global' => 'value' },
11
+ 'Gemfile' => { 'key' => 'value' }, },
12
+ {}
13
+ )
14
+ end
15
+
16
+ it { is_expected.not_to eq nil }
17
+ it { expect(subject.managed?('Rakefile')).to eq false }
18
+ it { expect(subject.managed?('Rakefile/foo')).to eq false }
19
+ it { expect(subject.managed?('Gemfile')).to eq true }
20
+ it { expect(subject.managed?('Gemfile/foo')).to eq true }
21
+ it { expect(subject.managed_files([])).to eq ['Gemfile'] }
22
+ it { expect(subject.managed_files(%w(Rakefile Gemfile other_file))).to eq %w(Gemfile other_file) }
23
+ it { expect(subject.unmanaged_files([])).to eq ['Rakefile'] }
24
+ it { expect(subject.unmanaged_files(%w(Rakefile Gemfile other_file))).to eq ['Rakefile'] }
25
+ end
metadata CHANGED
@@ -1,106 +1,140 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulesync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
5
- prerelease:
4
+ version: 0.7.2
6
5
  platform: ruby
7
6
  authors:
8
- - Colleen Murphy
7
+ - Vox Pupuli
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aruba
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ~>
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
33
  version: '1.6'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ~>
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
40
  version: '1.6'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  - !ruby/object:Gem::Dependency
47
- name: aruba
56
+ name: rspec
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
60
81
  - !ruby/object:Gem::Version
61
82
  version: '0'
62
83
  - !ruby/object:Gem::Dependency
63
84
  name: git
64
85
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
86
  requirements:
67
- - - ~>
87
+ - - "~>"
68
88
  - !ruby/object:Gem::Version
69
89
  version: '1.2'
70
90
  type: :runtime
71
91
  prerelease: false
72
92
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
93
  requirements:
75
- - - ~>
94
+ - - "~>"
76
95
  - !ruby/object:Gem::Version
77
96
  version: '1.2'
78
97
  - !ruby/object:Gem::Dependency
79
98
  name: puppet-blacksmith
80
99
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
100
  requirements:
83
- - - ~>
101
+ - - "~>"
84
102
  - !ruby/object:Gem::Version
85
103
  version: '3.0'
86
104
  type: :runtime
87
105
  prerelease: false
88
106
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
107
  requirements:
91
- - - ~>
108
+ - - "~>"
92
109
  - !ruby/object:Gem::Version
93
110
  version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
94
125
  description: Utility to synchronize common files across puppet modules in Github.
95
126
  email:
96
- - colleen@puppetlabs.com
127
+ - voxpupuli@groups.io
97
128
  executables:
98
129
  - msync
99
130
  extensions: []
100
131
  extra_rdoc_files: []
101
132
  files:
102
- - .gitignore
103
- - .travis.yml
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".rubocop_todo.yml"
137
+ - ".travis.yml"
104
138
  - CHANGELOG.md
105
139
  - Gemfile
106
140
  - LICENSE
@@ -108,6 +142,9 @@ files:
108
142
  - Rakefile
109
143
  - bin/msync
110
144
  - contrib/openstack-commit-msg-hook.sh
145
+ - features/cli.feature
146
+ - features/hook.feature
147
+ - features/step_definitions/git_steps.rb
111
148
  - features/support/env.rb
112
149
  - features/update.feature
113
150
  - lib/modulesync.rb
@@ -116,33 +153,40 @@ files:
116
153
  - lib/modulesync/git.rb
117
154
  - lib/modulesync/hook.rb
118
155
  - lib/modulesync/renderer.rb
156
+ - lib/modulesync/settings.rb
119
157
  - lib/modulesync/util.rb
120
158
  - modulesync.gemspec
121
- homepage: http://github.com/puppetlabs/modulesync
159
+ - spec/spec_helper.rb
160
+ - spec/unit/modulesync/settings_spec.rb
161
+ homepage: http://github.com/voxpupuli/modulesync
122
162
  licenses:
123
- - Apache 2
163
+ - Apache-2.0
164
+ metadata: {}
124
165
  post_install_message:
125
166
  rdoc_options: []
126
167
  require_paths:
127
168
  - lib
128
169
  required_ruby_version: !ruby/object:Gem::Requirement
129
- none: false
130
170
  requirements:
131
- - - ! '>='
171
+ - - ">="
132
172
  - !ruby/object:Gem::Version
133
173
  version: '0'
134
174
  required_rubygems_version: !ruby/object:Gem::Requirement
135
- none: false
136
175
  requirements:
137
- - - ! '>='
176
+ - - ">="
138
177
  - !ruby/object:Gem::Version
139
178
  version: '0'
140
179
  requirements: []
141
180
  rubyforge_project:
142
- rubygems_version: 1.8.23
181
+ rubygems_version: 2.4.5
143
182
  signing_key:
144
- specification_version: 3
183
+ specification_version: 4
145
184
  summary: Puppet Module Synchronizer
146
185
  test_files:
186
+ - features/cli.feature
187
+ - features/hook.feature
188
+ - features/step_definitions/git_steps.rb
147
189
  - features/support/env.rb
148
190
  - features/update.feature
191
+ - spec/spec_helper.rb
192
+ - spec/unit/modulesync/settings_spec.rb