Commit a6efc95f7783b76592e97d1c9c2d7206ccf3617b Parent: afedb32fd8d5e3134b4f9f05b78779bd4b7c2e27 Author: mcol <mcol@posteo.net> Date: 2021-12-03 23:47:17 +0300 Committer: mcol <mcol@posteo.net> Committed: 2021-12-03 23:47:17 +0300 Add `scanRepoPaths` config option to instead scan for repos Closes #17
test/config.dhall Modified
@@ -1,5 +1,6 @@ let config = { repoPaths = ["."] + , scanRepoPaths = False , templateDirectory = "./test/templates" , outputDirectory = "./test/result" , host = "https://github.com/m-col/gitserve"
src/config.dhall Modified
@@ -13,6 +13,7 @@ -- You may want to replace the relative paths for absolute paths. let config = { repoPaths = folders + , scanRepoPaths = True , templateDirectory = "./template" , outputDirectory = "./output" , host = "http://localhost:8000"
src/Templates.hs Modified
@@ -82,7 +82,12 @@ ensureDir output -- Parse repos for env - repoPaths' <- mapM (parseAbsDir <=< canonicalizePath) . repoPaths $ config + repoPaths' <- + if scanRepoPaths config + then do + ps <- fmap concat . mapM (fmap fst . ls) . repoPaths $ config + return . filter ((/=) ".git" . toFilePath . dirname) $ ps + else mapM (parseAbsDir <=< canonicalizePath) . repoPaths $ config -- Find template files, copying the static files as is (dirs, files) <- ls . templateDirectory $ config
src/Repositories.hs Modified
@@ -10,10 +10,11 @@ ) where import Conduit (runConduit, sinkList, (.|)) -import Control.Monad (unless, when, (<=<)) +import Control.Exception (try) +import Control.Monad (filterM, unless, when, (<=<)) import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Reader (ReaderT) -import Data.Either (fromRight) +import Data.Either (fromRight, isRight) import qualified Data.HashMap.Strict as HashMap import Data.Maybe (catMaybes, fromJust, mapMaybe) import Data.Tagged @@ -45,9 +46,12 @@ -} loadRepos :: Env -> IO [Repo] loadRepos env = do - let paths = envRepoPaths env - descs <- mapM getDescription paths - return . fmap ($ Nothing) . zipWith Repo paths $ descs + paths' <- filterM (fmap isRight . okRepo) . envRepoPaths $ env + descs <- mapM getDescription paths' + return . fmap ($ Nothing) . zipWith Repo paths' $ descs + where + okRepo :: Path Abs Dir -> IO (Either GitException LgRepo) + okRepo p = try . liftIO . openRepository lgFactory $ defaultRepositoryOptions{repoPath = toFilePath p} {- Pass the repository's folder, get its description.
src/Config.hs Modified
@@ -14,6 +14,7 @@ data Config = Config { repoPaths :: [FilePath] + , scanRepoPaths :: Bool , templateDirectory :: FilePath , outputDirectory :: FilePath , host :: Text
config.dhall Modified
@@ -13,6 +13,7 @@ -- If copying, you may want to replace the relative paths for absolute paths. let config = { repoPaths = folders + , scanRepoPaths = False , templateDirectory = "./templates/docs" , outputDirectory = "./output" , host = "http://localhost:8000"
DOCUMENTATION.md Modified
@@ -16,12 +16,13 @@ It requires the following settings: -| Setting | Description | -| -------------------- | --------------------------------------------------- | -| `repoPaths` | A list of folders containing your git repositories. | -| `templateDirectory` | The folder containing the template (see below). | -| `outputDirectory` | Where to put the generated files. | -| `host` | The host URL, which is needed for creating links. | +| Setting | Description | +| ------------------- | --------------------------------------------------- | +| `repoPaths` | A list of folders containing your git repositories. | +| `scanRepoPaths` | Whether `repoPaths` lists repos or folders containing nested repos. | +| `templateDirectory` | The folder containing the template (see below). | +| `outputDirectory` | Where to put the generated files. | +| `host` | The host URL, which is needed for creating links. | Then, pass the config file to gitserve.