diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-21 05:35:00 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-25 07:45:59 +0100 |
commit | f83b424bf70b7b14b0268aeeafe1b3483fced49f (patch) | |
tree | 348a60e815f4bee492f58dea903ebc380029d61f /app/Review.hs | |
parent | fc0afaaa273f5b5d3696df87d70d5347a13bb9ac (diff) |
chore: Git -> Backend
Diffstat (limited to 'app/Review.hs')
-rw-r--r-- | app/Review.hs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/app/Review.hs b/app/Review.hs index 721d8e3..52af23b 100644 --- a/app/Review.hs +++ b/app/Review.hs @@ -7,6 +7,7 @@ module Review ) where +import Backend qualified import Comment.Language qualified as L import Control.Monad (ap, forM, forM_, when) import Data.Binary qualified as B @@ -17,7 +18,6 @@ import Data.Text qualified as T import Data.Text.Encoding qualified as T import Data.Text.IO qualified as T import GHC.Generics (Generic) -import Git qualified import Patch qualified as A import Process (proc, sh, sh_) import Render (renderAsText) @@ -31,7 +31,7 @@ import Text.Diff.Parse.Types qualified as D data Plan = Plan { baseBranch :: BranchName, featureBranch :: BranchName, - commit :: Git.CommitHash, + commit :: Backend.CommitHash, perCommit :: Bool, steps :: NE.NonEmpty PlanStep } @@ -40,22 +40,22 @@ data Plan = Plan type BranchName = T.Text data PlanStep = PlanStep - { commit :: Git.CommitHash, - earlierCommit :: Git.CommitHash, + { commit :: Backend.CommitHash, + earlierCommit :: Backend.CommitHash, changes :: D.FileDeltas } deriving (Show, Generic, B.Binary) formulatePlan :: Bool -> T.Text -> T.Text -> IO Plan formulatePlan perCommit baseBranch featureBranch = do - baseCommit <- Git.resolveRef baseBranch - featureCommit <- Git.resolveRef featureBranch + baseCommit <- Backend.resolveRef baseBranch + featureCommit <- Backend.resolveRef featureBranch commits <- if perCommit then do commits <- - reverse <$> Git.getCommitsBetween baseCommit featureCommit + reverse <$> Backend.getCommitsBetween baseCommit featureCommit pure $ zipWith (,) commits (baseCommit : commits) else pure [(featureCommit, baseCommit)] @@ -63,7 +63,7 @@ formulatePlan perCommit baseBranch featureBranch = do fmap concat . forM commits $ \(commit, earlierCommit) -> map ((commit, earlierCommit),) . (: []) . (.fileDeltas) - <$> Git.diffOf earlierCommit commit + <$> Backend.diffOf earlierCommit commit pure Plan @@ -86,8 +86,8 @@ reviewStep step = do <$> sh ( proc "git log %..%" - (Git.toTextUnsafe step.earlierCommit) - (Git.toTextUnsafe step.commit) + (Backend.toTextUnsafe step.earlierCommit) + (Backend.toTextUnsafe step.commit) ) separateReview step.earlierCommit step.changes =<< reviewPatch commitMessages step.changes @@ -136,7 +136,7 @@ addComments = mapLines f x = x {D.hunkLines = map f x.hunkLines} separateReview :: - Git.CommitHash -> + Backend.CommitHash -> D.FileDeltas -> D.FileDeltas -> IO D.FileDeltas @@ -163,7 +163,7 @@ separateReview commit fileDeltas fileDeltas' = patchFile = "a.patch" patchFile' = "b.patch" -withTempSourceFiles :: Git.CommitHash -> D.FileDeltas -> (FilePath -> IO a) -> IO a +withTempSourceFiles :: Backend.CommitHash -> D.FileDeltas -> (FilePath -> IO a) -> IO a withTempSourceFiles commit fileDeltas action = do withSystemTempDirectory "anissue" $ \tmp -> do createDirectoryIfMissing False (tmp </> "a") @@ -173,8 +173,8 @@ withTempSourceFiles commit fileDeltas action = do fileContents <- if sourceFile /= "/dev/null" then case commit of - Git.Commit hash -> sh (proc "git show %:%" hash sourceFile) - Git.WorkingTree -> sh (proc "cat" sourceFile) + Backend.Commit hash -> sh (proc "git show %:%" hash sourceFile) + Backend.WorkingTree -> sh (proc "cat" sourceFile) else pure "" createDirectoryIfMissing True (tmp </> "a" </> sourceDir) LB.writeFile (tmp </> "a" </> sourceFile) fileContents @@ -209,11 +209,11 @@ commit_editmsg plan = do "#", "# review: approve " <> plan.featureBranch, "#", - "# Reviewed branch " <> plan.featureBranch <> " at commit " <> Git.toTextUnsafe plan.commit <> ".", + "# Reviewed branch " <> plan.featureBranch <> " at commit " <> Backend.toTextUnsafe plan.commit <> ".", "#", "# To requst changes, format your commit message like this:", "#", "# review: request-changes " <> plan.featureBranch, "#", - "# Reviewed branch " <> plan.featureBranch <> " at commit " <> Git.toTextUnsafe plan.commit <> "." + "# Reviewed branch " <> plan.featureBranch <> " at commit " <> Backend.toTextUnsafe plan.commit <> "." ] |