diff options
Diffstat (limited to 'app/Review.hs')
-rw-r--r-- | app/Review.hs | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/app/Review.hs b/app/Review.hs index 91f4baf..e134a62 100644 --- a/app/Review.hs +++ b/app/Review.hs @@ -7,15 +7,11 @@ module Review ) where -import Control.Exception (SomeException, catch) import Control.Monad (ap, forM, forM_) import Data.Binary qualified as B import Data.ByteString.Lazy qualified as LB import Data.Function ((&)) import Data.List.NonEmpty qualified as NE -import Data.List.NonEmpty.Zipper qualified as Z -import Data.List.NonEmpty.Zipper.Extra () -import Data.Maybe (fromMaybe) import Data.Text qualified as T import Data.Text.Encoding qualified as T import Data.Text.IO qualified as T @@ -34,15 +30,14 @@ import Text.Diff.Parse.Types qualified as D data Plan = Plan { baseBranch :: BranchName, perCommit :: Bool, - steps :: Z.Zipper PlanStep + steps :: NE.NonEmpty PlanStep } deriving (Show, Generic, B.Binary) type BranchName = T.Text data PlanStep = PlanStep - { id :: [Int], - commit :: Git.CommitHash, + { commit :: Git.CommitHash, changes :: D.FileDeltas } deriving (Show, Generic, B.Binary) @@ -69,8 +64,7 @@ formulatePlan perCommit baseBranch featureBranch = do pure Plan { steps = - Z.fromNonEmpty . fromMaybe (error "TODO") . NE.nonEmpty $ - map (uncurry (PlanStep {- TODO -} [])) fileDeltas, + NE.fromList (map (uncurry PlanStep) fileDeltas), .. } @@ -78,20 +72,17 @@ reviewPatch :: D.FileDeltas -> IO D.FileDeltas reviewPatch fileDeltas = withSystemTempDirectory "anissue" $ \tmp -> do let patchFile = tmp </> "a.patch" - loop = - ( do - sh_ (proc "${EDITOR-vi} %" patchFile) - T.writeFile patchFile - . (renderAsText . A.Patch) - . addComments - . ((.fileDeltas) . A.parse) - =<< T.readFile patchFile - ((.fileDeltas) . A.parse . T.decodeUtf8 . LB.toStrict) - <$> sh (proc "recountdiff %" patchFile) - ) - `catch` (\(_ :: SomeException) -> loop) + patchFile' = tmp </> "b.patch" T.writeFile patchFile (renderAsText (A.Patch fileDeltas)) - loop + T.writeFile patchFile' (renderAsText (A.Patch fileDeltas)) + sh_ (proc "${EDITOR-vi} %" patchFile') + T.writeFile patchFile' + . (renderAsText . A.Patch) + . addComments + . ((.fileDeltas) . A.parse) + =<< T.readFile patchFile' + ((.fileDeltas) . A.parse . T.decodeUtf8 . LB.toStrict) + <$> sh (proc "rediff % %" patchFile patchFile') addComments :: D.FileDeltas -> D.FileDeltas addComments = |