Sha256: 55991d2486d2678743a39e2eb590de6c686bd2de15f169889faa4418ca73c87d

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'gitlab'
require 'modulesync/util'

module ModuleSync
  module PR
    # GitLab creates and manages merge requests on gitlab.com or private GitLab
    # installations.
    class GitLab
      def initialize(token, endpoint)
        @api = Gitlab::Client.new(
          :endpoint => endpoint,
          :private_token => token
        )
      end

      def manage(namespace, module_name, options)
        repo_path = File.join(namespace, module_name)

        head = "#{namespace}:#{options[:branch]}"
        merge_requests = @api.merge_requests(repo_path,
                                             :state => 'opened',
                                             :source_branch => head,
                                             :target_branch => 'master')
        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 => 'master',
                                         :labels => mr_labels)
          $stdout.puts "Submitted MR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into master"
          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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
modulesync-1.2.0 lib/modulesync/pr/gitlab.rb