Skip to content

Commit

Permalink
Cleanup: move config validation out of processing
Browse files Browse the repository at this point in the history
This commit moves configuration validation (--pr cannot be used without
--branch) into initialization. This catches the error early on, before
any actual work is done.

Signed-off-by: Manuel Hutter <manuel@vshn.ch>
  • Loading branch information
mhutter committed May 25, 2020
1 parent 9a0b374 commit a50a730
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,32 +132,25 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op
if options[:noop]
Git.update_noop(git_repo, options)
elsif !options[:offline]
if options[:pr]
manage_pr_or_mr(git_repo, files_to_manage, namespace, module_name, options)
else
Git.update(git_repo, files_to_manage, options)
end
end
end
pushed = Git.update(git_repo, files_to_manage, options)

def self.manage_pr_or_mr(git_repo, files_to_manage, namespace, module_name, options)
unless options[:branch]
$stderr.puts 'A branch must be specified with --branch to use --pr!'
return nil
if pushed && options[:pr]
@pr.manage(namespace, module_name, options)
end
end
# Git.update() returns a boolean: true if files were pushed, false if not.
pushed = Git.update(git_repo, files_to_manage, options)

# If there's nothing pushed, we're done
return nil unless pushed

@pr.manage(namespace, module_name, options)
end

def self.update(options)
options = config_defaults.merge(options)
defaults = Util.parse_config(File.join(options[:configs], CONF_FILE))
@pr = get_pr_manager if options[:pr]
if options[:pr]
unless options[:branch]
$stderr.puts 'A branch must be specified with --branch to use --pr!'
raise
end

@pr = get_pr_manager if options[:pr]
end

local_template_dir = File.join(options[:configs], MODULE_FILES_DIR)
local_files = find_template_files(local_template_dir)
Expand Down

0 comments on commit a50a730

Please sign in to comment.