diff options
Diffstat (limited to 'app/Review.hs')
-rw-r--r-- | app/Review.hs | 82 |
1 files changed, 6 insertions, 76 deletions
diff --git a/app/Review.hs b/app/Review.hs index e296cee..91f4baf 100644 --- a/app/Review.hs +++ b/app/Review.hs @@ -1,6 +1,5 @@ module Review ( Plan (..), - Granularity (..), PlanStep (..), formulatePlan, reviewPatch, @@ -12,8 +11,7 @@ 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 (on, (&)) -import Data.List (groupBy, sortOn) +import Data.Function ((&)) import Data.List.NonEmpty qualified as NE import Data.List.NonEmpty.Zipper qualified as Z import Data.List.NonEmpty.Zipper.Extra () @@ -32,54 +30,16 @@ import System.IO.Temp (withSystemTempDirectory) import System.Process.Typed qualified as P import Text.Diff.Extra () import Text.Diff.Parse.Types qualified as D -import Text.Read (Lexeme (Ident, Symbol), choice, lexP, readPrec) data Plan = Plan { baseBranch :: BranchName, - granularity :: Granularity, + perCommit :: Bool, steps :: Z.Zipper PlanStep } deriving (Show, Generic, B.Binary) type BranchName = T.Text -data Granularity - = AsOne - | PerCommit - | PerFile - | PerHunk - deriving (Eq, Ord, Generic, B.Binary) - -instance Show Granularity where - show AsOne = "as-one" - show PerCommit = "per-commit" - show PerFile = "per-file" - show PerHunk = "per-hunk" - -instance Read Granularity where - readPrec = - choice - [ do - Ident "as" <- lexP - Symbol "-" <- lexP - Ident "one" <- lexP - pure AsOne, - do - Ident "per" <- lexP - Symbol "-" <- lexP - choice - [ do - Ident "commit" <- lexP - pure PerCommit, - do - Ident "file" <- lexP - pure PerFile, - do - Ident "hunk" <- lexP - pure PerHunk - ] - ] - data PlanStep = PlanStep { id :: [Int], commit :: Git.CommitHash, @@ -87,13 +47,13 @@ data PlanStep = PlanStep } deriving (Show, Generic, B.Binary) -formulatePlan :: Granularity -> T.Text -> T.Text -> IO Plan -formulatePlan granularity baseBranch featureBranch = do +formulatePlan :: Bool -> T.Text -> T.Text -> IO Plan +formulatePlan perCommit baseBranch featureBranch = do baseCommit <- Git.resolveRef baseBranch featureCommit <- Git.resolveRef featureBranch commits <- - if granularity >= PerCommit + if perCommit then do commits <- reverse <$> Git.getCommitsBetween baseCommit featureCommit @@ -103,12 +63,7 @@ formulatePlan granularity baseBranch featureBranch = do fileDeltas <- fmap concat . forM commits $ \(commit, earlierCommit) -> - map (earlierCommit,) - . if - | granularity >= PerHunk -> splitPerHunk - | granularity >= PerFile -> splitPerFile - | otherwise -> (: []) - . (.fileDeltas) + map (earlierCommit,) . (: []) . (.fileDeltas) <$> Git.diffOf earlierCommit commit pure @@ -119,31 +74,6 @@ formulatePlan granularity baseBranch featureBranch = do .. } -splitPerFile :: D.FileDeltas -> [D.FileDeltas] -splitPerFile = - groupBy - ((==) `on` (.fileDeltaSourceFile)) - . sortOn (.fileDeltaSourceFile) - -splitPerHunk :: D.FileDeltas -> [D.FileDeltas] -splitPerHunk = - concatMap - ( \fileDeltas -> - [ hunkToFileDeltas fileDelta hunk - | fileDelta <- fileDeltas, - let D.Hunks hunks = fileDelta.fileDeltaContent, - hunk <- hunks - ] - ) - . splitPerFile - -hunkToFileDeltas :: D.FileDelta -> D.Hunk -> D.FileDeltas -hunkToFileDeltas fileDelta hunk = - [ fileDelta - { D.fileDeltaContent = D.Hunks [hunk] - } - ] - reviewPatch :: D.FileDeltas -> IO D.FileDeltas reviewPatch fileDeltas = withSystemTempDirectory "anissue" $ \tmp -> do |