Skip to content

Commit

Permalink
Merge branch 'release/0.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
smallhadroncollider committed Jan 23, 2020
2 parents 57dca4d + 1da6c35 commit 6d55531
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: brok
version: 0.1.6.0
version: 0.1.7.0
github: "smallhadroncollider/brok"
license: BSD3
author: "Small Hadron Collider"
Expand Down
4 changes: 2 additions & 2 deletions src/Brok.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ go :: C.Config -> IO ()
go config
-- read files
= do
content <- sequence (readContent . pathToResult <$> C.files config)
content <- traverse (readContent . pathToResult) (C.files config)
-- find links in each file
let parsed = parseLinks links <$> content
-- check cached successes
Expand All @@ -37,7 +37,7 @@ go config
-- check links in each file
header "Checking URLs"
putStrLn ""
checked <- sequence (linkIOMap (check (C.interval config)) <$> uncached)
checked <- traverse (linkIOMap (check (C.interval config))) uncached
replace "Fetching complete"
-- display results
putStrLn ""
Expand Down
2 changes: 1 addition & 1 deletion src/Brok/IO/DB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ setCached :: Maybe Integer -> [URL] -> IO ()
setCached Nothing _ = return ()
setCached (Just age) links = do
current <- load age
stamped <- sequence (stamp <$> links)
stamped <- traverse stamp links
write $ current ++ stamped

-- read db
Expand Down
8 changes: 4 additions & 4 deletions src/Brok/IO/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ outputMap onlyFailures (Result path (Links links)) = do
if anyErrs
then do
errorMessage $ outputPath path
sequence_ $
linkOutput <$>
traverse_
linkOutput
(if onlyFailures
then errs
else links)
else unless onlyFailures $ do
message $ outputPath path
if not (null links)
then sequence_ $ linkOutput <$> links
then traverse_ linkOutput links
else putStrLn "- No links found in file"
return anyErrs
outputMap _ _ = return False

output :: Bool -> [Result] -> IO Bool
output onlyFailures results = do
errs <- sequence $ outputMap onlyFailures <$> results
errs <- traverse (outputMap onlyFailures) results
let anyErrs = foldl' (||) False errs
when (not anyErrs && onlyFailures) $ successMessage "All links working"
return anyErrs
4 changes: 2 additions & 2 deletions src/Brok/Parser/Links.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ parens parser = surround '(' ')' parser <|> surround '[' ']' parser

-- urls
part :: String -> Parser Text
part str = concat <$> many' (parens (part str) <|> manyChars (chars str))
part str = concat <$> many1 (parens (part str) <|> manyChars (chars str))

query :: Parser Text
query = (++) <$> string "?" <*> part queryBodyChars
Expand All @@ -42,7 +42,7 @@ url =
option "" query

noise :: Parser Token
noise = anyChar >> return Nothing
noise = anyChar $> Nothing

urls :: Parser [URL]
urls = nub . catMaybes <$> many1 ((Just <$> url) <|> noise)
Expand Down
2 changes: 1 addition & 1 deletion src/Brok/Types/Result.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ignoredLinks :: [URL] -> Result -> Result
ignoredLinks = findLinks ignoredLink

linkIOMap :: (Link -> IO Link) -> Result -> IO Result
linkIOMap fn (Result path (Links links)) = Result path . Links <$> sequence (lmap fn <$> links)
linkIOMap fn (Result path (Links links)) = Result path . Links <$> traverse (lmap fn) links
linkIOMap _ result = return result

justLinks :: Result -> [Link]
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-13.6
resolver: lts-14.21
pvp-bounds: both
packages:
- .
12 changes: 12 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 524162
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/21.yaml
sha256: 9a55dd75853718f2bbbe951872b36a3b7802fcd71796e0f25b8664f24e34c666
original: lts-14.21
18 changes: 12 additions & 6 deletions taskell.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
## Refactoring

- Use State monad for [Result] passing around?
> Needs to have IO too. mtl?
## Features

- Should show line number of found links
- Should detect if internet connection is down
- Parallel HTTP fetch for separate domains
- Better --only-failures output
- Cache length option should accept units: s, m, h, d - default to s
- Should be able to detect links without http:// or https:// prefixes
- More detailed HttpException errors
- Parallel HTTP fetch for separate domains
- Should be able to detect links without http:// or https:// prefixes
- Should detect if internet connection is down
- Should show line number of found links

## Bugs

- Is an invalid URL an error?
> Should an invalid URL count as an error? The parser shouldn't really pick up invalid URLs. But if it looks like one and fails then it is probably worth high-lighting.
- Can't parse links containing single quote marks
- Fetching message sometimes goes to more than one line, so next line doesn't replace it (saveCursor/restoreCursor?)
- Checks the same URL multiple times if in different files
- Is an invalid URL an error?
> Should an invalid URL count as an error? The parser shouldn't really pick up invalid URLs. But if it looks like one and fails then it is probably worth high-lighting.
- Edge case: shouldn't delay if only a single URL being checked

## In Progress
Expand Down
9 changes: 9 additions & 0 deletions test/Parser/LinksTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,14 @@ test_parser =
])
(links tex))
]
, testGroup
"just protocol"
[ testCase
"https://"
(assertEqual "Gives back empty list" (Right []) (links "https://"))
, testCase
"http://"
(assertEqual "Gives back empty list" (Right []) (links "http://"))
]
, testCase "nothing" (assertEqual "Gives back empty list" (Right []) (links ""))
]

0 comments on commit 6d55531

Please sign in to comment.