{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Stack.Types.Curator
  ( Curator (..)
  ) where

import           Data.Aeson.Types ( FromJSON (..), ToJSON (..), (.=), object )
import           Data.Aeson.WarningParser
                   ( WithJSONWarnings (..), (..:?), (..!=), withObjectWarnings )
import qualified Data.Set as Set
import           Stack.Prelude

-- | Extra configuration intended exclusively for usage by the curator tool. In

-- other words, this is /not/ part of the documented and exposed Stack API.

-- SUBJECT TO CHANGE.

data Curator = Curator
  { Curator -> Set PackageName
curatorSkipTest :: !(Set PackageName)
  , Curator -> Set PackageName
curatorExpectTestFailure :: !(Set PackageName)
  , Curator -> Set PackageName
curatorSkipBenchmark :: !(Set PackageName)
  , Curator -> Set PackageName
curatorExpectBenchmarkFailure :: !(Set PackageName)
  , Curator -> Set PackageName
curatorSkipHaddock :: !(Set PackageName)
  , Curator -> Set PackageName
curatorExpectHaddockFailure :: !(Set PackageName)
  }
  deriving Int -> Curator -> ShowS
[Curator] -> ShowS
Curator -> String
(Int -> Curator -> ShowS)
-> (Curator -> String) -> ([Curator] -> ShowS) -> Show Curator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Curator -> ShowS
showsPrec :: Int -> Curator -> ShowS
$cshow :: Curator -> String
show :: Curator -> String
$cshowList :: [Curator] -> ShowS
showList :: [Curator] -> ShowS
Show

instance ToJSON Curator where
  toJSON :: Curator -> Value
toJSON Curator
c = [Pair] -> Value
object
    [ Key
"skip-test" Key -> Set (CabalString PackageName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= (PackageName -> CabalString PackageName)
-> Set PackageName -> Set (CabalString PackageName)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map PackageName -> CabalString PackageName
forall a. a -> CabalString a
CabalString (Curator -> Set PackageName
curatorSkipTest Curator
c)
    , Key
"expect-test-failure" Key -> Set (CabalString PackageName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= (PackageName -> CabalString PackageName)
-> Set PackageName -> Set (CabalString PackageName)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map PackageName -> CabalString PackageName
forall a. a -> CabalString a
CabalString (Curator -> Set PackageName
curatorExpectTestFailure Curator
c)
    , Key
"skip-bench" Key -> Set (CabalString PackageName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= (PackageName -> CabalString PackageName)
-> Set PackageName -> Set (CabalString PackageName)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map PackageName -> CabalString PackageName
forall a. a -> CabalString a
CabalString (Curator -> Set PackageName
curatorSkipBenchmark Curator
c)
    , Key
"expect-benchmark-failure" Key -> Set (CabalString PackageName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.=
        (PackageName -> CabalString PackageName)
-> Set PackageName -> Set (CabalString PackageName)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map PackageName -> CabalString PackageName
forall a. a -> CabalString a
CabalString (Curator -> Set PackageName
curatorExpectTestFailure Curator
c)
    , Key
"skip-haddock" Key -> Set (CabalString PackageName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= (PackageName -> CabalString PackageName)
-> Set PackageName -> Set (CabalString PackageName)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map PackageName -> CabalString PackageName
forall a. a -> CabalString a
CabalString (Curator -> Set PackageName
curatorSkipHaddock Curator
c)
    , Key
"expect-test-failure" Key -> Set (CabalString PackageName) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.=
        (PackageName -> CabalString PackageName)
-> Set PackageName -> Set (CabalString PackageName)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map PackageName -> CabalString PackageName
forall a. a -> CabalString a
CabalString (Curator -> Set PackageName
curatorExpectHaddockFailure Curator
c)
    ]

instance FromJSON (WithJSONWarnings Curator) where
  parseJSON :: Value -> Parser (WithJSONWarnings Curator)
parseJSON = String
-> (Object -> WarningParser Curator)
-> Value
-> Parser (WithJSONWarnings Curator)
forall a.
String
-> (Object -> WarningParser a)
-> Value
-> Parser (WithJSONWarnings a)
withObjectWarnings String
"Curator" ((Object -> WarningParser Curator)
 -> Value -> Parser (WithJSONWarnings Curator))
-> (Object -> WarningParser Curator)
-> Value
-> Parser (WithJSONWarnings Curator)
forall a b. (a -> b) -> a -> b
$ \Object
o -> Set PackageName
-> Set PackageName
-> Set PackageName
-> Set PackageName
-> Set PackageName
-> Set PackageName
-> Curator
Curator
    (Set PackageName
 -> Set PackageName
 -> Set PackageName
 -> Set PackageName
 -> Set PackageName
 -> Set PackageName
 -> Curator)
-> WriterT WarningParserMonoid Parser (Set PackageName)
-> WriterT
     WarningParserMonoid
     Parser
     (Set PackageName
      -> Set PackageName
      -> Set PackageName
      -> Set PackageName
      -> Set PackageName
      -> Curator)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Set (CabalString PackageName) -> Set PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
-> WriterT WarningParserMonoid Parser (Set PackageName)
forall a b.
(a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CabalString PackageName -> PackageName)
-> Set (CabalString PackageName) -> Set PackageName
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map CabalString PackageName -> PackageName
forall a. CabalString a -> a
unCabalString) (Object
o Object
-> Text -> WarningParser (Maybe (Set (CabalString PackageName)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"skip-test" WarningParser (Maybe (Set (CabalString PackageName)))
-> Set (CabalString PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Set (CabalString PackageName)
forall a. Monoid a => a
mempty)
    WriterT
  WarningParserMonoid
  Parser
  (Set PackageName
   -> Set PackageName
   -> Set PackageName
   -> Set PackageName
   -> Set PackageName
   -> Curator)
-> WriterT WarningParserMonoid Parser (Set PackageName)
-> WriterT
     WarningParserMonoid
     Parser
     (Set PackageName
      -> Set PackageName
      -> Set PackageName
      -> Set PackageName
      -> Curator)
forall a b.
WriterT WarningParserMonoid Parser (a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Set (CabalString PackageName) -> Set PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
-> WriterT WarningParserMonoid Parser (Set PackageName)
forall a b.
(a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CabalString PackageName -> PackageName)
-> Set (CabalString PackageName) -> Set PackageName
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map CabalString PackageName -> PackageName
forall a. CabalString a -> a
unCabalString) (Object
o Object
-> Text -> WarningParser (Maybe (Set (CabalString PackageName)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"expect-test-failure" WarningParser (Maybe (Set (CabalString PackageName)))
-> Set (CabalString PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Set (CabalString PackageName)
forall a. Monoid a => a
mempty)
    WriterT
  WarningParserMonoid
  Parser
  (Set PackageName
   -> Set PackageName
   -> Set PackageName
   -> Set PackageName
   -> Curator)
-> WriterT WarningParserMonoid Parser (Set PackageName)
-> WriterT
     WarningParserMonoid
     Parser
     (Set PackageName -> Set PackageName -> Set PackageName -> Curator)
forall a b.
WriterT WarningParserMonoid Parser (a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Set (CabalString PackageName) -> Set PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
-> WriterT WarningParserMonoid Parser (Set PackageName)
forall a b.
(a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CabalString PackageName -> PackageName)
-> Set (CabalString PackageName) -> Set PackageName
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map CabalString PackageName -> PackageName
forall a. CabalString a -> a
unCabalString) (Object
o Object
-> Text -> WarningParser (Maybe (Set (CabalString PackageName)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"skip-bench" WarningParser (Maybe (Set (CabalString PackageName)))
-> Set (CabalString PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Set (CabalString PackageName)
forall a. Monoid a => a
mempty)
    WriterT
  WarningParserMonoid
  Parser
  (Set PackageName -> Set PackageName -> Set PackageName -> Curator)
-> WriterT WarningParserMonoid Parser (Set PackageName)
-> WriterT
     WarningParserMonoid
     Parser
     (Set PackageName -> Set PackageName -> Curator)
forall a b.
WriterT WarningParserMonoid Parser (a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Set (CabalString PackageName) -> Set PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
-> WriterT WarningParserMonoid Parser (Set PackageName)
forall a b.
(a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CabalString PackageName -> PackageName)
-> Set (CabalString PackageName) -> Set PackageName
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map CabalString PackageName -> PackageName
forall a. CabalString a -> a
unCabalString) (Object
o Object
-> Text -> WarningParser (Maybe (Set (CabalString PackageName)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"expect-benchmark-failure" WarningParser (Maybe (Set (CabalString PackageName)))
-> Set (CabalString PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Set (CabalString PackageName)
forall a. Monoid a => a
mempty)
    WriterT
  WarningParserMonoid
  Parser
  (Set PackageName -> Set PackageName -> Curator)
-> WriterT WarningParserMonoid Parser (Set PackageName)
-> WriterT WarningParserMonoid Parser (Set PackageName -> Curator)
forall a b.
WriterT WarningParserMonoid Parser (a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Set (CabalString PackageName) -> Set PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
-> WriterT WarningParserMonoid Parser (Set PackageName)
forall a b.
(a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CabalString PackageName -> PackageName)
-> Set (CabalString PackageName) -> Set PackageName
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map CabalString PackageName -> PackageName
forall a. CabalString a -> a
unCabalString) (Object
o Object
-> Text -> WarningParser (Maybe (Set (CabalString PackageName)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"skip-haddock" WarningParser (Maybe (Set (CabalString PackageName)))
-> Set (CabalString PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Set (CabalString PackageName)
forall a. Monoid a => a
mempty)
    WriterT WarningParserMonoid Parser (Set PackageName -> Curator)
-> WriterT WarningParserMonoid Parser (Set PackageName)
-> WarningParser Curator
forall a b.
WriterT WarningParserMonoid Parser (a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Set (CabalString PackageName) -> Set PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
-> WriterT WarningParserMonoid Parser (Set PackageName)
forall a b.
(a -> b)
-> WriterT WarningParserMonoid Parser a
-> WriterT WarningParserMonoid Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((CabalString PackageName -> PackageName)
-> Set (CabalString PackageName) -> Set PackageName
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map CabalString PackageName -> PackageName
forall a. CabalString a -> a
unCabalString) (Object
o Object
-> Text -> WarningParser (Maybe (Set (CabalString PackageName)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"expect-haddock-failure" WarningParser (Maybe (Set (CabalString PackageName)))
-> Set (CabalString PackageName)
-> WriterT
     WarningParserMonoid Parser (Set (CabalString PackageName))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Set (CabalString PackageName)
forall a. Monoid a => a
mempty)