summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-07-05 22:57:49 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-07-09 19:45:40 +0200
commit0b3b675bfc9e78ee563d526f17184e317a962ae8 (patch)
treed88a9a768338435cdcc4d316902b3dba30dbb397
parent439481ad37868c732fa68fc31b65c581d0dcd7fa (diff)
Move watch-branch test event to Expression moduleHEADmaster
-rw-r--r--src/Command.hs6
-rw-r--r--src/Command/Run.hs2
-rw-r--r--src/Expression.hs11
-rw-r--r--src/Output.hs5
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 ()