Commit 5f6131b

mo khan <mo@mokhan.ca>
2021-03-20 00:04:16
refactor: extract methods for generating slugs tag: v0.4.4
1 parent 3073f31
Changed files (1)
lib
lib/jive/repo.rb
@@ -12,12 +12,7 @@ module Jive
       remote = @repo.remotes.find { |x| x.name == "origin" }
       return if remote.nil?
 
-      if (match = remote.url.match(SSH_REGEX))
-        ["https:/", match[:host], match[:account], match[:repo], @repo.head.name].join("/")
-      else
-        uri = URI.parse(remote.url)
-        [uri.host, uri.path, @repo.head.name].join("/")
-      end
+      ssh?(remote) ? url_for_ssh(remote) : url_for(remote)
     end
 
     class << self
@@ -25,5 +20,27 @@ module Jive
         @current ||= new(Pathname.pwd)
       end
     end
+
+    private
+
+    def ssh?(remote)
+      remote.url.match?(SSH_REGEX)
+    end
+
+    def url_for_ssh(remote)
+      match = remote.url.match(SSH_REGEX)
+      [
+        "https:/",
+        match[:host],
+        match[:account],
+        match[:repo],
+        @repo.head.name
+      ].join("/")
+    end
+
+    def url_for(remote)
+      uri = URI.parse(remote.url)
+      [uri.host, uri.path, @repo.head.name].join("/")
+    end
   end
 end