From 0b3b675bfc9e78ee563d526f17184e317a962ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 5 Jul 2026 22:57:49 +0200 Subject: Move watch-branch test event to Expression module --- src/Command.hs | 6 +++--- src/Command/Run.hs | 2 -- src/Expression.hs | 11 ++++++++--- src/Output.hs | 5 +++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Command.hs b/src/Command.hs index 1ef52ed..452be9d 100644 --- a/src/Command.hs +++ b/src/Command.hs @@ -99,6 +99,9 @@ tfail err = liftIO $ do T.hPutStrLn stderr err exitFailure +instance MonadOutput CommandExec where + getOutput = CommandExec (asks ciOutput) + data CommandInput = CommandInput { ciOptions :: CommonOptions , ciRootPath :: FilePath @@ -148,8 +151,5 @@ cmdEvalWith :: (EvalInput -> EvalInput) -> Eval a -> CommandExec a cmdEvalWith f ev = do either (tfail . textEvalError) return =<< liftIO . runEval ev . f =<< getEvalInput -getOutput :: CommandExec Output -getOutput = CommandExec (asks ciOutput) - getStorageDir :: CommandExec FilePath getStorageDir = CommandExec (asks ciStorageDir) diff --git a/src/Command/Run.hs b/src/Command/Run.hs index d4c995f..b26c265 100644 --- a/src/Command/Run.hs +++ b/src/Command/Run.hs @@ -262,9 +262,7 @@ watchExpressionSource expr = do watchBranchSource :: Text -> CommandExec JobSource watchBranchSource branch = do repo <- getDefaultRepo - output <- getOutput expr <- evaluateDeclaredRange repo $ RangeExpression (WatchedRef branch) (StaticRef branch) - outputEvent output $ TestMessage $ "watch-branch-started " <> branch watchExpressionSource expr watchTagSource :: Pattern -> CommandExec JobSource diff --git a/src/Expression.hs b/src/Expression.hs index cd6c9dc..6b1adc9 100644 --- a/src/Expression.hs +++ b/src/Expression.hs @@ -19,6 +19,7 @@ import Data.Maybe import Data.Text (Text) import Job.Types +import Output import Repo @@ -62,13 +63,17 @@ textCommitRef :: CommitRef -> Text textCommitRef (CommitRef suffix cid) = textCommitId cid <> suffix -evaluateDeclaredRevision :: (MonadIO m, MonadFail m) => Repo -> DeclaredRevisionExpression -> m RevisionExpression +evaluateDeclaredRevision :: (MonadIO m, MonadFail m, MonadOutput m) => Repo -> DeclaredRevisionExpression -> m RevisionExpression evaluateDeclaredRevision repo = \case StaticRef ref -> StaticRef <$> readCommit repo ref - WatchedRef ref -> WatchedRef . BranchRef <$> watchBranch repo ref + WatchedRef ref -> do + watched <- watchBranch repo ref + output <- getOutput + outputEvent output $ TestMessage $ "watch-branch-started " <> ref + return $ WatchedRef $ BranchRef watched ModifiedRevision suffix rev -> ModifiedRevision suffix <$> evaluateDeclaredRevision repo rev -evaluateDeclaredRange :: (MonadIO m, MonadFail m) => Repo -> DeclaredRangeExpression -> m RangeExpression +evaluateDeclaredRange :: (MonadIO m, MonadFail m, MonadOutput m) => Repo -> DeclaredRangeExpression -> m RangeExpression evaluateDeclaredRange repo (RangeExpression a b) = RangeExpression <$> evaluateDeclaredRevision repo a <*> evaluateDeclaredRevision repo b diff --git a/src/Output.hs b/src/Output.hs index e9ce718..293f598 100644 --- a/src/Output.hs +++ b/src/Output.hs @@ -3,6 +3,7 @@ module Output ( OutputType(..), OutputEvent(..), OutputFootnote(..), + MonadOutput(..), withOutput, outputTerminal, @@ -56,6 +57,10 @@ data OutputFootnote = OutputFootnote deriving (Eq) +class Monad m => MonadOutput m where + getOutput :: m Output + + withOutput :: [ OutputType ] -> (Output -> IO a) -> IO a withOutput types inner = do lock <- newMVar () -- cgit v1.2.3