Sha256: 87122e56d6f8c75aa28340165bf249ac9849b31c8c706813a0c9e75cbedeced1

Contents?: true

Size: 685 Bytes

Versions: 4

Compression:

Stored size: 685 Bytes

Contents

require 'uri'

module GhCompare
  class Error < StandardError; end

  class CommitCompare
    attr_reader :remote_origin

    def initialize
      @remote_origin = get_remote_origin
    end

    def remote_url
      remote_url? ? remote_origin.gsub(/\.git$/, '') : ssh_to_url
    end

    def compare_url(from, to)
      remote_url + "/compare/#{from}...#{to}"
    end

    private

    def get_remote_origin
      `git config --get remote.origin.url`.strip
    end

    def remote_url?
      URI.parse(remote_origin).is_a?(URI::HTTP) rescue false
    end

    def ssh_to_url
      "https://github.com/#{remote_origin.gsub(/git@github.com:/, '').gsub(/\.git$/, '')}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gh_compare-0.1.3 lib/gh_compare.rb
gh_compare-0.1.2 lib/gh_compare.rb
gh_compare-0.1.1 lib/gh_compare.rb
gh_compare-0.1.0 lib/gh_compare.rb