Sha256: 01f8dbc4892fd30ad73fb1c9abb06566e78e323b3be300dfa3e26cdfc9f4d900

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

require 'git-utils/command'

class Open < Command

  def parser
    OptionParser.new do |opts|
      opts.banner = "Usage: git open"
      opts.on_tail("-h", "--help", "this usage guide") do
        puts opts.to_s; exit 0
      end
    end
  end

  # Returns the URL for the repository page.
  def page_url
    if service == 'stash' && protocol == 'ssh'
      pattern = /(.*)@([^:]*):?([^\/]*)\/([^\/]*)\/(.*)\.git/
      replacement = 'https://\2/projects/\4/repos/\5/browse?at=' +
                    current_branch
    elsif service == 'stash' && protocol == 'http'
      pattern = /(.*)@([^:\/]*)(:?[^\/]*)\/(.*)scm\/([^\/]*)\/(.*)\.git/
      replacement = 'https://\2\3/\4projects/\5/repos/\6/browse?at=' +
                    current_branch
    elsif protocol == 'ssh'
      pattern = /(.*)@(.*):(.*)\.git/
      replacement = 'https://\2/\3/'
    elsif protocol == 'http'
      pattern = /https?\:\/\/(([^@]*)@)?(.*)\.git/
      replacement = 'https://\3/'
    end
    origin_url.sub(pattern, replacement)
  end

  # Returns a command appropriate for executing at the command line
  def cmd
    c = ["open #{page_url}"]
    c << argument_string(unknown_options) unless unknown_options.empty?
    c.join("\n")
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
git-utils-0.5.4 lib/git-utils/open.rb
git-utils-0.5.3 lib/git-utils/open.rb
git-utils-0.5.2 lib/git-utils/open.rb
git-utils-0.5.1 lib/git-utils/open.rb
git-utils-0.5.0 lib/git-utils/open.rb
git-utils-0.1.2 lib/git-utils/open.rb
git-utils-0.1.1 lib/git-utils/open.rb
git-utils-0.1.0 lib/git-utils/open.rb