Skip to content

Commit

Permalink
Avoid element access on nil value
Browse files Browse the repository at this point in the history
Fixes #187
  • Loading branch information
bittner committed Aug 10, 2020
1 parent 41d5def commit d75e971
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 5 additions & 2 deletions lib/modulesync/pr/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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]}"
Expand Down
7 changes: 5 additions & 2 deletions lib/modulesync/pr/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down

0 comments on commit d75e971

Please sign in to comment.