Sha256: 3a309064bdc55c6eb27135c26c3cfdd5202f0eb58f768c8e7ba535a472c1bef1

Contents?: true

Size: 1.89 KB

Versions: 17

Compression:

Stored size: 1.89 KB

Contents

module GitReflow
  module GitServer
    autoload :Base,        'git_reflow/git_server/base'
    autoload :GitHub,      'git_reflow/git_server/git_hub'
    autoload :PullRequest, 'git_reflow/git_server/pull_request'

    extend self

    class ConnectionError < StandardError; end

    def connect(options = {})
      options ||= {}
      options[:provider] = 'GitHub' if "#{options[:provider]}".length <= 0
      begin
        provider_name = options[:provider]
        provider = provider_class_for(options.delete(:provider)).new(options)
        provider.authenticate(options.keep_if {|key, value| key == :silent })
        provider
      rescue ConnectionError => e
        GitReflow.say "Error connecting to #{provider_name}: #{e.message}", :error
      end
    end

    def connection
      return nil unless current_provider
      current_provider.connection
    end

    def current_provider
      provider = "#{GitReflow::Config.get('reflow.git-server', local: true)  || GitReflow::Config.get('reflow.git-server')}"
      if provider.length > 0
        begin
          provider_class_for(provider)
        rescue ConnectionError => e
          GitReflow.say e.message, :error
          nil
        end
      else
        GitReflow.say "Reflow hasn't been setup yet.  Run 'git reflow setup' to continue", :notice
        nil
      end
    end

    def can_connect_to?(provider)
      GitReflow::GitServer.const_defined?(provider)
    end

    def create_pull_request(options = {})
      raise "#{self.class.to_s}#create_pull_request method must be implemented"
    end

    def find_open_pull_request(options = {})
      raise "#{self.class.to_s}#find_open_pull_request method must be implemented"
    end

    private

    def provider_class_for(provider)
      raise ConnectionError, "GitServer not setup for \"#{provider}\"" unless self.can_connect_to?(provider)
      GitReflow::GitServer.const_get(provider)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
git_reflow-0.9.9 lib/git_reflow/git_server.rb
git_reflow-0.9.8 lib/git_reflow/git_server.rb
git_reflow-0.9.7 lib/git_reflow/git_server.rb
git_reflow-0.9.6 lib/git_reflow/git_server.rb
git_reflow-0.9.5 lib/git_reflow/git_server.rb
git_reflow-0.9.4 lib/git_reflow/git_server.rb
git_reflow-0.9.3 lib/git_reflow/git_server.rb
git_reflow-0.9.2 lib/git_reflow/git_server.rb
git_reflow-0.9.1 lib/git_reflow/git_server.rb
git_reflow-0.9.0 lib/git_reflow/git_server.rb
git_reflow-0.8.10 lib/git_reflow/git_server.rb
git_reflow-0.8.6 lib/git_reflow/git_server.rb
git_reflow-0.8.4 lib/git_reflow/git_server.rb
git_reflow-0.8.3 lib/git_reflow/git_server.rb
git_reflow-0.8.2 lib/git_reflow/git_server.rb
git_reflow-0.8.1 lib/git_reflow/git_server.rb
git_reflow-0.8.0 lib/git_reflow/git_server.rb