aboutsummaryrefslogtreecommitdiffstats
path: root/app/Review.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-14 06:52:32 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-14 07:07:45 +0100
commit1821aca5ef5451d0b1943c8640c5eb1f6fa7bbee (patch)
treedc3df78464a164b3fb9674d4e03bc56d58a56df1 /app/Review.hs
parent2c107e71572888327496d327a36737c02f64d894 (diff)
chore: resolve TODOs
Diffstat (limited to 'app/Review.hs')
-rw-r--r--app/Review.hs30
1 files changed, 18 insertions, 12 deletions
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