Skip to content

Commit af0ce91

Browse files
committed
improve reporting of UnacceptableRole
1 parent a3e8b04 commit af0ce91

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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 (..))
12+
import Core.Types.Basic (Commit(..), Directory (..), Duration (..), Repository(..), Try (..), Username(..))
1313
import Core.Types.Change (Change (..), Key (..))
1414
import Core.Types.Fact (Fact (..))
1515
import Core.Types.Operation (Op (..), Operation (..))
@@ -45,6 +45,7 @@ import User.Agent.Types (WhiteListKey (..))
4545
import User.Types
4646
( Phase (PendingT)
4747
, RegisterUserKey (..)
48+
, RegisterRoleKey (..)
4849
, TestRun (..)
4950
, TestRunState (..)
5051
, roleOfATestRun
@@ -107,7 +108,7 @@ data TestRunRejection
107108
= UnacceptableDuration Int Int
108109
| UnacceptableCommit Repository Commit
109110
| UnacceptableTryIndex Try
110-
| UnacceptableRole
111+
| UnacceptableRole RegisterRoleKey
111112
| NoRegisteredKeyVerifiesTheSignature
112113
| UserHasNoRegisteredSSHKeys
113114
| GithubResponseError GithubResponseError
@@ -123,8 +124,8 @@ instance Monad m => ToJSON m TestRunRejection where
123124
stringJSON $ "unacceptable commit. The specified commit "<> show commit<>" cannot be found in the repository "<>show org<>"/"<>show repo
124125
toJSON (UnacceptableTryIndex (Try maxIx))=
125126
stringJSON $ "unacceptable try index. Expecting at most "<>show maxIx<>" run attempts for a given commit"
126-
toJSON UnacceptableRole =
127-
stringJSON "unacceptable role"
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
128129
toJSON NoRegisteredKeyVerifiesTheSignature =
129130
stringJSON "no registered key verifies the signature"
130131
toJSON UserHasNoRegisteredSSHKeys =
@@ -154,7 +155,7 @@ checkRole
154155
let roleFact = roleOfATestRun testRun
155156
if Fact roleFact () `elem` fs
156157
then return Nothing
157-
else return $ Just UnacceptableRole
158+
else return $ Just (UnacceptableRole roleFact)
158159

159160
checkWhiteList
160161
:: Monad m

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import User.Types
9494
( TestRun (..)
9595
, TestRunRejection (..)
9696
, TestRunState (..)
97+
, RegisterRoleKey(..)
9798
, URL (..)
9899
, tryIndexL
99100
)
@@ -269,10 +270,10 @@ spec = do
269270
, changeProject testRunRequest
270271
, pure testRunRequest
271272
]
272-
role <- jsFactRole testRunFact
273+
roleFact <- jsFactRole testRunFact
273274
let validation =
274275
mkValidation
275-
(withFacts [role] mockMPFS)
276+
(withFacts [roleFact] mockMPFS)
276277
noValidation
277278
testRunState = Pending (Duration duration) signature
278279
pure $ do
@@ -283,7 +284,8 @@ spec = do
283284
validation
284285
testRunRequest
285286
testRunState
286-
onConditionHaveReason mresult UnacceptableRole
287+
let role = RegisterRoleKey testRunRequest.platform testRunRequest.repository testRunRequest.requester
288+
onConditionHaveReason mresult (UnacceptableRole role)
287289
$ testRunRequest.platform /= testRunFact.platform
288290
|| testRunRequest.repository.organization
289291
/= testRunFact.repository.organization

0 commit comments

Comments
 (0)