aboutsummaryrefslogtreecommitdiffstats
path: root/app/Main.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-14 07:10:03 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-14 07:10:03 +0100
commit11284c7c12c44e12de1cfc712c0391d5ee32a9f2 (patch)
tree553a527ff19f5ef105cbc2f026284e75fa5900db /app/Main.hs
parentc8ab97e77c8ab56b9835d9f260dc222a10e9b3c6 (diff)
parent09e26c37de7e7227d856ffe15c9554af36b50c58 (diff)
Merge remote-tracking branch 'origin/feature/review'main
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs82
1 files changed, 82 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 52a316d..f9fedea 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,3 +1,39 @@
+-- TODO Add `anissue review-comments`
+--
+-- The command `review-comments` should list all review comments within the current review.
+--
+-- @assigned aforemny
+-- @priority medium
+-- @topic review
+
+-- TODO `anissue review --base` should take own commits into account
+--
+-- To facilitate reviewing, the `--base` parameter of `anissue review` should implement some heuristic to review a set of changes multiple times.
+--
+-- The first time a review is performed, `--base` should default to the base branch. Any subsequent time, it should default to the last review commit added by myself.
+--
+-- @assigned aforemny
+-- @priority high
+-- @topic review
+
+-- TODO Add `anissue merge`
+--
+-- The command `anissue merge` should merge the currenlty checked out feature request, if there are no unresolved review comments.
+--
+-- If there are unresolved review comments, it should fail with a warning.
+--
+-- @assigned aforemny
+-- @priority high
+-- @topic review
+
+-- TODO Add `anissue request-review`
+--
+-- The command `request-review` should create an empty commit, stating that a review is requested. It should mention the eventual "base branch" for inclusion of the feature.
+--
+-- @assigned aforemny
+-- @priority high
+-- @topic review
+
-- TODO Compute history from the top
--
-- Currently we are computing the history from the bottom (ie. earliest commit
@@ -319,14 +355,17 @@ module Main where
import Comment qualified as G
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
import Data.Text.IO qualified as T
import Data.Text.Lazy qualified as LT
import Data.Text.Lazy.IO qualified as LT
+import Exception qualified as E
import Git qualified
import History qualified as H
import Issue (Issue (..))
@@ -338,9 +377,11 @@ 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 qualified as P
+import Review qualified as R
import Settings (Settings (..), readSettings)
import System.Console.Terminal.Size qualified as Terminal
import System.Exit (ExitCode (ExitFailure), exitWith)
@@ -424,6 +465,11 @@ data Command
| Open
{ id :: String
}
+ | Review
+ { baseBranch :: T.Text,
+ featureBranch :: T.Text,
+ perCommit :: Bool
+ }
| Search
{ pattern :: R.RE,
closed :: Bool,
@@ -444,6 +490,8 @@ cmd =
O.progDesc "Show a log of all issues",
O.command "open" . O.info openCmd $
O.progDesc "Open file containing an issue",
+ O.command "review" . O.info reviewCmd $
+ O.progDesc "Review changes",
O.command "search" . O.info searchCmd $
O.progDesc "List issues matching a pattern",
O.command "show" . O.info showCmd $
@@ -480,6 +528,33 @@ openCmd =
Open
<$> idArg
+reviewCmd :: O.Parser Command
+reviewCmd =
+ Review
+ <$> baseBranchArg
+ <*> featureBranchArg
+ <*> perCommitArg
+
+baseBranchArg :: O.Parser T.Text
+baseBranchArg =
+ O.strOption $
+ O.long "base"
+ <> O.short 'b'
+ <> O.metavar "BRANCH"
+ <> O.help "Base branch from which to review changes. Defaults to `main`."
+ <> O.value "main"
+
+featureBranchArg :: O.Parser T.Text
+featureBranchArg =
+ O.strArgument (O.metavar "BRANCH_NAME" <> O.value "HEAD")
+
+perCommitArg :: O.Parser Bool
+perCommitArg =
+ O.switch
+ ( O.long "per-commit"
+ <> O.help "Review commits individually. (Default: review combined patches)"
+ )
+
showCmd :: O.Parser Command
showCmd =
Show
@@ -548,6 +623,13 @@ main :: IO ()
main = do
settings <- readSettings
O.execParser (O.info (options <**> O.helper) O.idm) >>= \case
+ 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.."
+ plan <- R.formulatePlan perCommit baseBranch featureBranch
+ R.commitReview plan . A.Patch . concat
+ =<< mapM R.reviewStep (NE.toList plan.steps)
Options {colorize, noPager, width, command = List {sort, filters, files, group = Just group, closed}} -> do
ungroupedIssues <-
I.applySorts sort