@@ -32,6 +32,7 @@ import Data.ByteString.Lazy (toStrict)
32
32
import Data.String (fromString )
33
33
import Data.Maybe
34
34
import Distribution.Compiler ( CompilerId (.. ) )
35
+ import Data.Aeson (toJSON )
35
36
36
37
37
38
-- TODO:
@@ -47,6 +48,7 @@ data ReportsFeature = ReportsFeature {
47
48
queryBuildLog :: forall m . MonadIO m => BuildLog -> m Resource. BuildLog ,
48
49
pkgReportDetails :: forall m . MonadIO m => (PackageIdentifier , Bool ) -> m BuildReport. PkgDetails ,
49
50
queryLastReportStats :: forall m . MonadIO m => PackageIdentifier -> m (Maybe (BuildReportId , BuildReport , Maybe BuildCovg )),
51
+ queryRunTests :: forall m . MonadIO m => PackageId -> m Bool ,
50
52
reportsResource :: ReportsResource
51
53
}
52
54
@@ -59,6 +61,7 @@ data ReportsResource = ReportsResource {
59
61
reportsPage :: Resource ,
60
62
reportsLog :: Resource ,
61
63
reportsReset :: Resource ,
64
+ reportsTest :: Resource ,
62
65
reportsListUri :: String -> PackageId -> String ,
63
66
reportsPageUri :: String -> PackageId -> BuildReportId -> String ,
64
67
reportsLogUri :: PackageId -> BuildReportId -> String
@@ -119,6 +122,7 @@ buildReportsFeature name
119
122
, reportsPage
120
123
, reportsLog
121
124
, reportsReset
125
+ , reportsTest
122
126
]
123
127
, featureState = [abstractAcidStateComponent reportsState]
124
128
}
@@ -140,6 +144,13 @@ buildReportsFeature name
140
144
]
141
145
, resourceGet = [ (" " , resetBuildFails) ]
142
146
}
147
+ , reportsTest = (extendResourcePath " /reports/test/" corePackagePage) {
148
+ resourceDesc = [ (GET , " Get reports test settings" )
149
+ , (POST , " Set reports test settings" )
150
+ ]
151
+ , resourceGet = [ (" json" , getReportsTest) ]
152
+ , resourcePost = [ (" " , postReportsTest) ]
153
+ }
143
154
, reportsPage = (extendResourcePath " /reports/:id.:format" corePackagePage) {
144
155
resourceDesc = [ (GET , " Get a specific build report" )
145
156
, (DELETE , " Delete a specific build report" )
@@ -201,12 +212,13 @@ buildReportsFeature name
201
212
pkgReportDetails (pkgid, docs) = do
202
213
failCnt <- queryState reportsState $ LookupFailCount pkgid
203
214
latestRpt <- queryState reportsState $ LookupLatestReport pkgid
215
+ runTests <- fmap Just . queryState reportsState $ LookupRunTests pkgid
204
216
(time, ghcId) <- case latestRpt of
205
217
Nothing -> return (Nothing ,Nothing )
206
218
Just (_, brp, _, _) -> do
207
219
let (CompilerId _ vrsn) = compiler brp
208
220
return (time brp, Just vrsn)
209
- return (BuildReport. PkgDetails pkgid docs failCnt time ghcId)
221
+ return (BuildReport. PkgDetails pkgid docs failCnt time ghcId runTests )
210
222
211
223
queryLastReportStats :: MonadIO m => PackageIdentifier -> m (Maybe (BuildReportId , BuildReport , Maybe BuildCovg ))
212
224
queryLastReportStats pkgid = do
@@ -215,6 +227,8 @@ buildReportsFeature name
215
227
Nothing -> return Nothing
216
228
Just (rptId, rpt, _, covg) -> return (Just (rptId, rpt, covg))
217
229
230
+ queryRunTests :: MonadIO m => PackageId -> m Bool
231
+ queryRunTests pkgid = queryState reportsState $ LookupRunTests pkgid
218
232
219
233
---------------------------------------------------------------------------
220
234
@@ -318,6 +332,25 @@ buildReportsFeature name
318
332
then seeOther (reportsListUri reportsResource " " pkgid) $ toResponse ()
319
333
else errNotFound " Report not found" [MText " Build report does not exist" ]
320
334
335
+ getReportsTest :: DynamicPath -> ServerPartE Response
336
+ getReportsTest dpath = do
337
+ pkgid <- packageInPath dpath
338
+ guardValidPackageId pkgid
339
+ guardAuthorisedAsMaintainerOrTrustee (packageName pkgid)
340
+ runTest <- queryRunTests pkgid
341
+ pure $ toResponse $ toJSON runTest
342
+
343
+ postReportsTest :: DynamicPath -> ServerPartE Response
344
+ postReportsTest dpath = do
345
+ pkgid <- packageInPath dpath
346
+ runTests <- body $ looks " runTests"
347
+ guardValidPackageId pkgid
348
+ guardAuthorisedAsMaintainerOrTrustee (packageName pkgid)
349
+ success <- updateState reportsState $ SetRunTests pkgid (" on" `elem` runTests)
350
+ if success
351
+ then seeOther (reportsListUri reportsResource " " pkgid) $ toResponse ()
352
+ else errNotFound " Package not found" [MText " Package does not exist" ]
353
+
321
354
322
355
putAllReports :: DynamicPath -> ServerPartE Response
323
356
putAllReports dpath = do
0 commit comments