5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/gemstar/git_hub.rb', line 5
def self.github_blob_to_raw(url, ref_is_tag: false)
return nil unless url
uri = URI(url)
return url unless uri.host == "github.com"
owner, repo, blob, *rest = uri.path.split("/")[1..]
return url unless blob == "blob"
ref = rest.shift
path = rest.join("/")
ref_prefix = ref_is_tag ? "refs/tags/" : ""
uri.scheme = "https"
uri.host = "raw.githubusercontent.com"
uri.path = "/#{owner}/#{repo}/#{ref_prefix}#{ref}/#{path}"
uri.to_s
end
|