Sha256: 5344fd0ee5eb435c00e67e5d5ae1c2ff5054dc4eeeec17c6d555eeaf9b56f3fb

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module Instapusher

  class RepoOwnerIdentifierService

    attr_reader :string

    def initialize string
      @string = string
    end

    def process
      string.include?('git@github.com') ? handle_ssh_version : handle_https_version
    end

    private

    def handle_ssh_version
      regex = /.*:(.*)\/.*/
      match_data = string.match(regex)
      match_data.to_a.last
    end

    def handle_https_version
      regex = /.*:\/\/github\.com\/(.*)\/.*/
      match_data = string.match(regex)
      match_data.to_a.last
    end

  end

  class Git
    def current_branch
      result = %x{git branch}.split("\n")
      if result.empty?
        raise "It seems your app is not a git repository. Please check."
      else
        result.select { |b| b =~ /^\*/ }.first.split(" ").last.strip
      end
    end

    def current_user
      `git config user.name`.chop!
    end

    def project_name
      result = `git config remote.origin.url`.chop!.scan(/\/([^\/]+)?$/).flatten.first
      result.sub!(/\.git$/, '') if result
      result ||= File.basename(Dir.getwd)
      result
    end

    def repo_owner
      string = `git remote -v | grep fetch | grep origin`
      RepoOwnerIdentifierService.new(string).process
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
instapusher-0.1.9 lib/instapusher/git.rb
instapusher-0.1.8 lib/instapusher/git.rb
instapusher-0.1.7 lib/instapusher/git.rb