Module: Ace::Git::Atoms::ServerUrl
- Defined in:
- lib/ace/git/atoms/server_url.rb
Overview
Normalize forge server URLs and remote URLs to a canonical comparable form. Purely textual: no network access, no hostname allow-lists, and no assumptions about any particular forge host.
Supported input shapes:
- "https://forge.example.com/owner/repo.git"
- "http://forge.internal:3000/owner/repo"
- "[email protected]:owner/repo.git" (scp-style)
- "ssh://[email protected]:2222/owner/repo.git"
- "forge.example.com/owner/repo"
Canonical form: lowercase "host/path" with any credentials, scheme, trailing slash, and ".git" suffix removed. A colon segment is treated as a port (not an scp separator) only when it is all digits and followed by a slash; everything else is scp-style "host:path".
Class Method Summary collapse
-
.match?(server_url, remote_url) ⇒ Boolean
Compare a configured server URL against a remote URL for identity.
-
.normalize(url) ⇒ String
Normalize a server or remote URL to the canonical comparable form.
Class Method Details
.match?(server_url, remote_url) ⇒ Boolean
Compare a configured server URL against a remote URL for identity.
46 47 48 49 50 51 52 |
# File 'lib/ace/git/atoms/server_url.rb', line 46 def self.match?(server_url, remote_url) normalized_server = normalize(server_url) normalized_remote = normalize(remote_url) return false if normalized_server.empty? || normalized_remote.empty? normalized_server == normalized_remote end |
.normalize(url) ⇒ String
Normalize a server or remote URL to the canonical comparable form.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ace/git/atoms/server_url.rb', line 26 def self.normalize(url) text = url.to_s.strip text = text.sub(%r{\A[a-z][a-z0-9+.\-]*://}i, "") text = text.sub(%r{\A[^/@]+@}, "") if (port_match = text.match(%r{\A([^/:]+):(\d+)(/.+)\z})) text = "#{port_match[1]}:#{port_match[2]}#{port_match[3]}" elsif (scp_match = text.match(%r{\A([^/:]+):(.+)\z})) text = "#{scp_match[1]}/#{scp_match[2]}" end text = text.sub(%r{/?\.git/?\z}i, "") text.chomp("/").downcase end |