lib/modulesync.rb in modulesync-1.2.0 vs lib/modulesync.rb in modulesync-1.3.0
- old
+ new
@@ -103,11 +103,15 @@
end
end
end
def self.manage_module(puppet_module, module_files, module_options, defaults, options)
- namespace, module_name = module_name(puppet_module, options[:namespace])
+ default_namespace = options[:namespace]
+ if module_options.is_a?(Hash) && module_options.key?(:namespace)
+ default_namespace = module_options[:namespace]
+ end
+ namespace, module_name = module_name(puppet_module, default_namespace)
git_repo = File.join(namespace, module_name)
unless options[:offline]
Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], module_options || {})
end
@@ -128,31 +132,40 @@
if options[:noop]
Git.update_noop(git_repo, options)
elsif !options[:offline]
pushed = Git.update(git_repo, files_to_manage, options)
- pushed && options[:pr] && @pr.manage(namespace, module_name, options)
+ pushed && options[:pr] && pr(module_options).manage(namespace, module_name, options)
end
end
+ def self.config_path(file, options)
+ return file if Pathname.new(file).absolute?
+ File.join(options[:configs], file)
+ end
+
+ def config_path(file, options)
+ self.class.config_path(file, options)
+ end
+
def self.update(options)
options = config_defaults.merge(options)
- defaults = Util.parse_config(File.join(options[:configs], CONF_FILE))
+ defaults = Util.parse_config(config_path(CONF_FILE, options))
if options[:pr]
unless options[:branch]
$stderr.puts 'A branch must be specified with --branch to use --pr!'
raise
end
@pr = create_pr_manager if options[:pr]
end
- local_template_dir = File.join(options[:configs], MODULE_FILES_DIR)
+ local_template_dir = config_path(MODULE_FILES_DIR, options)
local_files = find_template_files(local_template_dir)
module_files = relative_names(local_files, local_template_dir)
- managed_modules = self.managed_modules(File.join(options[:configs], options[:managed_modules_conf]),
+ managed_modules = self.managed_modules(config_path(options[:managed_modules_conf], options),
options[:filter],
options[:negative_filter])
errors = false
# managed_modules is either an array or a hash
@@ -167,21 +180,40 @@
end
end
exit 1 if errors && options[:fail_on_warnings]
end
+ def self.pr(module_options)
+ github_conf = module_options[:github]
+ gitlab_conf = module_options[:gitlab]
+
+ if !github_conf.nil?
+ base_url = github_conf[:base_url] || ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com')
+ require 'modulesync/pr/github'
+ ModuleSync::PR::GitHub.new(github_conf[:token], base_url)
+ elsif !gitlab_conf.nil?
+ base_url = gitlab_conf[:base_url] || ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4')
+ require 'modulesync/pr/gitlab'
+ ModuleSync::PR::GitLab.new(gitlab_conf[:token], base_url)
+ elsif @pr.nil?
+ $stderr.puts 'No GitHub or GitLab token specified for --pr!'
+ raise
+ else
+ @pr
+ end
+ end
+
def self.create_pr_manager
github_token = ENV.fetch('GITHUB_TOKEN', '')
gitlab_token = ENV.fetch('GITLAB_TOKEN', '')
if !github_token.empty?
require 'modulesync/pr/github'
ModuleSync::PR::GitHub.new(github_token, ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com'))
elsif !gitlab_token.empty?
- require 'modulesync/pr/github'
+ require 'modulesync/pr/gitlab'
ModuleSync::PR::GitLab.new(gitlab_token, ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4'))
else
- $stderr.puts 'Environment variables GITHUB_TOKEN or GITLAB_TOKEN must be set to use --pr!'
- raise
+ warn '--pr specified without environment variables GITHUB_TOKEN or GITLAB_TOKEN'
end
end
end