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

Accept github subdirs more than one level deep #399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/Hpack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import Data.Map.Lazy (Map)
import qualified Data.Map.Lazy as Map
import qualified Data.HashMap.Lazy as HashMap
import Data.List (nub, (\\), sortBy, intercalate)
import qualified Data.List.NonEmpty as NE
import Data.Maybe
import Data.Semigroup (Semigroup(..))
import Data.Ord
Expand Down Expand Up @@ -588,8 +589,8 @@ 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
(owner: _) | owner `elem` ["http:", "https:"] -> fail $ "expected owner/repo or owner/repo/subdir, but encountered url instead: " ++ show input
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add some hacky url detection because otherwise urls were being matched as

owner: "https:"
repo: ""
subdir: "github.com/sol/hpack/issues/365"

Not sure how to handle this robustly

(owner: repo: subdir) -> return $ GitHub owner repo $ intercalate "/" . NE.toList <$> NE.nonEmpty subdir
_ -> fail $ "expected owner/repo or owner/repo/subdir, but encountered " ++ show input

data DefaultsConfig = DefaultsConfig {
Expand Down
16 changes: 14 additions & 2 deletions test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec = around_ (inTempDirectoryNamed "foo") $ do
location: https://github.com/sol/hpack
|]

it "accepts owner/repo/path" $ do
it "accepts owner/repo" $ do
[i|
github: hspec/hspec/hspec-core
|] `shouldRenderTo` package [i|
Expand All @@ -131,10 +131,22 @@ spec = around_ (inTempDirectoryNamed "foo") $ do
subdir: hspec-core
|]

it "accepts owner/repo/path" $ do
[i|
github: hspec/hspec/hspec-core/a/b/c/d/e
|] `shouldRenderTo` package [i|
homepage: https://github.com/hspec/hspec#readme
bug-reports: https://github.com/hspec/hspec/issues
source-repository head
type: git
location: https://github.com/hspec/hspec
subdir: hspec-core/a/b/c/d/e
|]

it "rejects URLs" $ do
[i|
github: https://github.com/sol/hpack/issues/365
|] `shouldFailWith` "package.yaml: Error while parsing $.github - expected owner/repo or owner/repo/subdir, but encountered \"https://github.com/sol/hpack/issues/365\""
|] `shouldFailWith` "package.yaml: Error while parsing $.github - expected owner/repo or owner/repo/subdir, but encountered url instead: \"https://github.com/sol/hpack/issues/365\""

describe "homepage" $ do
it "accepts homepage URL" $ do
Expand Down