Skip to content

Commit f844879

Browse files
authored
Merge pull request #443 from haskell-CI/issue-440-github-url-parsing
Fix #440: Accept more urls as github origin
2 parents 758b2e3 + 736e288 commit f844879

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ accept : build
2323
(cd cabal-install-parsers && cabal v2-run -w $(HC) cabal-parsers-golden -- --accept)
2424

2525
doctest :
26+
perl -i -e 'while (<ARGV>) { print unless /package-id\s+(base-compat-batteries|bs-cmpt-bttrs)-\d+(\.\d+)*/; }' .ghc.environment.*
2627
doctest --fast -XBangPatterns -XScopedTypeVariables -XDerivingStrategies -XGeneralizedNewtypeDeriving -XDeriveAnyClass -XNoImplicitPrelude -XDeriveFunctor -XDeriveFoldable -XDeriveTraversable -XDeriveGeneric src
2728

2829
regenerate :

src/HaskellCI/GitHub.hs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module HaskellCI.GitHub (
88

99
import HaskellCI.Prelude
1010

11+
import Control.Applicative (optional)
12+
1113
import qualified Crypto.Hash.SHA256 as SHA256
1214
import qualified Data.Attoparsec.Text as Atto
1315
import qualified Data.Binary as Binary
@@ -42,6 +44,9 @@ import HaskellCI.ShVersionRange
4244
import HaskellCI.Tools
4345
import 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+
--
559582
parseGitHubRepo :: Text -> Maybe Text
560583
parseGitHubRepo 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

Comments
 (0)