mirror of
https://github.com/discourse/discourse.git
synced 2024-12-11 21:53:44 +08:00
ec4c302708
Co-authored-by: Daniel Waterworth <me@danielwaterworth.com>
21 lines
385 B
Ruby
21 lines
385 B
Ruby
# frozen_string_literal: true
|
|
|
|
module GitUrl
|
|
class << self
|
|
SSH_REGEXP = /\A(\w+@\w+(\.\w+)*):(.*)\z/
|
|
|
|
def normalize(url)
|
|
if m = SSH_REGEXP.match(url)
|
|
url = "ssh://#{m[1]}/#{m[3]}"
|
|
end
|
|
|
|
if url.start_with?("https://github.com/") && !url.end_with?(".git")
|
|
url = url.gsub(%r{/$}, "")
|
|
url += ".git"
|
|
end
|
|
|
|
url
|
|
end
|
|
end
|
|
end
|