packages feed

codecov-haskell 0.2.0 → 0.3.0

raw patch · 6 files changed

+47/−9 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Trace.Hpc.Codecov.Types: PostSuccess :: URLString -> String -> PostResult
+ Trace.Hpc.Codecov.Types: PostSuccess :: URLString -> URLString -> PostResult

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@++[0.3.0](https://github.com/guillaume-nargeot/codcov-haskell/issues?q=milestone:v0.3.0+is:closed)+-----+* Fix coverage result response reading (issue #5)+ +[0.2.0](https://github.com/guillaume-nargeot/codcov-haskell/issues?q=milestone:v0.2.0+is:closed) ----- * Fix coverage conversion rule for otherwise bug (issue #4)
README.md view
@@ -1,4 +1,4 @@-codecov-haskell [![Build Status](http://img.shields.io/travis/guillaume-nargeot/codecov-haskell/master.svg)](https://travis-ci.org/guillaume-nargeot/codecov-haskell) [![Gitter chat](http://img.shields.io/badge/gitter-chat--room-brightgreen.svg)](https://gitter.im/guillaume-nargeot/codecov-haskell) [![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29) [![v0.2.0 on Hackage](http://img.shields.io/badge/hackage-0.2.0-brightgreen.svg)](http://hackage.haskell.org/package/codecov-haskell-0.2.0)+codecov-haskell [![Build Status](http://img.shields.io/travis/guillaume-nargeot/codecov-haskell/master.svg)](https://travis-ci.org/guillaume-nargeot/codecov-haskell) [![Gitter chat](http://img.shields.io/badge/gitter-chat--room-brightgreen.svg)](https://gitter.im/guillaume-nargeot/codecov-haskell) [![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29) [![v0.3.0 on Hackage](http://img.shields.io/badge/hackage-0.3.0-brightgreen.svg)](http://hackage.haskell.org/package/codecov-haskell-0.3.0) ===============  codecov-haskell converts and sends Haskell projects hpc code coverage to [codecov.io](http://codecov.io/).@@ -36,6 +36,7 @@ You may also experience some issues related to your project dependencies, which can be solved by using the `--avoid-reinstalls`/`--force-reinstalls` flags.</br> Another way to solve problems related dependencies is to install codecov-haskell in a sandbox, as in the example below: ```yaml+after_script:   - cabal sandbox init && cabal install codecov-haskell   - .cabal-sandbox/bin/codecov-haskell [options] [test-suite-names] ```@@ -60,7 +61,7 @@ Below is an example which can be useful for projects with a Travis configuration based on [multi-ghc-travis](https://github.com/hvr/multi-ghc-travis):  ```yaml-run-cabal-test --cabal-name=cabal-1.18+run-cabal-test --cabal-name=cabal-1.20 ```  ## The codecov-haskell command@@ -89,6 +90,10 @@ ```yaml codecov-haskell --exclude-dir=test1 --exclude-dir=test2 [test-suite-names] ```++#### --display-report++This boolean option prints the raw json coverage report to be sent to coveralls.io.  #### --dont-send 
codecov-haskell.cabal view
@@ -1,5 +1,5 @@ name:           codecov-haskell-version:        0.2.0+version:        0.3.0 synopsis:       Codecov.io support for Haskell. description:   This utility converts and sends Haskell projects hpc code coverage to
src/CodecovHaskellMain.hs view
@@ -1,6 +1,7 @@ module Main where  import           Control.Applicative+import           Control.Concurrent import           Control.Monad import           Data.Aeson import qualified Data.ByteString.Lazy.Char8 as BSL@@ -46,7 +47,12 @@                 apiUrl <- getUrlApiV1                 response <- postJson (BSL.unpack $ encode codecovJson) apiUrl (printResponse cha)                 case response of-                    PostSuccess url totalCoverage -> do+                    PostSuccess url waitUrl -> do                         putStrLn ("URL: " ++ url)-                        putStrLn ("Coverage: " ++ totalCoverage)+                        -- wait 10 seconds until the page is available+                        threadDelay (10 * 1000000)+                        coverageResult <- readCoverageResult waitUrl (printResponse cha)+                        case coverageResult of+                            Just totalCoverage -> putStrLn ("Coverage: " ++ totalCoverage) >> exitSuccess+                            Nothing -> putStrLn "Failed to read total coverage" >> exitSuccess                     PostFailure msg -> putStrLn ("Error: " ++ msg) >> exitFailure
src/Trace/Hpc/Codecov/Curl.hs view
@@ -10,8 +10,9 @@ -- -- Functions for sending coverage report files over http. -module Trace.Hpc.Codecov.Curl ( postJson, PostResult (..) ) where+module Trace.Hpc.Codecov.Curl ( postJson, readCoverageResult, PostResult (..) ) where +import           Control.Applicative import           Control.Monad import           Data.Aeson import           Data.Aeson.Types (parseMaybe)@@ -22,7 +23,7 @@  parseResponse :: CurlResponse -> PostResult parseResponse r = case respCurlCode r of-    CurlOK -> PostSuccess (getField "url") (show (getField "coverage" :: Integer) ++ "%")+    CurlOK -> PostSuccess (getField "url") (getField "wait_url")     _      -> PostFailure $ getField "message"     where getField fieldName = fromJust $ mGetField fieldName           mGetField fieldName = do@@ -44,3 +45,25 @@     r <- perform_with_response_ h     when printResponse $ putStrLn $ respBody r     return $ parseResponse r++extractCoverage :: String -> Maybe String+extractCoverage rBody = (++ "%") . show <$> (getField "coverage" :: Maybe Integer)+    where getField fieldName = do+              result <- decode $ LBS.pack rBody+              parseMaybe (.: fieldName) result++-- | Read the coveraege result page from coveralls.io+readCoverageResult :: URLString         -- ^ target url+                   -> Bool              -- ^ print json response if true+                   -> IO (Maybe String) -- ^ coverage result+readCoverageResult url printResponse = do+    response <- curlGetString url curlOptions+    when printResponse $ putStrLn $ snd response+    return $ case response of+        (CurlOK, body) -> extractCoverage body+        _ -> Nothing+    where curlOptions = [+              CurlTimeout 60,+              CurlConnectTimeout 60,+              CurlVerbose True,+              CurlFollowLocation True]
src/Trace/Hpc/Codecov/Types.hs view
@@ -29,5 +29,5 @@  -- | Result to the POST request to codecov.io data PostResult =-    PostSuccess URLString String -- ^ Codecov job url and total coverage percentage-  | PostFailure String           -- ^ error message+    PostSuccess URLString URLString -- ^ Codecov job url and wait url+  | PostFailure String              -- ^ error message