Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deeper subdirectory for github #445

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/Hpack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,37 @@ data GitHub = GitHub {
instance FromValue GitHub where
fromValue v = do
input <- fromValue v
case map T.unpack $ T.splitOn "/" input of
[owner, repo, subdir] -> return $ GitHub owner repo (Just subdir)
[owner, repo] -> return $ GitHub owner repo Nothing
_ -> fail $ "expected owner/repo or owner/repo/subdir, but encountered " ++ show input
let parsed = case map T.unpack $ T.splitOn "/" input of
-- Bad: empty: ""
[] ->
Nothing

-- Bad: starts with a slash: "/..."
"" : _rest ->
Nothing

-- Bad: starts with an URL-like protocol: "https:...", "git:..."
proto : _rest | last proto == ':' ->
Nothing

-- Bad: single path piece: "sol"
[_owner] ->
Nothing

-- Good: "sol/hpack"
[owner, repo] ->

Just $ GitHub owner repo Nothing

-- Good: "sol/hpack/subdir", "sol/hpack/deep/subdir/..."
owner : repo : subdirs ->
Just $ GitHub owner repo (Just $ intercalate "/" subdirs)

case parsed of
Nothing ->
fail $ "expected \"owner/repo\" or \"owner/repo/subdir\", but encountered " ++ show input
Just ok ->
return ok

data DefaultsConfig = DefaultsConfig {
defaultsConfigDefaults :: Maybe (List Defaults)
Expand Down