packages feed

brok 0.1.4.0 → 0.1.5.0

raw patch · 7 files changed

+54/−32 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Brok.IO.DB: getCached :: Integer -> IO [URL]
+ Brok.IO.DB: getCached :: Maybe Integer -> IO [URL]
- Brok.IO.DB: setCached :: Integer -> [URL] -> IO ()
+ Brok.IO.DB: setCached :: Maybe Integer -> [URL] -> IO ()
- Brok.Types.Config: Config :: Integer -> [URL] -> Integer -> [Text] -> Config
+ Brok.Types.Config: Config :: Maybe Integer -> [URL] -> Integer -> [Text] -> Config
- Brok.Types.Config: [cache] :: Config -> Integer
+ Brok.Types.Config: [cache] :: Config -> Maybe Integer

Files

README.md view
@@ -84,3 +84,29 @@ # wait for 1 second between checks brok --interval 1000 test.md links.tex ```++### Git Pre-Commit Hook++If you want to check all the links in your Git repo are valid before being able to commit then add something like the following to `.git/hooks/pre-commit`.++#### `bash`++```bash+#! /bin/bash++# cache for 1 week+# use find to check all *.md files+# only show errors (if there are any)+brok --cache 604800 $(find . -type f -name "*.md") > /dev/null+```++#### `zsh`++```bash+#! /bin/zsh++# cache for 1 week+# using a zsh glob to check all *.md files+# only show errors (if there are any)+brok --cache 604800 */**/*.md > /dev/null+```
brok.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: brok-version: 0.1.4.0+version: 0.1.5.0 license: BSD3 license-file: LICENSE copyright: 2019 Small Hadron Collider
src/Brok/IO/DB.hs view
@@ -36,8 +36,9 @@ write :: [(URL, Integer)] -> IO () write links = writeFile path . encodeUtf8 . unlines $ linkToText <$> links -setCached :: Integer -> [URL] -> IO ()-setCached age links = do+setCached :: Maybe Integer -> [URL] -> IO ()+setCached Nothing _ = return ()+setCached (Just age) links = do     current <- load age     stamped <- sequence (stamp <$> links)     write $ current ++ stamped@@ -53,5 +54,6 @@         then read age path         else return [] -getCached :: Integer -> IO [URL]-getCached age = (fst <$>) <$> load age+getCached :: Maybe Integer -> IO [URL]+getCached Nothing    = return []+getCached (Just age) = (fst <$>) <$> load age
src/Brok/Parser/Options.hs view
@@ -15,21 +15,19 @@ import Brok.Types.Next        (Next (..))  data Option-    = Cache Integer+    = Cache (Maybe Integer)     | Interval Integer     | Ignore [Text]     | Files [Text] -readInt :: String -> String -> Parser Integer-readInt arg value =-    maybe (fail $ "Unable to parse " ++ arg ++ " value") return (readMay value :: Maybe Integer)+noCacheP :: Parser Option+noCacheP = lexeme $ string "--no-cache" $> Cache Nothing  cacheP :: Parser Option-cacheP = lexeme $ Cache <$> (string "--cache" *> char '\n' *> many1 digit >>= readInt "cache")+cacheP = lexeme $ Cache . Just <$> (string "--cache" *> char '\n' *> decimal)  intervalP :: Parser Option-intervalP =-    lexeme $ Interval <$> (string "--interval" *> char '\n' *> many1 digit >>= readInt "interval")+intervalP = lexeme $ Interval <$> (string "--interval" *> char '\n' *> decimal)  urlP :: Parser Text urlP = lexeme url@@ -50,7 +48,7 @@  arguments :: Parser Config arguments = do-    opts <- many' (cacheP <|> intervalP <|> ignoreP)+    opts <- many' (noCacheP <|> cacheP <|> intervalP <|> ignoreP)     fls <- many1 fileP     return . optsToConfig $ opts ++ [Files fls] 
src/Brok/Types/Config.hs view
@@ -7,11 +7,11 @@ import Brok.Types.Link (URL)  data Config = Config-    { cache    :: Integer+    { cache    :: Maybe Integer     , ignore   :: [URL]     , interval :: Integer     , files    :: [Text]     } deriving (Show, Eq)  defaultConfig :: Config-defaultConfig = Config {cache = 84600, ignore = [], interval = 100, files = []}+defaultConfig = Config {cache = Just 84600, ignore = [], interval = 100, files = []}
test/IO/HttpTest.hs view
@@ -37,18 +37,7 @@                        "https://code.tutsplus.com/tutorials/stateful-vs-stateless-functional-components-in-react--cms-29541"                        (Working 200))                   result-        , testCase "Random blog (404 on a HEAD request)" $ do-              result <--                  check 0 $-                  urlToLink-                      "https://blog.infinitenegativeutility.com/2017/12/some-notes-about-how-i-write-haskell"-              assertEqual-                  "Returns a 200"-                  (Link-                       "https://blog.infinitenegativeutility.com/2017/12/some-notes-about-how-i-write-haskell"-                       (Working 200))-                  result-        , testCase "Non-existant site" $ do+        , testCase "Non-existent site" $ do               result <- check 0 $ urlToLink "http://askdjfhaksjdhfkajsdfh.com"               assertEqual                   "Returns a 200"
test/OptionsTest.hs view
@@ -34,10 +34,16 @@                    (Right (Continue (defaultConfig {files = ["blah.md", "tests/spoon.md"]})))                    (parse ["blah.md", "tests/spoon.md"]))         , testCase+              "single file with no-cache option"+              (assertEqual+                   "gives back files"+                   (Right (Continue (defaultConfig {cache = Nothing, files = ["blah.md"]})))+                   (parse ["--no-cache", "blah.md"]))+        , testCase               "single file with cache option"               (assertEqual                    "gives back files"-                   (Right (Continue (defaultConfig {cache = 172800, files = ["blah.md"]})))+                   (Right (Continue (defaultConfig {cache = Just 172800, files = ["blah.md"]})))                    (parse ["--cache", "172800", "blah.md"]))         , testCase               "multiple files with cache option"@@ -45,7 +51,8 @@                    "gives back files"                    (Right                         (Continue-                             (defaultConfig {cache = 172800, files = ["blah.md", "tests/spoon.md"]})))+                             (defaultConfig+                              {cache = Just 172800, files = ["blah.md", "tests/spoon.md"]})))                    (parse ["--cache", "172800", "blah.md", "tests/spoon.md"]))         , testCase               "multiple files with interval option"@@ -79,7 +86,7 @@                    (Right                         (Continue                              (defaultConfig-                              { cache = 172800+                              { cache = Just 172800                               , interval = 400                               , ignore = ["http://www.google.com", "http://facebook.com"]                               , files = ["blah.md", "tests/spoon.md"]@@ -102,7 +109,7 @@                    (Right                         (Continue                              (defaultConfig-                              { cache = 172800+                              { cache = Just 172800                               , interval = 400                               , ignore = ["http://www.google.com", "http://facebook.com"]                               , files = ["blah.md", "tests/spoon.md"]@@ -125,7 +132,7 @@                    (Right                         (Continue                              (defaultConfig-                              { cache = 172800+                              { cache = Just 172800                               , interval = 400                               , ignore = ["http://www.google.com", "http://facebook.com"]                               , files = ["blah.md", "tests/spoon.md"]