Skip to content

Commit dbd1bea

Browse files
committed
final cleanup
1 parent af0ce91 commit dbd1bea

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

cli/src/Oracle/Validate/Requests/TestRun/Create.hs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ module Oracle.Validate.Requests.TestRun.Create
99

1010
import Control.Monad (when)
1111
import Control.Monad.Trans.Class (lift)
12-
import Core.Types.Basic (Commit(..), Directory (..), Duration (..), Repository(..), Try (..), Username(..))
12+
import Core.Types.Basic
13+
( Commit (..)
14+
, Directory (..)
15+
, Duration (..)
16+
, Repository (..)
17+
, Try (..)
18+
, Username (..)
19+
)
1320
import Core.Types.Change (Change (..), Key (..))
1421
import Core.Types.Fact (Fact (..))
1522
import Core.Types.Operation (Op (..), Operation (..))
@@ -44,8 +51,8 @@ import Text.JSON.Canonical
4451
import User.Agent.Types (WhiteListKey (..))
4552
import User.Types
4653
( Phase (PendingT)
47-
, RegisterUserKey (..)
4854
, RegisterRoleKey (..)
55+
, RegisterUserKey (..)
4956
, TestRun (..)
5057
, TestRunState (..)
5158
, roleOfATestRun
@@ -119,17 +126,39 @@ data TestRunRejection
119126

120127
instance Monad m => ToJSON m TestRunRejection where
121128
toJSON (UnacceptableDuration minDuration maxDuration) =
122-
stringJSON $ "unacceptable duration. Expecting duration to be between "<> show minDuration <> " and "<>show maxDuration
123-
toJSON (UnacceptableCommit (Repository org repo) (Commit commit))=
124-
stringJSON $ "unacceptable commit. The specified commit "<> show commit<>" cannot be found in the repository "<>show org<>"/"<>show repo
125-
toJSON (UnacceptableTryIndex (Try maxIx))=
126-
stringJSON $ "unacceptable try index. Expecting at most "<>show maxIx<>" run attempts for a given commit"
127-
toJSON (UnacceptableRole (RegisterRoleKey _ (Repository org repo) (Username user)))=
128-
stringJSON $ "unacceptable role. User "<>show user<>" has not been registered within the repository "<>show org<>"/"<>show repo
129+
stringJSON
130+
$ "unacceptable duration. Expecting duration to be between "
131+
<> show minDuration
132+
<> " and "
133+
<> show maxDuration
134+
toJSON (UnacceptableCommit (Repository org repo) (Commit commit)) =
135+
stringJSON
136+
$ "unacceptable commit. The specified commit "
137+
<> show commit
138+
<> " cannot be found in the repository "
139+
<> show org
140+
<> "/"
141+
<> show repo
142+
toJSON (UnacceptableTryIndex (Try maxIx)) =
143+
stringJSON
144+
$ "unacceptable try index. Expecting at most "
145+
<> show maxIx
146+
<> " run attempts for a given commit"
147+
toJSON ( UnacceptableRole
148+
(RegisterRoleKey _ (Repository org repo) (Username user))
149+
) =
150+
stringJSON
151+
$ "unacceptable role. User "
152+
<> show user
153+
<> " has not been registered within the repository "
154+
<> show org
155+
<> "/"
156+
<> show repo
129157
toJSON NoRegisteredKeyVerifiesTheSignature =
130-
stringJSON "no registered key verifies the signature"
158+
stringJSON
159+
"there is no registered Ed25519 SSH key that can verify the signature"
131160
toJSON UserHasNoRegisteredSSHKeys =
132-
stringJSON "user has no Ed25519 registered SSH keys"
161+
stringJSON "user has no Ed25519 SSH key registered"
133162
toJSON (GithubResponseError err) =
134163
object ["githubResponseError" .= err]
135164
toJSON (GithubResponseStatusCodeError err) =
@@ -143,7 +172,7 @@ checkDuration
143172
:: TestRunValidationConfig -> Duration -> Maybe TestRunRejection
144173
checkDuration TestRunValidationConfig{maxDuration, minDuration} (Duration n)
145174
| n < minDuration || n > maxDuration =
146-
Just $ UnacceptableDuration minDuration maxDuration
175+
Just $ UnacceptableDuration minDuration maxDuration
147176
| otherwise = Nothing
148177

149178
checkRole

cli/test/Oracle/Validate/Requests/TestRun/CreateSpec.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ import Test.QuickCheck.EGen
9191
)
9292
import User.Agent.Types (WhiteListKey (..))
9393
import User.Types
94-
( TestRun (..)
94+
( RegisterRoleKey (..)
95+
, TestRun (..)
9596
, TestRunRejection (..)
9697
, TestRunState (..)
97-
, RegisterRoleKey(..)
9898
, URL (..)
9999
, tryIndexL
100100
)
@@ -252,7 +252,9 @@ spec = do
252252
testRunState
253253
let expectedMinDuration = minDuration testConfig
254254
let expectedMaxDuration = maxDuration testConfig
255-
onConditionHaveReason mresult (UnacceptableDuration expectedMinDuration expectedMaxDuration)
255+
onConditionHaveReason
256+
mresult
257+
(UnacceptableDuration expectedMinDuration expectedMaxDuration)
256258
$ duration < expectedMinDuration
257259
|| duration > expectedMaxDuration
258260

@@ -284,7 +286,11 @@ spec = do
284286
validation
285287
testRunRequest
286288
testRunState
287-
let role = RegisterRoleKey testRunRequest.platform testRunRequest.repository testRunRequest.requester
289+
let role =
290+
RegisterRoleKey
291+
testRunRequest.platform
292+
testRunRequest.repository
293+
testRunRequest.requester
288294
onConditionHaveReason mresult (UnacceptableRole role)
289295
$ testRunRequest.platform /= testRunFact.platform
290296
|| testRunRequest.repository.organization

0 commit comments

Comments
 (0)