aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-13 04:46:13 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-14 07:07:45 +0100
commitb9f4ee069228e80dda60bc10436693df0aee77ea (patch)
tree2e39d07d72b1349ab6c2d0ecf975d9329c6493c8 /app
parente7450765081e31341496a3f8ac91bda119b55f5a (diff)
chore: drop `Status`
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs40
-rw-r--r--app/Review.hs35
-rw-r--r--app/Status.hs122
3 files changed, 32 insertions, 165 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 634e085..0154840 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -322,6 +322,7 @@ import Control.Applicative ((<|>))
import Control.Exception (catch)
import Data.Function ((&))
import Data.List (find, intersperse)
+import Data.List.NonEmpty qualified as NE
import Data.Map qualified as M
import Data.Maybe (fromMaybe)
import Data.Text qualified as T
@@ -340,11 +341,12 @@ import Issue.Render ()
import Issue.Sort qualified as I
import Options.Applicative ((<**>))
import Options.Applicative qualified as O
+import Patch qualified as A
import Process (proc, sh_, textInput)
-import Render ((<<<))
+import Render (renderAsText, (<<<))
import Render qualified as P
+import Review qualified as R
import Settings (Settings (..), readSettings)
-import Status qualified as S
import System.Console.Terminal.Size qualified as Terminal
import System.Exit (ExitCode (ExitFailure), exitWith)
import System.FilePath ((</>))
@@ -427,7 +429,6 @@ data Command
| Open
{ id :: String
}
- | Status
| Review
{ baseBranch :: T.Text,
featureBranch :: T.Text,
@@ -459,8 +460,6 @@ cmd =
O.progDesc "List issues matching a pattern",
O.command "show" . O.info showCmd $
O.progDesc "Show details of all issues",
- O.command "status" . O.info statusCmd $
- O.progDesc "Describe the current anissue action.",
O.command "tags" . O.info tagsCmd $
O.progDesc "Show all tags"
]
@@ -532,10 +531,6 @@ patternArg =
(O.maybeReader R.compileRegex)
(O.metavar "PATTERN")
-statusCmd :: O.Parser Command
-statusCmd =
- pure Status
-
tagsCmd :: O.Parser Command
tagsCmd =
pure Tags
@@ -592,21 +587,24 @@ main :: IO ()
main = do
settings <- readSettings
O.execParser (O.info (options <**> O.helper) O.idm) >>= \case
- Options {colorize, noPager, width, command = Status} -> do
- status <- S.readStatus ".anissue/status"
- putDoc colorize noPager width status
- Options {colorize, noPager, width, command = Review {baseBranch, featureBranch, perCommit}} -> do
+ Options {command = Review {baseBranch, featureBranch, perCommit}} -> do
sh_ "test -z $(git status --porcelain --untracked-files=no)"
`catch` \(_ :: E.ProcessException) ->
error "working directory not clean, aborting.."
- S.withReviewing
- (putDoc colorize noPager width)
- perCommit
- baseBranch
- featureBranch
- ".anissue/status"
- S.continueReview
--- REVIEW Why is withReviewing in the Status module and not the Review module?
+ plan <- R.formulatePlan perCommit baseBranch featureBranch
+ patch <-
+ A.Patch . concat
+ <$> mapM
+ ( \step -> do
+ R.separateReview step.commit step.changes
+ =<< R.reviewPatch step.changes
+ )
+ (NE.toList plan.steps)
+ T.writeFile "review.patch" (renderAsText patch)
+ -- REVIEW Why is withReviewing in the Status module and not the Review
+ -- module?
+ --
+ -- RESOLVED `Status` has been dropped in this commit
Options {colorize, noPager, width, command = List {sort, filters, files, group = Just group, closed}} -> do
ungroupedIssues <-
I.applySorts sort
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 =
diff --git a/app/Status.hs b/app/Status.hs
deleted file mode 100644
index 13effa4..0000000
--- a/app/Status.hs
+++ /dev/null
@@ -1,122 +0,0 @@
-{-# LANGUAGE DerivingStrategies #-}
-
-module Status
- ( Status,
- writeStatus,
- readStatus,
- deleteStatus,
- withReviewing,
- continueReview,
- )
-where
-
-import Control.Exception (SomeException, catch)
-import Control.Monad.State (MonadState, StateT, get, put, runStateT)
-import Control.Monad.Trans (MonadIO, liftIO)
-import Control.Monad.Writer (MonadWriter, WriterT, runWriterT, tell)
-import Data.Binary qualified as B
-import Data.List.NonEmpty.Zipper qualified as Z
-import Data.List.NonEmpty.Zipper.Extra ()
-import Data.Text qualified as T
-import Data.Text.IO qualified as T
-import GHC.Generics (Generic)
-import Patch qualified as A
-import Render (Render, Summarized (Summarized), render, renderAsText, (<<<), (===))
-import Review qualified as R
-import System.Directory (removeFile)
-import Text.Diff.Extra ()
-import Text.Diff.Parse.Types qualified as D
-
-data Status = Reviewing {plan :: R.Plan, changes :: D.FileDeltas}
- deriving (Show, Generic, B.Binary)
-
-writeStatus :: FilePath -> Status -> IO ()
-writeStatus = B.encodeFile
-
-readStatus :: FilePath -> IO Status
-readStatus = B.decodeFile
-
-deleteStatus :: FilePath -> IO ()
-deleteStatus fp = removeFile fp
-
-instance Render Status where
- render (Reviewing {..}) =
- render ("review in progress\n" :: T.Text)
- <<< (render (" " :: T.Text) <<< render (Z.lefts plan.steps) <<< render ("\n" :: T.Text))
- <<< (render ("*" :: T.Text) <<< render (Z.current plan.steps) <<< render ("\n" :: T.Text))
- <<< (render (" " :: T.Text) <<< render (Z.rights plan.steps) <<< render ("\n" :: T.Text))
- <<< (render ("run `anissue review` to continue" :: T.Text))
-
-instance Render R.PlanStep where
- render (R.PlanStep {..}) =
- render id <<< render (Summarized commit)
-
-instance Render [R.PlanStep] where
- render [] = render ("" :: T.Text)
- render (x : xs) = render x === render xs
-
-instance Render [Int] where
- render [] = render ("[]" :: T.Text)
- render (x : xs) = render (show x) <<< render xs
-
-newtype ReviewingT m a = ReviewingT
- { runReviewingT :: StateT (Maybe R.Plan) (WriterT D.FileDeltas m) a
- }
- deriving newtype
- ( Functor,
- Applicative,
- Monad,
- MonadIO,
- MonadFail,
- MonadState (Maybe R.Plan),
- MonadWriter D.FileDeltas
- )
-
-type BranchName = T.Text
-
-withReviewing ::
- (forall a. Render a => a -> IO ()) ->
- Bool ->
- BranchName ->
- BranchName ->
- FilePath ->
- ReviewingT IO a ->
- IO a
-withReviewing putDoc perCommit baseBranch featureBranch fp action = do
- (plan, changes) <-
- (Just <$> readStatus fp)
- `catch` (\(_ :: SomeException) -> pure Nothing)
- >>= \case
- Nothing -> do
- plan <- R.formulatePlan perCommit baseBranch featureBranch
- let changes = []
- writeStatus fp $ Reviewing plan changes
- pure (plan, changes)
- Just (Reviewing plan changes) -> pure (plan, changes)
- ((result, maybePlan), ((++) changes) -> changes') <-
- runWriterT (runStateT (runReviewingT action) (Just plan))
- case maybePlan of
- Just plan' -> do
- let status' = Reviewing plan' changes'
- writeStatus fp status'
- putDoc status'
- Nothing -> do
- T.writeFile "review.patch" (renderAsText (A.Patch changes'))
- putDoc $
- render ("your review has been put into `review.patch`\n" :: T.Text)
- <<< render ("please apply it manually (`patch -p0 <review.patch`)" :: T.Text)
- deleteStatus fp
- pure result
-
-continueReview :: ReviewingT IO ()
-continueReview = do
- Just plan <- get
- let step = Z.current plan.steps
- tell
- =<< liftIO
- ( R.separateReview step.commit step.changes
- =<< R.reviewPatch step.changes
- )
- case Z.right plan.steps of
- Just steps' -> put $ Just $ plan {R.steps = steps'}
- Nothing -> put Nothing