Skip to content

Commit 2f328d0

Browse files
committed
[cli] internal: add mkTestRunId function
1 parent b9fc1a4 commit 2f328d0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cli/src/User/Agent/Types.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ module User.Agent.Types
33
, TestRunMap (..)
44
, WhiteListKey (..)
55
, TestRunId (..)
6+
, mkTestRunId
7+
, testRunIdFromFact
68
) where
79

810
import Control.Monad (unless)
911
import Core.Types.Basic (Platform, Repository)
10-
import Core.Types.Fact (Fact)
12+
import Core.Types.Fact (Fact (..), keyHash)
13+
import Data.Functor.Identity (Identity (..))
1114
import Lib.JSON.Canonical.Extra (object, withObject, (.:), (.=))
1215
import Text.JSON.Canonical
1316
( FromJSON (..)
@@ -22,6 +25,11 @@ import User.Types (Phase (..), TestRun, TestRunState)
2225
newtype TestRunId = TestRunId {testRunId :: String}
2326
deriving (Show, Eq)
2427

28+
mkTestRunId :: ToJSON Identity key => key -> TestRunId
29+
mkTestRunId = TestRunId . runIdentity . keyHash
30+
31+
testRunIdFromFact :: Fact TestRun v -> TestRunId
32+
testRunIdFromFact = mkTestRunId . factKey
2533
instance Monad m => ToJSON m TestRunId where
2634
toJSON (TestRunId hash) =
2735
pure $ JSString $ toJSString hash

0 commit comments

Comments
 (0)