@@ -8,6 +8,8 @@ module HaskellCI.GitHub (
88
99import HaskellCI.Prelude
1010
11+ import Control.Applicative (optional )
12+
1113import qualified Crypto.Hash.SHA256 as SHA256
1214import qualified Data.Attoparsec.Text as Atto
1315import qualified Data.Binary as Binary
@@ -42,6 +44,9 @@ import HaskellCI.ShVersionRange
4244import HaskellCI.Tools
4345import HaskellCI.VersionInfo
4446
47+ -- $setup
48+ -- >>> :set -XOverloadedStrings
49+
4550-------------------------------------------------------------------------------
4651-- GitHub header
4752-------------------------------------------------------------------------------
@@ -556,16 +561,43 @@ cat path contents = sh $ concat
556561 , " EOF"
557562 ]
558563
564+ -- | GitHub is very lenient and undocumented. We accept something.
565+ -- Please, write a patch, if you need an extra scheme to be accepted.
566+ --
567+ -- >>> parseGitHubRepo "[email protected] :haskell-CI/haskell-ci.git" 568+ -- Just "haskell-CI/haskell-ci"
569+ --
570+ -- >>> parseGitHubRepo "[email protected] :haskell-CI/haskell-ci" 571+ -- Just "haskell-CI/haskell-ci"
572+ --
573+ -- >>> parseGitHubRepo "https://github.com/haskell-CI/haskell-ci.git"
574+ -- Just "haskell-CI/haskell-ci"
575+ --
576+ -- >>> parseGitHubRepo "https://github.com/haskell-CI/haskell-ci"
577+ -- Just "haskell-CI/haskell-ci"
578+ --
579+ -- >>> parseGitHubRepo "git://github.com/haskell-CI/haskell-ci"
580+ -- Just "haskell-CI/haskell-ci"
581+ --
559582parseGitHubRepo :: Text -> Maybe Text
560583parseGitHubRepo t =
561584 either (const Nothing ) Just $ Atto. parseOnly (parser <* Atto. endOfInput) t
562585 where
563586 parser :: Atto. Parser Text
564- parser = sshP
587+ parser = sshP <|> httpsP
565588
566589 sshP :: Atto. Parser Text
567590 sshP = do
591+ _ <- optional (Atto. string " git://" )
568592 _
<- Atto. string
" [email protected] :" 569593 repo <- Atto. takeWhile (/= ' .' )
570- _ <- Atto. string " .git"
594+ _ <- optional (Atto. string " .git" )
595+ return repo
596+
597+ httpsP :: Atto. Parser Text
598+ httpsP = do
599+ _ <- Atto. string " https" <|> Atto. string " git"
600+ _ <- Atto. string " ://github.com/"
601+ repo <- Atto. takeWhile (/= ' .' )
602+ _ <- optional (Atto. string " .git" )
571603 return repo
0 commit comments