From 1821aca5ef5451d0b1943c8640c5eb1f6fa7bbee Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 14 Mar 2024 06:52:32 +0100 Subject: chore: resolve TODOs --- app/Review.hs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'app/Review.hs') diff --git a/app/Review.hs b/app/Review.hs index 37d9ee4..721d8e3 100644 --- a/app/Review.hs +++ b/app/Review.hs @@ -7,6 +7,7 @@ module Review ) where +import Comment.Language qualified as L import Control.Monad (ap, forM, forM_, when) import Data.Binary qualified as B import Data.ByteString.Lazy qualified as LB @@ -116,11 +117,18 @@ reviewPatch commitMessages fileDeltas = addComments :: D.FileDeltas -> D.FileDeltas addComments = - map . mapContent . mapHunks . mapLines $ \line@(D.Line {..}) -> - if lineAnnotation == D.Comment - then -- TODO Haskell comment - D.Line D.Added ("-- REVIEW" <> lineContent) - else line + map + ( \fileDelta@(D.FileDelta {D.fileDeltaSourceFile}) -> + ( mapContent . mapHunks . mapLines $ + \line@(D.Line {..}) -> + if lineAnnotation == D.Comment + then + let language = L.fromPath (T.unpack fileDeltaSourceFile) + in D.Line D.Added (L.lineStart language <> " REVIEW" <> lineContent) + else line + ) + fileDelta + ) where mapContent f x = x {D.fileDeltaContent = f x.fileDeltaContent} mapHunks _ D.Binary = D.Binary @@ -155,12 +163,8 @@ separateReview commit fileDeltas fileDeltas' = patchFile = "a.patch" patchFile' = "b.patch" -withTempSourceFiles :: - Git.CommitHash -> - D.FileDeltas -> - (FilePath -> IO a) -> - IO a -withTempSourceFiles (Git.Commit hash) fileDeltas action = do +withTempSourceFiles :: Git.CommitHash -> D.FileDeltas -> (FilePath -> IO a) -> IO a +withTempSourceFiles commit fileDeltas action = do withSystemTempDirectory "anissue" $ \tmp -> do createDirectoryIfMissing False (tmp "a") createDirectoryIfMissing False (tmp "b") @@ -168,7 +172,9 @@ withTempSourceFiles (Git.Commit hash) fileDeltas action = do let sourceDir = takeDirectory sourceFile fileContents <- if sourceFile /= "/dev/null" - then sh (proc "git show %:%" hash sourceFile) + then case commit of + Git.Commit hash -> sh (proc "git show %:%" hash sourceFile) + Git.WorkingTree -> sh (proc "cat" sourceFile) else pure "" createDirectoryIfMissing True (tmp "a" sourceDir) LB.writeFile (tmp "a" sourceFile) fileContents -- cgit v1.2.3