lib/instapusher/git.rb in instapusher-0.1.0 vs lib/instapusher/git.rb in instapusher-0.1.1

- old
+ new

@@ -1,6 +1,35 @@ 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 repo" @@ -20,12 +49,11 @@ result end def repo_owner string = `git remote -v | grep fetch | grep origin` - regex = /.*:(.*)\/.*/ - match_data = string.match(regex) - match_data.to_a.last + RepoOwnerIdentifierService.new(string).process end end end +