krank 0.2.2 → 0.2.3
raw patch · 7 files changed
+79/−24 lines, 7 filesdep +processsetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: process
API changes (from Hackage documentation)
- Krank.Types: krankRunRESTRequest :: (MonadKrank m, FromJSON t) => Url 'Https -> Option 'Https -> m t
+ Krank.Types: krankRunRESTRequest :: (MonadKrank m, FromJSON t) => Url 'Https -> Option 'Https -> m t
Files
- CHANGELOG.md +6/−0
- README.md +27/−13
- Setup.hs +0/−3
- app/Main.hs +32/−5
- krank.cabal +4/−3
- tests/Test/Utils/GithubSpec.hs +5/−0
- tests/Test/Utils/GitlabSpec.hs +5/−0
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for krank +## 0.2.3 -- 2021-07-18++* #88 krank tries to test files listed by `git ls-files` or `find` by default.+* #89 support `NO_COLOR`. https://no-color.org/.+* README is rebranded so it is obvious that `krank` checks for issue tracker / PR links.+ ## 0.2.2 -- 2020-06-30 * #84 fix build with `unordered-containers` 0.2.11.0
README.md view
@@ -1,23 +1,37 @@ # Krank - -Krank checks your code source comments for important markers.+Krank checks your code source comments for link to issue trackers, such as+gitlab or github. -Comments are part of our code and are not usually tested-correctly. Hence their content can become incoherent or-obsolete. Krank tries to avoid that by running checkers on the comments-themselves.+Krank will then outputs a report of the status of theses issues, if they are+closed or still open. +# Why++You are blocked on upstream ticket, there you write a nice comment in your code such as:++```python+# blocked on upstream ticket https//github.com/Foo/Bar/issues/1234+# This workaround should be removed once the upstream ticket is closed+if workaround:+ pass+```++And, this stays in your codebase for the next ten years, even if the upstream issue is closed.++Now you can run `krank` on your codebase, and it will tells you that issue+`#1234` in project `Foo/Bar` has been closed. Time to remove your workaround.+ # Usage -Just launch the `krank` command with a list of files as arguments. It+Just launch the `krank` command, optionally with a list of files as arguments. It works on any kind of source code file and prints a report of informations found in the comments: ```bash-$ krank $(git ls-files)+$ krank default.nix:20:20: info: still Open: https://github.com/NixOS/nix/issues/2733@@ -36,12 +50,12 @@ configuring your API token for external services, such as github and gitlab. -# Available checkers+# Specific documentation -- [IssueTracker](docs/Checkers/IssueTracker.md) is listing Github and- Gitlab issue linked in comment. Issues which are still Open will be- listed as info and Closed *issues* are listed as *error*. Convenient- to know when to remove workarounds.+[IssueTracker](docs/Checkers/IssueTracker.md) is listing Github and Gitlab+issue linked in comment. Issues which are still Open will be listed as info and+Closed *issues* are listed as *error*. Convenient to know when to remove+workarounds. # Red herring
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
app/Main.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE ScopedTypeVariables #-} import Control.Applicative (optional) import Control.Monad.Reader@@ -9,12 +10,17 @@ import Krank import Krank.Types import qualified Options.Applicative as Opt-import Options.Applicative ((<**>), many, some)+import Options.Applicative ((<**>), many) import PyF (fmt) import System.Console.Pretty (supportsPretty) import System.Exit (exitFailure) import Text.Regex.PCRE.Heavy import Version (displayVersion)+import System.Environment (lookupEnv)+import Data.Maybe+import System.Process+import Control.Exception (catch)+import GHC.Exception data KrankOpts = KrankOpts@@ -23,7 +29,7 @@ } filesToParse :: Opt.Parser [FilePath]-filesToParse = some (Opt.argument Opt.str (Opt.metavar "FILES..."))+filesToParse = many (Opt.argument Opt.str (Opt.metavar "FILES..." <> Opt.help "List of file to check. If empty, it will try to use `git ls-files`.")) githubKeyToParse :: Opt.Parser (Maybe GithubKey) githubKeyToParse =@@ -56,7 +62,7 @@ not <$> Opt.switch ( Opt.long "no-colors"- <> Opt.help "Disable colored outputs"+ <> Opt.help "Disable colored outputs. You can also set NO_COLOR environment variable." ) versionParse :: Opt.Parser (a -> a)@@ -92,11 +98,32 @@ main :: IO () main = do- canUseColor <- supportsPretty+ noColor <- isJust <$> lookupEnv "NO_COLOR"+ colorSupport <- supportsPretty++ let canUseColor = colorSupport && not noColor config <- Opt.customExecParser (Opt.prefs Opt.showHelpOnError) opts let kConfig = (krankConfig config) { useColors = useColors (krankConfig config) && canUseColor }- success <- runReaderT (unKrank $ runKrank (codeFilePaths config)) kConfig++ -- If files are not explicitly listed, try `git ls-files` and `find`.+ files <- case codeFilePaths config of+ [] -> (lines <$> readProcess "git" ["ls-files"] "") `catch` (\(e :: SomeException) -> noGitFailure e)+ l -> pure l+ + success <- runReaderT (unKrank $ runKrank files) kConfig unless success exitFailure++noGitFailure :: SomeException -> IO [String]+noGitFailure e = do+ print e+ putStrLn "`Git` was not found, trying to list files using `find`"+ (lines <$> readProcess "find" [""] "") `catch` findFailure++findFailure :: SomeException -> IO [FilePath]+findFailure e = do+ print e+ putStrLn "`find` was not found, please pass file argument manually"+ pure []
krank.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: krank-version: 0.2.2-synopsis: Krank checks your code source comments for important markers+version: 0.2.3+synopsis: Krank checks issue tracker link status in your source code -- description: bug-reports: https://github.com/guibou/krank/issues license: BSD-3-Clause@@ -11,7 +11,7 @@ homepage: https://github.com/guibou/krank copyright: category: quality-description: Comments are part of our code and are not usually tested correctly. Hence their content can become incoherent or obsolete. Krank tries to avoid that by running checkers on the comment themselves.+description: Krank checks issue tracker link status in your source code. When you implement a workaround because of an upstream issue, you often put a link in comment in your code. Krank will tell you when the issue associated with your workaround is closed, meaning that you may get ride of your workaround. build-type: Simple extra-source-files: CHANGELOG.md, README.md HACKING.md docs/Checkers/IssueTracker.md @@ -85,6 +85,7 @@ , pcre-heavy , pretty-terminal , text+ , process hs-source-dirs: app default-language: Haskell2010 ghc-options: -Wall -threaded -rtsopts
tests/Test/Utils/GithubSpec.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE CPP #-} module Test.Utils.GithubSpec ( spec,@@ -55,7 +56,11 @@ showGithubException exception `shouldBe` showHTTPException showRawResponse exception dummyResponse :: Status -> Response ()+#if MIN_VERSION_http_client(0,7,8)+dummyResponse status = Response status http11 [] () (createCookieJar []) (ResponseClose $ pure ()) (error "WTF")+#else dummyResponse status = Response status http11 [] () (createCookieJar []) (ResponseClose $ pure ())+#endif -- | From a raw error message to a JSON formatted github error mkGithubErrorBody :: Text -> ByteString
tests/Test/Utils/GitlabSpec.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE CPP #-} -- Leaving unnecessary do because -- * they improve readability@@ -62,7 +63,11 @@ showGitlabException exception `shouldBe` showHTTPException showRawResponse exception dummyResponse :: Status -> Response ()+#if MIN_VERSION_http_client(0,7,8)+dummyResponse status = Response status http11 [] () (createCookieJar []) (ResponseClose $ pure ()) (error "WTF")+#else dummyResponse status = Response status http11 [] () (createCookieJar []) (ResponseClose $ pure ())+#endif -- | From a raw error message to a JSON formatted gitlab error mkGitlabErrorBody :: Text -> ByteString