Class: ModuleSync::PR::GitLab
- Inherits:
-
Object
- Object
- ModuleSync::PR::GitLab
- Defined in:
- lib/modulesync/pr/gitlab.rb
Overview
GitLab creates and manages merge requests on gitlab.com or private GitLab installations.
Instance Method Summary collapse
-
#initialize(token, endpoint) ⇒ GitLab
constructor
A new instance of GitLab.
- #manage(namespace, module_name, options) ⇒ Object
Constructor Details
#initialize(token, endpoint) ⇒ GitLab
9 10 11 12 13 14 |
# File 'lib/modulesync/pr/gitlab.rb', line 9 def initialize(token, endpoint) @api = Gitlab::Client.new( :endpoint => endpoint, :private_token => token ) end |
Instance Method Details
#manage(namespace, module_name, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/modulesync/pr/gitlab.rb', line 16 def manage(namespace, module_name, ) repo_path = File.join(namespace, module_name) branch = [:remote_branch] || [:branch] head = "#{namespace}:#{branch}" target_branch = [:pr_target_branch] || 'master' if [:noop] $stdout.puts \ "Using no-op. Would submit MR '#{options[:pr_title]}' to #{repo_path} " \ "- merges #{branch} into #{target_branch}" 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 #{branch}" return end mr_labels = ModuleSync::Util.parse_list([:pr_labels]) mr = @api.create_merge_request(repo_path, [:pr_title], :source_branch => branch, :target_branch => target_branch, :labels => mr_labels) $stdout.puts \ "Submitted MR '#{options[:pr_title]}' to #{repo_path} " \ "- merges #{branch} into #{target_branch}" return if mr_labels.empty? $stdout.puts "Attached the following labels to MR #{mr.iid}: #{mr_labels.join(', ')}" end |