Sha256: e68a1a52549fbdad36ec593f22408e69a414707a304d290f55a949d4083d02f6

Contents?: true

Size: 612 Bytes

Versions: 3

Compression:

Stored size: 612 Bytes

Contents

class GitRemote

  REPOSITORY_PATTERN = %r{
    # Define recurring patterns
    (?<part> [\w\d-]+ ){0}

    (?<user>\g<part>)/(?<repo>\g<part>).git$
  }x

  def initialize(url = nil)
    @url = url || fetch_url

    match = @url.match(REPOSITORY_PATTERN)

    @user = match[:user]
    @project = match[:repo]

    unless @user && @project
      raise "Can't extract github user and project from origin remote"
    end
  end

  attr_reader :user, :project

  private

  def fetch_url
    @fetch_url ||= run_command.split(' ').last
  end

  def run_command
   `git remote show origin | grep "Fetch URL"`
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pimpmychangelog-0.1.2 lib/pimpmychangelog/git_remote.rb
pimpmychangelog-0.1.1 lib/pimpmychangelog/git_remote.rb
pimpmychangelog-0.1.0 lib/pimpmychangelog/git_remote.rb