diff --git a/lib/modulesync/pr/github.rb b/lib/modulesync/pr/github.rb index 2791c060..31254dce 100644 --- a/lib/modulesync/pr/github.rb +++ b/lib/modulesync/pr/github.rb @@ -22,36 +22,34 @@ def manage(namespace, module_name, options) $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? - pr = @api.create_pull_request(repo_path, - target_branch, - options[:branch], - options[:pr_title], - options[:message]) - $stdout.puts \ - "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]}" - end + return + end + + pull_requests = @api.pull_requests(repo_path, + :state => 'open', + :base => target_branch, + :head => head) + unless pull_requests.empty? + # Skip creating the PR if it exists already. + $stdout.puts "Skipped! #{pull_requests.length} PRs found for branch #{options[:branch]}" + return end - # PR labels can either be a list in the YAML file or they can pass in a comma - # separated list via the command line argument. pr_labels = ModuleSync::Util.parse_list(options[:pr_labels]) + pr = @api.create_pull_request(repo_path, + target_branch, + options[:branch], + options[:pr_title], + options[:message]) + $stdout.puts \ + "Submitted PR '#{options[:pr_title]}' to #{repo_path} " \ + "- merges #{options[:branch]} into #{target_branch}" # We only assign labels to the PR if we've discovered a list > 1. The labels MUST # already exist. We DO NOT create missing labels. return if pr_labels.empty? - if options[:noop] - puts "Using no-op. Would attach the following labels to the PR: #{pr_labels.join(', ')}" - else - $stdout.puts "Attaching the following labels to PR #{pr['number']}: #{pr_labels.join(', ')}" - @api.add_labels_to_an_issue(repo_path, pr['number'], pr_labels) - end + $stdout.puts "Attaching the following labels to PR #{pr['number']}: #{pr_labels.join(', ')}" + @api.add_labels_to_an_issue(repo_path, pr['number'], pr_labels) end end end diff --git a/lib/modulesync/pr/gitlab.rb b/lib/modulesync/pr/gitlab.rb index 4a7b067c..514e4255 100644 --- a/lib/modulesync/pr/gitlab.rb +++ b/lib/modulesync/pr/gitlab.rb @@ -15,7 +15,6 @@ def initialize(token, endpoint) def manage(namespace, module_name, options) repo_path = File.join(namespace, module_name) - head = "#{namespace}:#{options[:branch]}" target_branch = options[:pr_target_branch] || 'master' @@ -23,27 +22,31 @@ def manage(namespace, module_name, options) $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', - :source_branch => head, - :target_branch => target_branch) - if merge_requests.empty? - mr_labels = ModuleSync::Util.parse_list(options[:pr_labels]) - mr = @api.create_merge_request(repo_path, options[:pr_title], - :source_branch => options[:branch], - :target_branch => target_branch, - :labels => mr_labels) - $stdout.puts \ - "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 - # Skip creating the MR if it exists already. - $stdout.puts "Skipped! #{merge_requests.length} MRs found for branch #{options[:branch]}" - end + return + end + + merge_requests = @api.merge_requests(repo_path, + :state => 'opened', + :source_branch => head, + :target_branch => target_branch) + unless merge_requests.empty? + # Skip creating the MR if it exists already. + $stdout.puts "Skipped! #{merge_requests.length} MRs found for branch #{options[:branch]}" + return end + + mr_labels = ModuleSync::Util.parse_list(options[:pr_labels]) + mr = @api.create_merge_request(repo_path, + options[:pr_title], + :source_branch => options[:branch], + :target_branch => target_branch, + :labels => mr_labels) + $stdout.puts \ + "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(', ')}" end end end