From d75e9713aaddc1de55fc40d57259dc6858069289 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Mon, 10 Aug 2020 17:51:53 +0200 Subject: [PATCH] Avoid element access on nil value Fixes #187 --- lib/modulesync.rb | 11 ++++++++--- lib/modulesync/pr/github.rb | 7 +++++-- lib/modulesync/pr/gitlab.rb | 7 +++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index ec050557..d742a121 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -184,9 +184,14 @@ def self.update(options) exit 1 if errors && options[:fail_on_warnings] end - def self.pr(module_options = {}) - github_conf = module_options[:github] - gitlab_conf = module_options[:gitlab] + def self.pr(module_options) + if !module_options.nil? + github_conf = module_options[:github] + gitlab_conf = module_options[:gitlab] + else + github_conf = nil + gitlab_conf = nil + end if !github_conf.nil? base_url = github_conf[:base_url] || ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com') diff --git a/lib/modulesync/pr/github.rb b/lib/modulesync/pr/github.rb index 13606888..2791c060 100644 --- a/lib/modulesync/pr/github.rb +++ b/lib/modulesync/pr/github.rb @@ -19,7 +19,9 @@ def manage(namespace, module_name, options) target_branch = options[:pr_target_branch] || 'master' if options[:noop] - puts "Using no-op. Would submit PR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into #{target_branch}" + $stdout.puts \ + "Using no-op. Would submit PR '#{options[:pr_title]}' to #{repo_path} " \ + "- merges #{options[:branch]} into #{target_branch}" else pull_requests = @api.pull_requests(repo_path, :state => 'open', :base => target_branch, :head => head) if pull_requests.empty? @@ -29,7 +31,8 @@ def manage(namespace, module_name, options) options[:pr_title], options[:message]) $stdout.puts \ - "Submitted PR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into #{target_branch}" + "Submitted PR '#{options[:pr_title]}' to #{repo_path} "\ + "- merges #{options[:branch]} into #{target_branch}" else # Skip creating the PR if it exists already. $stdout.puts "Skipped! #{pull_requests.length} PRs found for branch #{options[:branch]}" diff --git a/lib/modulesync/pr/gitlab.rb b/lib/modulesync/pr/gitlab.rb index 0659bb2f..4a7b067c 100644 --- a/lib/modulesync/pr/gitlab.rb +++ b/lib/modulesync/pr/gitlab.rb @@ -20,7 +20,9 @@ def manage(namespace, module_name, options) target_branch = options[:pr_target_branch] || 'master' if options[:noop] - puts "Using no-op. Would submit MR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into #{target_branch}" + $stdout.puts \ + "Using no-op. Would submit MR '#{options[:pr_title]}' to #{repo_path} " \ + "- merges #{options[:branch]} into #{target_branch}" else merge_requests = @api.merge_requests(repo_path, :state => 'opened', @@ -33,7 +35,8 @@ def manage(namespace, module_name, options) :target_branch => target_branch, :labels => mr_labels) $stdout.puts \ - "Submitted MR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into #{target_branch}" + "Submitted MR '#{options[:pr_title]}' to #{repo_path} " \ + "- merges #{options[:branch]} into #{target_branch}" return if mr_labels.empty? $stdout.puts "Attached the following labels to MR #{mr.iid}: #{mr_labels.join(', ')}" else