<commit_before>module Hi.Template
    (
      withTemplatesFromRepo
    , untemplate
    ) where

import           Hi.Directory (inTemporaryDirectory)
import           Data.List.Split       (splitOn)
import           System.Exit           (ExitCode)
import           System.FilePath.Glob  (compile, globDir1)
import           System.Process        (system)

-- | Run callback with list of template files.
withTemplatesFromRepo :: String               -- ^ Repository url
                      -> ([FilePath] -> IO a) -- ^ Callback which takes list of the template file
                      -> IO a                 -- ^ Result
withTemplatesFromRepo repo cb =
    inTemporaryDirectory "hi" $ do
        _ <- cloneRepo repo
        paths <- globDir1 (compile "./**/*.template") "./"
        cb paths

-- | Remove \".template\" from 'FilePath'
untemplate :: FilePath -> FilePath
untemplate = head . splitOn ".template"

-- | Clone given repository to current directory
cloneRepo :: String -> IO ExitCode
cloneRepo repoUrl = do
    system $ "git clone --no-checkout --quiet --depth=1 " ++ repoUrl ++ " ./"
    system "git checkout HEAD --quiet"<commit_msg>Comment a inappropriate error handling<commit_after>module Hi.Template
    (
      withTemplatesFromRepo
    , untemplate
    ) where

import           Hi.Directory (inTemporaryDirectory)
import           Data.List.Split       (splitOn)
import           System.Exit           (ExitCode)
import           System.FilePath.Glob  (compile, globDir1)
import           System.Process        (system)

-- | Run callback with list of template files.
withTemplatesFromRepo :: String               -- ^ Repository url
                      -> ([FilePath] -> IO a) -- ^ Callback which takes list of the template file
                      -> IO a                 -- ^ Result
withTemplatesFromRepo repo cb =
    inTemporaryDirectory "hi" $ do
        -- TODO Handle error
        _ <- cloneRepo repo
        paths <- globDir1 (compile "./**/*.template") "./"
        cb paths

-- | Remove \".template\" from 'FilePath'
untemplate :: FilePath -> FilePath
untemplate = head . splitOn ".template"

-- | Clone given repository to current directory
cloneRepo :: String -> IO ExitCode
cloneRepo repoUrl = do
    _ <- system $ "git clone --no-checkout --quiet --depth=1 " ++ repoUrl ++ " ./"
    system "git checkout HEAD --quiet"
{'fraction_non_alphanumeric': 0.10579771476936098, 'fraction_numerical': 0.0025391451544646637, 'mean_word_length': 1.955, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1830774', 'n_tokens_mistral': 626, 'n_tokens_neox': 618, 'n_words': 198}