Skip to content

Commit

Permalink
Small cleanup to canonicalization routines (JuliaPackaging#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat authored Feb 16, 2018
1 parent 96871ea commit dbc7432
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/wizard/obtain_source.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using ProgressMeter

const repo_regex = r"(https:\/\/)?github.com\/([^\/]+)\/([^\/]+)\/?$"

"""
Canonicalize a GitHub repository URL
"""
function canonicalize_source_url(url)
repo_regex = r"(https:\/\/)?github.com\/([^\/]+)\/([^\/]+)\/?$"

m = match(repo_regex, url)
if m !== nothing
_, user, repo = m.captures
Expand Down Expand Up @@ -202,9 +206,11 @@ function step1(state::WizardState)
println(state.outs)
end

const blob_regex = r"(https:\/\/)?github.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)"

"""
Canonicalize URL to a file within a GitHub repo
"""
function canonicalize_file_url(url)
blob_regex = r"(https:\/\/)?github.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)"
m = match(blob_regex, url)
if m !== nothing
_, user, repo, ref, filepath = m.captures
Expand Down Expand Up @@ -241,7 +247,7 @@ function obtain_binary_deps(state::WizardState)
print(state.outs, "> ")
url = readline(state.ins)
println(state.outs)
canon_url = canonicalize_url(url)
canon_url = canonicalize_file_url(url)
if url != canon_url
print(state.outs, "The entered URL has been canonicalized to\n")
printstyled(state.outs, canon_url, bold=true)
Expand Down

0 comments on commit dbc7432

Please sign in to comment.