release_manager 0.4.0 → 0.5.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.
@@ -3,6 +3,7 @@ require 'uri'
3
3
 
4
4
  module ReleaseManager
5
5
  module Git
6
+ STATUSES = [:added, :deleted, :modified, :renamed, :copied, :ignored, :untracked, :typechange]
6
7
  module Utilities
7
8
 
8
9
  def repo
@@ -13,11 +14,10 @@ module ReleaseManager
13
14
  def fetch(remote_name = 'upstream')
14
15
  return unless remote_exists?(remote_name)
15
16
  remote = repo.remotes[remote_name]
17
+ options = {credentials: credentials.call(remote.url)}
16
18
  logger.info("Fetching remote #{remote_name} from #{remote.url}")
17
- remote.fetch({
18
- #progress: lambda { |output| puts output },
19
- credentials: credentials.call(remote.url)
20
- })
19
+ options[:certificate_check] = lambda { |valid, host| true } if ENV['GIT_SSL_NO_VERIFY']
20
+ remote.fetch(options)
21
21
  end
22
22
 
23
23
  def transports
@@ -110,12 +110,16 @@ module ReleaseManager
110
110
  # @param [String] name - the name of the branch to delete
111
111
  def delete_branch(name)
112
112
  repo.branches.delete(name)
113
+ !branch_exist?(name)
113
114
  end
114
115
 
115
116
  # @param [String] remote_name - the remote name to push the branch to
116
- def push_branch(remote_name, branch)
117
+ def push_branch(remote_name, branch, force = false)
117
118
  remote = find_or_create_remote(remote_name)
118
- refs = [repo.branches[branch].canonical_name]
119
+ b = repo.branches[branch]
120
+ raise InvalidBranchName.new("Branch #{branch} does not exist locally, cannot push") unless b
121
+ refs = [b.canonical_name]
122
+ refs = refs.map { |r| r.prepend('+') } if force
119
123
  logger.info("Pushing branch #{branch} to remote #{remote.url}")
120
124
  remote.push(refs, credentials: credentials)
121
125
  end
@@ -134,10 +138,28 @@ module ReleaseManager
134
138
  repo.head.name.sub(/^refs\/heads\//, '')
135
139
  end
136
140
 
137
- def checkout_branch(name)
138
- if current_branch != name
139
- logger.info("Checking out branch: #{name} for #{path}")
140
- repo.checkout(name)
141
+ # @param name [String] - the name of the branch
142
+ # @return [Boolean] returns true if the current branch is the name
143
+ def current_branch?(name)
144
+ current_branch != name
145
+ end
146
+
147
+ # @param name [String] - the name of the tag
148
+ # @param ref [String] - the ref oid the tag should point to
149
+ # @param message [String] - optional tag message
150
+ def create_local_tag(name, ref, message = nil)
151
+ message ||= name
152
+ logger.info("Creating tag #{name} which points to #{ref}")
153
+ repo.tags.create(name, ref, {:message => message} )
154
+ end
155
+
156
+ # @param name [String] - the name of the branch to checkout
157
+ # @return [Rugged::Branch] returns the rugged branch object
158
+ def checkout_branch(name, options = {})
159
+ if current_branch?(name)
160
+ logger.debug("Checking out branch: #{name} for #{path}")
161
+ repo.checkout(name, options)
162
+ logger.debug("Checked out branch: #{current_branch} for #{path}")
141
163
  else
142
164
  # already checked out
143
165
  logger.debug("Currently on branch #{name} for #{path}")
@@ -172,7 +194,7 @@ module ReleaseManager
172
194
  # @return [MatchData] MatchData if the remote name is a url
173
195
  # Is the name actually a url?
174
196
  def git_url?(name)
175
- /((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:\/\-~]+)(\.git)(\/)?/.match(name)
197
+ /([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|\/)([A-Za-z0-9\/]+)(\.git)?/.match(name)
176
198
  end
177
199
 
178
200
  # @return [String] - the author name found in the config
@@ -190,66 +212,128 @@ module ReleaseManager
190
212
  {:email=>author_email, :time=>Time.now, :name=>author_name}
191
213
  end
192
214
 
193
- # # @param [String] file - the path to the file you want to add
194
- # def add_file(file)
195
- # return unless File.exists?(file)
196
- # index = repo.index
197
- # file.slice!(repo.workdir)
198
- # index.add(:path => file, :oid => Rugged::Blob.from_workdir(repo, file), :mode => 0100644)
199
- # index.write
200
- # end
215
+ # @param pathspec Array[String] path specs as strings in an array
216
+ def add_all(pathspec = [])
217
+ index = repo.index
218
+ index.add_all
219
+ index.write
220
+ end
201
221
 
202
222
  # @param [String] file - the path to the file you want to add
203
223
  def add_file(file)
224
+ logger.debug("Adding file #{file}")
225
+ return add_all if file == '.'
226
+ index = repo.index
227
+ file.slice!(repo.workdir)
228
+ index.add(:path => file, :oid => Rugged::Blob.from_workdir(repo, file), :mode => 0100644)
229
+ end
230
+
231
+ # @param [String] file - the path to the patch file you want to apply
232
+ def apply_patch(file)
204
233
  # TODO: change this to rugged implementation
205
- `git --work-tree=#{path} --git-dir=#{repo.path} add #{file}`
234
+ logger.info("Applying patch #{file}")
235
+ Dir.chdir(path) do
236
+ output = `#{git_command} apply #{file} 2>&1`
237
+ end
238
+ raise PatchError.new(output) unless $?.success?
239
+ end
240
+
241
+ # [Rugged::Diff] a rugged diff object
242
+ # Not fully tested
243
+ def apply_diff(diff)
244
+ diff.deltas.each do |d|
245
+ case d.status
246
+ when :deleted
247
+ remove_file(d.new_file[:path])
248
+ File.delete(File.join(path, path))
249
+ when :added, :modified
250
+ add_file(d.new_file[:path])
251
+ when :renamed
252
+ remove_file(d.old_file[:path])
253
+ File.delete(File.join(path, path))
254
+ add_file(d.new_file[:path])
255
+ else
256
+ logger.warn("File has a status of #{d.status}")
257
+ end
258
+ end
259
+ end
260
+
261
+ def up2date?(src_ref, dst_ref)
262
+ create_diff(src_ref, dst_ref).deltas.count < 1
263
+ end
264
+
265
+ # @return [String] the git command with
266
+ def git_command
267
+ @git_command ||= "git --work-tree=#{path} --git-dir=#{repo.path}"
206
268
  end
207
269
 
208
270
  # @param [String] file - the path to the file you want to remove
209
271
  def remove_file(file)
272
+ logger.debug("Removing file #{file}")
210
273
  index = repo.index
211
274
  File.unlink(file)
212
275
  index.remove(file)
213
- index.write
214
276
  end
215
277
 
216
- # # @param [String] message - the message you want in the commit
217
- # def create_commit(message)
218
- # # get the index for this repository
219
- # logger.info repo.status { |file, status_data| puts "#{file} has status: #{status_data.inspect}" }
220
- #
221
- # index = repo.index
222
- # index.read_tree repo.head.target.tree unless repo.empty?
223
- # require 'pry'; binding.pry
224
- # #repo.lookup
225
- # tree_new = index.write_tree repo
226
- # oid = Rugged::Commit.create(repo,
227
- # author: author,
228
- # message: message,
229
- # committer: author,
230
- # parents: repo.empty? ? [] : [repo.head.target].compact,
231
- # tree: tree_new,
232
- # update_ref: 'HEAD')
233
- # logger.info("Created commit #{oid} with #{message}")
234
- # index.write
235
- # #repo.status { |file, status_data| puts "#{file} has status: #{status_data.inspect}" }
236
- # oid
237
- # end
278
+ def update_cli_index
279
+ `#{git_command} update-index --really-refresh`
280
+ end
238
281
 
239
282
  # @param [String] message - the message you want in the commit
240
- # TODO: change this to rugged implementation
241
283
  def create_commit(message)
242
- output = `git --work-tree=#{path} --git-dir=#{repo.path} commit --message '#{message}' 2>&1`
284
+ # get the index for this repository
285
+ repo.status { |file, status_data| logger.debug "#{file} has status: #{status_data.inspect}" }
286
+ index = repo.index
287
+ index.write
288
+ options = {}
289
+ options[:author] = author
290
+ options[:message] = message
291
+ options[:committer] = author
292
+ options[:parents] = repo.empty? ? [] : [repo.head.target_id].compact
293
+ options[:update_ref] = 'HEAD'
294
+ options[:tree] = index.write_tree
295
+ oid = Rugged::Commit.create(repo, options)
296
+ if oid
297
+ logger.info("Created commit #{message}")
298
+ repo.status { |file, status_data| logger.debug "#{file} has status: #{status_data.inspect}" }
299
+ else
300
+ logger.warn("Something went wrong with the commit")
301
+ end
302
+ update_cli_index # for some reason the command line doesn't refresh the index after committing.
303
+ oid
304
+ end
305
+
306
+ # @param [String] message - the message you want in the commit
307
+ # TODO: change this to rugged implementation
308
+ def cli_create_commit(message)
309
+ output = nil
310
+ Dir.chdir(path) do
311
+ output = `#{git_command} commit --message '#{message}' 2>&1`
312
+ end
243
313
  if $?.success?
244
314
  logger.info("Created commit #{message}")
245
315
  else
246
- logger.error output
316
+ if output =~ /nothing\sto\scommit/
317
+ logger.info("Nothing to commit")
318
+ else
319
+ logger.error output
320
+ end
321
+ return false
247
322
  end
248
323
  end
249
324
 
250
- # @return [String] the current branch name
251
- def current_branch
252
- repo.head.name.sub(/^refs\/heads\//, '')
325
+ # @param [String] branch_name - the branch name you want to update
326
+ # @param [String] target - the target branch you want to rebase against
327
+ # @param [String] remote - the remote name to rebase from, defaults to local
328
+ # TODO: change this to rugged implementation
329
+ def rebase_branch(branch_name, target, remote = nil)
330
+ src = [remote, target].compact.join('/') # produces upstream/master
331
+ Dir.chdir(path) do
332
+ checkout_branch(branch_name)
333
+ logger.info("Rebasing #{branch_name} with #{src}")
334
+ output = `#{git_command} rebase #{src} 2>&1`
335
+ raise GitError.new(output) unless $?.success?
336
+ end
253
337
  end
254
338
 
255
339
  def cherry_pick(commit)
@@ -258,6 +342,60 @@ module ReleaseManager
258
342
  logger.info("Cherry picking commit with id: #{commit}")
259
343
  end
260
344
 
345
+ # @param src [Rubbed::Object] - the rugged object to compare from
346
+ # @param dst [Rubbed::Object] - the rugged object to compare to
347
+ # @return [Array[String]] the changed files in the commit or all the commits in the diff between src and dst
348
+ def changed_files(src_ref, dst_ref)
349
+ src = repo.lookup(find_ref(src_ref))
350
+ src = src.kind_of?(Rugged::Tag::Annotation) ? src.target : src
351
+ dst = repo.lookup(find_ref(dst_ref))
352
+ dst.diff(src).deltas.map { |d| [d.old_file[:path], d.new_file[:path]] }.flatten.uniq
353
+ end
354
+
355
+ # @param oid [String] the oid of the file object
356
+ # @return [String] the contents of the file from the object
357
+ def get_content(oid)
358
+ return nil if oid =~ /0000000000000000000000000000000000000000/
359
+ obj = repo.read(oid)
360
+ obj.data
361
+ end
362
+
363
+ # @param src [Rugged::Object] - the rugged object or string to compare from
364
+ # @param dst [Rugged::Object] - the rugged object or string to compare to
365
+ # @return Array[Hash] the changed files in the commit or all the commits in the diff between src and dst
366
+ # with status, old_path, new_path, and content
367
+ # status can be one of: :added, :deleted, :modified, :renamed, :copied, :ignored, :untracked, :typechange
368
+ def create_diff_obj(src, dst)
369
+ diff = create_diff(src, dst)
370
+ diff.deltas.map do |d|
371
+ { old_path: d.old_file[:path], status: d.status,
372
+ new_path: d.new_file[:path], content: get_content(d.new_file[:oid])
373
+ }
374
+ end
375
+ end
376
+
377
+ # @param src_ref [Rugged::Object] - the rugged object or string to compare from
378
+ # @param dst_ref [Rugged::Object] - the rugged object or string to compare to
379
+ # @return [Rugged::Diff] a rugged diff object between src and dst
380
+ def create_diff(src_ref, dst_ref)
381
+ logger.debug("Creating a diff between #{dst_ref} and #{src_ref}")
382
+ src = repo.lookup(find_ref(src_ref))
383
+ src = src.kind_of?(Rugged::Tag::Annotation) ? src.target : src
384
+ dst = repo.lookup(find_ref(dst_ref))
385
+ dst = dst.kind_of?(Rugged::Tag::Annotation) ? dst.target : dst
386
+ dst.diff(src)
387
+ end
388
+
389
+ # @param sha_or_ref [String] - the name or sha of the ref
390
+ # @return [String] the oid of the sha or ref
391
+ def find_ref(sha_or_ref)
392
+ case sha_or_ref
393
+ when Rugged::Object
394
+ sha_or_ref.oid
395
+ else
396
+ repo.rev_parse_oid(sha_or_ref)
397
+ end
398
+ end
261
399
  end
262
400
  end
263
401
  end
@@ -41,12 +41,16 @@ class ModuleDeployer
41
41
  @puppetfile ||= Puppetfile.new(puppetfile_path)
42
42
  end
43
43
 
44
+ def remote_deploy?
45
+ options[:remote]
46
+ end
47
+
44
48
  # @param [PuppetModule] puppet_module - the puppet module to check for existance
45
49
  # raises
46
50
  def add_module(puppet_module)
47
51
  unless puppetfile.mod_exists?(puppet_module.name)
48
- answer = ask("The #{puppet_module.name} module does not exist, do you want to add it? (y/n): ", String) { |q| q =~ /y|n/i }.downcase
49
- if answer == 'y'
52
+ answer = ask("The #{puppet_module.name} module does not exist, do you want to add it? (y/n): ", String) { |q| q =~ /y|n/i }.downcase unless options[:auto]
53
+ if answer == 'y' or options[:auto]
50
54
  puppetfile.add_module(puppet_module.name, git: puppet_module.repo, tag: "v#{puppet_module.version}") unless options[:dry_run]
51
55
  end
52
56
  end
@@ -56,22 +60,20 @@ class ModuleDeployer
56
60
  begin
57
61
  check_requirements
58
62
  logger.info "Deploying module #{puppet_module.name} with version: #{latest_version}"
63
+ add_module(puppet_module)
59
64
  if options[:dry_run]
60
- add_module(puppet_module)
61
65
  puts "Would have updated module #{puppet_module.name} in Puppetfile to version: #{latest_version}".green
62
66
  puts "Would have committed with message: bump #{puppet_module.name} to version: #{latest_version}".green if options[:commit]
63
67
  puts "Would have just pushed branch: #{puppetfile.current_branch} to remote: #{control_repo_remote}".green if options[:push]
64
68
  else
65
- add_module(puppet_module)
66
69
  puppetfile.write_version(puppet_module.name, latest_version)
67
70
  puppetfile.write_source(puppet_module.name, puppet_module.source)
68
71
  puppetfile.write_to_file
69
72
  logger.info "Updated module #{puppet_module.name} in Puppetfile to version: #{latest_version}"
70
73
  if options[:commit]
71
74
  puppetfile.commit("bump #{puppet_module.name} to version #{latest_version}")
72
- logger.info "Commited with message: bump #{puppet_module.name} to version #{latest_version}"
73
75
  end
74
- if options[:push]
76
+ if remote_deploy?
75
77
  puppetfile.push(control_repo_remote, puppetfile.current_branch)
76
78
  logger.info "Just pushed branch: #{puppetfile.current_branch} to remote: #{control_repo_remote}"
77
79
  end
@@ -1,19 +1,20 @@
1
1
  require 'json'
2
2
  require 'release_manager/errors'
3
3
  require 'release_manager/workflow_action'
4
+ require 'release_manager/vcs_manager'
4
5
  require 'release_manager/git/utilites'
5
6
  require 'rugged'
6
7
 
7
-
8
8
  class PuppetModule < WorkflowAction
9
9
  attr_reader :name, :metadata_file, :path, :version, :upstream
10
10
  attr_writer :version, :source
11
11
 
12
12
  include ReleaseManager::Git::Utilities
13
13
  include ReleaseManager::Logger
14
+ include ReleaseManager::VCSManager
14
15
 
15
16
  def initialize(mod_path, upstream = nil)
16
- raise ModNotFoundException if mod_path.nil?
17
+ raise ModNotFoundException.new("#{mod_path} is not a valid puppet module path") if mod_path.nil?
17
18
  @path = mod_path
18
19
  @upstream = upstream
19
20
  @metadata_file = File.join(mod_path, 'metadata.json')
@@ -40,21 +41,23 @@ class PuppetModule < WorkflowAction
40
41
  # @returns [Hash] the metadata object as a ruby hash
41
42
  def metadata
42
43
  unless @metadata
43
- raise ModNotFoundException unless File.exists?(metadata_file)
44
+ raise ModNotFoundException.new("#{path} does not contain a metadata file") unless File.exists?(metadata_file)
44
45
  @metadata ||= JSON.parse(File.read(metadata_file))
45
46
  end
46
47
  @metadata
47
48
  end
48
49
 
50
+ def already_latest?
51
+ return false unless latest_tag
52
+ up2date?(latest_tag, src_branch)
53
+ end
54
+
49
55
  def add_upstream_remote
50
- if upstream != source
51
- `#{git_command} remote rm upstream`
52
- end
53
- `#{git_command} remote add upstream #{source}`
56
+ add_remote(source,'upstream',true )
54
57
  end
55
58
 
56
59
  def git_upstream_url
57
- `#{git_command} config --get remote.upstream.url`.chomp
60
+ repo.remotes['upstream'].url if remote_exists?('upstream')
58
61
  end
59
62
 
60
63
  def git_upstream_set?
@@ -62,7 +65,7 @@ class PuppetModule < WorkflowAction
62
65
  end
63
66
 
64
67
  def tags
65
- `#{git_command} tag`.split("\n").map{|v| pad_version_string(v)}
68
+ repo.tags.map{|v| pad_version_string(v.name)}
66
69
  end
67
70
 
68
71
  def source=(s)
@@ -82,7 +85,6 @@ class PuppetModule < WorkflowAction
82
85
  end
83
86
 
84
87
  def latest_tag
85
- Gem::Version.new('0.0.12') >= Gem::Version.new('0.0.2')
86
88
  v = tags.sort do |a,b|
87
89
  Gem::Version.new(a.tr('v', '')) <=> Gem::Version.new(b.tr('v', ''))
88
90
  end
@@ -103,10 +105,20 @@ class PuppetModule < WorkflowAction
103
105
  metadata['version']
104
106
  end
105
107
 
106
- def tag_module
107
- `git --git-dir=#{path}/.git tag -m 'v#{version}' v#{version}`
108
+ # @param remote [Boolean] - create the tag remotely using the remote VCS
109
+ # @param id [String] - the commit id to tag to
110
+ def tag_module(remote = false, id = nil)
111
+ id ||= repo.head.target_id
112
+ if remote
113
+ # TODO add release_notes as the last argument, currently nil
114
+ # where we get the latest from the changelog
115
+ create_tag(source, "v#{version}", id, "v#{version}", nil)
116
+ else
117
+ create_local_tag("v#{version}", id)
118
+ end
108
119
  end
109
120
 
121
+ # Updates the version in memory
110
122
  def bump_patch_version
111
123
  return unless version
112
124
  pieces = version.split('.')
@@ -115,6 +127,7 @@ class PuppetModule < WorkflowAction
115
127
  metadata['version'] = pieces.join('.')
116
128
  end
117
129
 
130
+ # Updates the version in memory
118
131
  def bump_minor_version
119
132
  return unless version
120
133
  pieces = version.split('.')
@@ -124,6 +137,7 @@ class PuppetModule < WorkflowAction
124
137
  metadata['version'] = pieces.join('.')
125
138
  end
126
139
 
140
+ # Updates the version in memory
127
141
  def bump_major_version
128
142
  return unless version
129
143
  pieces = version.split('.')
@@ -139,16 +153,7 @@ class PuppetModule < WorkflowAction
139
153
  end
140
154
 
141
155
  def r10k_module?
142
- name =~ /r10k_control/i
143
- end
144
-
145
- def branch_exists?(name)
146
- `#{git_command} branch |grep '#{name}$'`
147
- $?.success?
148
- end
149
-
150
- def git_command
151
- @git_command ||= "git --work-tree=#{path} --git-dir=#{path}/.git"
156
+ mod_name =~ /r10k[-_]?control/i
152
157
  end
153
158
 
154
159
  def upstream
@@ -157,18 +162,11 @@ class PuppetModule < WorkflowAction
157
162
 
158
163
  # ensures the dev branch has been created and is up to date
159
164
  def create_dev_branch
160
- `#{git_command} fetch upstream`
161
- raise GitError unless $?.success?
162
- #puts "#{git_command} checkout -b #{src_branch} upstream/#{src_branch}"
163
- `#{git_command} checkout -b #{src_branch} upstream/#{src_branch}` unless branch_exists?(src_branch)
164
- raise GitError unless $?.success?
165
+ fetch('upstream')
166
+ create_branch(src_branch, "upstream/#{src_branch}")
165
167
  # ensure we have updated our local branch
166
- #puts "#{git_command} checkout #{src_branch}"
167
- `#{git_command} checkout #{src_branch}`
168
- raise GitError unless $?.success?
169
- #puts "#{git_command} rebase upstream/#{src_branch}"
170
- `#{git_command} rebase upstream/#{src_branch}`
171
- raise GitError unless $?.success?
168
+ checkout_branch(src_branch)
169
+ rebase_branch(src_branch, src_branch, 'upstream')
172
170
  end
173
171
 
174
172
  # @returns [String] - the source branch to push to
@@ -183,17 +181,48 @@ class PuppetModule < WorkflowAction
183
181
  end
184
182
 
185
183
  # @return [String] the oid of the commit that was created
186
- def commit_metadata
187
- to_metadata_file
188
- add_file(metadata_file)
189
- create_commit("[ReleaseManager] - bump version to #{version}")
184
+ # @param remote [Boolean] if true creates the commit on the remote repo
185
+ def commit_metadata(remote = false)
186
+ message = "[ReleaseManager] - bump version to #{version}"
187
+ if remote
188
+ actions = [{
189
+ action: 'update',
190
+ file_path: metadata_file.split(repo.workdir).last,
191
+ content: JSON.pretty_generate(metadata)
192
+ }]
193
+ obj = vcs_create_commit(source, src_branch, message, actions)
194
+ obj.id if obj
195
+ else
196
+ to_metadata_file
197
+ add_file(metadata_file)
198
+ create_commit(message)
199
+ end
190
200
  end
191
201
 
192
202
  # @return [String] the oid of the commit that was created
193
- def commit_metadata_source
194
- to_metadata_file
195
- add_file(metadata_file)
196
- create_commit("[ReleaseManager] - change source to #{source}")
203
+ def commit_metadata_source(remote = false)
204
+ message = "[ReleaseManager] - change source to #{source}"
205
+ if remote
206
+ actions = [{
207
+ action: 'update',
208
+ file_path: metadata_file.split(repo.workdir).last,
209
+ content: JSON.pretty_generate(metadata)
210
+ }]
211
+ obj = vcs_create_commit(source, src_branch, message, actions)
212
+ obj.id if obj
213
+ else
214
+ to_metadata_file
215
+ add_file(metadata_file)
216
+ create_commit(message)
217
+ end
218
+ end
219
+
220
+ def tag_exists?(tag, remote = false)
221
+ if remote
222
+ remote_tag_exists?(source, tag)
223
+ else
224
+ latest_tag == tag
225
+ end
197
226
  end
198
227
 
199
228
  def to_metadata_file
@@ -8,6 +8,12 @@ class Puppetfile
8
8
  attr_accessor :modules, :puppetfile, :data, :base_path, :puppetmodule
9
9
  BUMP_TYPES = %w{patch minor major}
10
10
 
11
+ include ReleaseManager::Git::Utilities
12
+ include ReleaseManager::Logger
13
+ include ReleaseManager::VCSManager
14
+
15
+ alias_method :path, :base_path
16
+
11
17
  # @param [String] puppetfile - the path to the puppetfile
12
18
  def initialize(puppetfile = 'Puppetfile')
13
19
  @puppetfile = puppetfile
@@ -22,17 +28,21 @@ class Puppetfile
22
28
  @base_path ||= File.dirname(puppetfile)
23
29
  end
24
30
 
25
- def git_command
26
- "git --work-tree=#{base_path} --git-dir=#{base_path}/.git"
27
- end
28
-
29
- def commit(message)
30
- puts `#{git_command} add #{puppetfile}`
31
- puts `#{git_command} commit -n -m "[ReleaseManager] - #{message}"`
32
- end
33
-
34
- def current_branch
35
- `#{git_command} rev-parse --abbrev-ref HEAD`
31
+ def commit(message, remote = false)
32
+ message = "[ReleaseManager] - #{message}"
33
+ if remote
34
+ actions = [{
35
+ action: 'update',
36
+ file_path: puppetfile.split(repo.workdir).last,
37
+ content: to_s
38
+ }]
39
+ obj = vcs_create_commit(source, 'master', message, actions)
40
+ obj.id if obj
41
+ else
42
+ write_to_file
43
+ add_file(puppetfile)
44
+ create_commit(message)
45
+ end
36
46
  end
37
47
 
38
48
  def add_module(name, metadata)
@@ -40,8 +50,8 @@ class Puppetfile
40
50
  end
41
51
 
42
52
  def push(remote, branch, force = false)
43
- opts = force ? '-f' : ''
44
- `#{git_command} push #{remote} #{branch} #{opts}`
53
+ push_branch(remote, branch, force)
54
+ push_tags(remote)
45
55
  end
46
56
 
47
57
  def data