{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeCommit.Types.RepositoryTrigger
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeCommit.Types.RepositoryTrigger where

import Amazonka.CodeCommit.Types.RepositoryTriggerEventEnum
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a trigger for a repository.
--
-- /See:/ 'newRepositoryTrigger' smart constructor.
data RepositoryTrigger = RepositoryTrigger'
  { -- | The branches to be included in the trigger configuration. If you specify
    -- an empty array, the trigger applies to all branches.
    --
    -- Although no content is required in the array, you must include the array
    -- itself.
    RepositoryTrigger -> Maybe [Text]
branches :: Prelude.Maybe [Prelude.Text],
    -- | Any custom data associated with the trigger to be included in the
    -- information sent to the target of the trigger.
    RepositoryTrigger -> Maybe Text
customData :: Prelude.Maybe Prelude.Text,
    -- | The name of the trigger.
    RepositoryTrigger -> Text
name :: Prelude.Text,
    -- | The ARN of the resource that is the target for a trigger (for example,
    -- the ARN of a topic in Amazon SNS).
    RepositoryTrigger -> Text
destinationArn :: Prelude.Text,
    -- | The repository events that cause the trigger to run actions in another
    -- service, such as sending a notification through Amazon SNS.
    --
    -- The valid value \"all\" cannot be used with any other values.
    RepositoryTrigger -> [RepositoryTriggerEventEnum]
events :: [RepositoryTriggerEventEnum]
  }
  deriving (RepositoryTrigger -> RepositoryTrigger -> Bool
(RepositoryTrigger -> RepositoryTrigger -> Bool)
-> (RepositoryTrigger -> RepositoryTrigger -> Bool)
-> Eq RepositoryTrigger
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RepositoryTrigger -> RepositoryTrigger -> Bool
$c/= :: RepositoryTrigger -> RepositoryTrigger -> Bool
== :: RepositoryTrigger -> RepositoryTrigger -> Bool
$c== :: RepositoryTrigger -> RepositoryTrigger -> Bool
Prelude.Eq, ReadPrec [RepositoryTrigger]
ReadPrec RepositoryTrigger
Int -> ReadS RepositoryTrigger
ReadS [RepositoryTrigger]
(Int -> ReadS RepositoryTrigger)
-> ReadS [RepositoryTrigger]
-> ReadPrec RepositoryTrigger
-> ReadPrec [RepositoryTrigger]
-> Read RepositoryTrigger
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RepositoryTrigger]
$creadListPrec :: ReadPrec [RepositoryTrigger]
readPrec :: ReadPrec RepositoryTrigger
$creadPrec :: ReadPrec RepositoryTrigger
readList :: ReadS [RepositoryTrigger]
$creadList :: ReadS [RepositoryTrigger]
readsPrec :: Int -> ReadS RepositoryTrigger
$creadsPrec :: Int -> ReadS RepositoryTrigger
Prelude.Read, Int -> RepositoryTrigger -> ShowS
[RepositoryTrigger] -> ShowS
RepositoryTrigger -> String
(Int -> RepositoryTrigger -> ShowS)
-> (RepositoryTrigger -> String)
-> ([RepositoryTrigger] -> ShowS)
-> Show RepositoryTrigger
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RepositoryTrigger] -> ShowS
$cshowList :: [RepositoryTrigger] -> ShowS
show :: RepositoryTrigger -> String
$cshow :: RepositoryTrigger -> String
showsPrec :: Int -> RepositoryTrigger -> ShowS
$cshowsPrec :: Int -> RepositoryTrigger -> ShowS
Prelude.Show, (forall x. RepositoryTrigger -> Rep RepositoryTrigger x)
-> (forall x. Rep RepositoryTrigger x -> RepositoryTrigger)
-> Generic RepositoryTrigger
forall x. Rep RepositoryTrigger x -> RepositoryTrigger
forall x. RepositoryTrigger -> Rep RepositoryTrigger x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RepositoryTrigger x -> RepositoryTrigger
$cfrom :: forall x. RepositoryTrigger -> Rep RepositoryTrigger x
Prelude.Generic)

-- |
-- Create a value of 'RepositoryTrigger' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'branches', 'repositoryTrigger_branches' - The branches to be included in the trigger configuration. If you specify
-- an empty array, the trigger applies to all branches.
--
-- Although no content is required in the array, you must include the array
-- itself.
--
-- 'customData', 'repositoryTrigger_customData' - Any custom data associated with the trigger to be included in the
-- information sent to the target of the trigger.
--
-- 'name', 'repositoryTrigger_name' - The name of the trigger.
--
-- 'destinationArn', 'repositoryTrigger_destinationArn' - The ARN of the resource that is the target for a trigger (for example,
-- the ARN of a topic in Amazon SNS).
--
-- 'events', 'repositoryTrigger_events' - The repository events that cause the trigger to run actions in another
-- service, such as sending a notification through Amazon SNS.
--
-- The valid value \"all\" cannot be used with any other values.
newRepositoryTrigger ::
  -- | 'name'
  Prelude.Text ->
  -- | 'destinationArn'
  Prelude.Text ->
  RepositoryTrigger
newRepositoryTrigger :: Text -> Text -> RepositoryTrigger
newRepositoryTrigger Text
pName_ Text
pDestinationArn_ =
  RepositoryTrigger' :: Maybe [Text]
-> Maybe Text
-> Text
-> Text
-> [RepositoryTriggerEventEnum]
-> RepositoryTrigger
RepositoryTrigger'
    { $sel:branches:RepositoryTrigger' :: Maybe [Text]
branches = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:customData:RepositoryTrigger' :: Maybe Text
customData = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:RepositoryTrigger' :: Text
name = Text
pName_,
      $sel:destinationArn:RepositoryTrigger' :: Text
destinationArn = Text
pDestinationArn_,
      $sel:events:RepositoryTrigger' :: [RepositoryTriggerEventEnum]
events = [RepositoryTriggerEventEnum]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The branches to be included in the trigger configuration. If you specify
-- an empty array, the trigger applies to all branches.
--
-- Although no content is required in the array, you must include the array
-- itself.
repositoryTrigger_branches :: Lens.Lens' RepositoryTrigger (Prelude.Maybe [Prelude.Text])
repositoryTrigger_branches :: (Maybe [Text] -> f (Maybe [Text]))
-> RepositoryTrigger -> f RepositoryTrigger
repositoryTrigger_branches = (RepositoryTrigger -> Maybe [Text])
-> (RepositoryTrigger -> Maybe [Text] -> RepositoryTrigger)
-> Lens
     RepositoryTrigger RepositoryTrigger (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepositoryTrigger' {Maybe [Text]
branches :: Maybe [Text]
$sel:branches:RepositoryTrigger' :: RepositoryTrigger -> Maybe [Text]
branches} -> Maybe [Text]
branches) (\s :: RepositoryTrigger
s@RepositoryTrigger' {} Maybe [Text]
a -> RepositoryTrigger
s {$sel:branches:RepositoryTrigger' :: Maybe [Text]
branches = Maybe [Text]
a} :: RepositoryTrigger) ((Maybe [Text] -> f (Maybe [Text]))
 -> RepositoryTrigger -> f RepositoryTrigger)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> RepositoryTrigger
-> f RepositoryTrigger
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Any custom data associated with the trigger to be included in the
-- information sent to the target of the trigger.
repositoryTrigger_customData :: Lens.Lens' RepositoryTrigger (Prelude.Maybe Prelude.Text)
repositoryTrigger_customData :: (Maybe Text -> f (Maybe Text))
-> RepositoryTrigger -> f RepositoryTrigger
repositoryTrigger_customData = (RepositoryTrigger -> Maybe Text)
-> (RepositoryTrigger -> Maybe Text -> RepositoryTrigger)
-> Lens
     RepositoryTrigger RepositoryTrigger (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepositoryTrigger' {Maybe Text
customData :: Maybe Text
$sel:customData:RepositoryTrigger' :: RepositoryTrigger -> Maybe Text
customData} -> Maybe Text
customData) (\s :: RepositoryTrigger
s@RepositoryTrigger' {} Maybe Text
a -> RepositoryTrigger
s {$sel:customData:RepositoryTrigger' :: Maybe Text
customData = Maybe Text
a} :: RepositoryTrigger)

-- | The name of the trigger.
repositoryTrigger_name :: Lens.Lens' RepositoryTrigger Prelude.Text
repositoryTrigger_name :: (Text -> f Text) -> RepositoryTrigger -> f RepositoryTrigger
repositoryTrigger_name = (RepositoryTrigger -> Text)
-> (RepositoryTrigger -> Text -> RepositoryTrigger)
-> Lens RepositoryTrigger RepositoryTrigger Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepositoryTrigger' {Text
name :: Text
$sel:name:RepositoryTrigger' :: RepositoryTrigger -> Text
name} -> Text
name) (\s :: RepositoryTrigger
s@RepositoryTrigger' {} Text
a -> RepositoryTrigger
s {$sel:name:RepositoryTrigger' :: Text
name = Text
a} :: RepositoryTrigger)

-- | The ARN of the resource that is the target for a trigger (for example,
-- the ARN of a topic in Amazon SNS).
repositoryTrigger_destinationArn :: Lens.Lens' RepositoryTrigger Prelude.Text
repositoryTrigger_destinationArn :: (Text -> f Text) -> RepositoryTrigger -> f RepositoryTrigger
repositoryTrigger_destinationArn = (RepositoryTrigger -> Text)
-> (RepositoryTrigger -> Text -> RepositoryTrigger)
-> Lens RepositoryTrigger RepositoryTrigger Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepositoryTrigger' {Text
destinationArn :: Text
$sel:destinationArn:RepositoryTrigger' :: RepositoryTrigger -> Text
destinationArn} -> Text
destinationArn) (\s :: RepositoryTrigger
s@RepositoryTrigger' {} Text
a -> RepositoryTrigger
s {$sel:destinationArn:RepositoryTrigger' :: Text
destinationArn = Text
a} :: RepositoryTrigger)

-- | The repository events that cause the trigger to run actions in another
-- service, such as sending a notification through Amazon SNS.
--
-- The valid value \"all\" cannot be used with any other values.
repositoryTrigger_events :: Lens.Lens' RepositoryTrigger [RepositoryTriggerEventEnum]
repositoryTrigger_events :: ([RepositoryTriggerEventEnum] -> f [RepositoryTriggerEventEnum])
-> RepositoryTrigger -> f RepositoryTrigger
repositoryTrigger_events = (RepositoryTrigger -> [RepositoryTriggerEventEnum])
-> (RepositoryTrigger
    -> [RepositoryTriggerEventEnum] -> RepositoryTrigger)
-> Lens
     RepositoryTrigger
     RepositoryTrigger
     [RepositoryTriggerEventEnum]
     [RepositoryTriggerEventEnum]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepositoryTrigger' {[RepositoryTriggerEventEnum]
events :: [RepositoryTriggerEventEnum]
$sel:events:RepositoryTrigger' :: RepositoryTrigger -> [RepositoryTriggerEventEnum]
events} -> [RepositoryTriggerEventEnum]
events) (\s :: RepositoryTrigger
s@RepositoryTrigger' {} [RepositoryTriggerEventEnum]
a -> RepositoryTrigger
s {$sel:events:RepositoryTrigger' :: [RepositoryTriggerEventEnum]
events = [RepositoryTriggerEventEnum]
a} :: RepositoryTrigger) (([RepositoryTriggerEventEnum] -> f [RepositoryTriggerEventEnum])
 -> RepositoryTrigger -> f RepositoryTrigger)
-> (([RepositoryTriggerEventEnum]
     -> f [RepositoryTriggerEventEnum])
    -> [RepositoryTriggerEventEnum] -> f [RepositoryTriggerEventEnum])
-> ([RepositoryTriggerEventEnum] -> f [RepositoryTriggerEventEnum])
-> RepositoryTrigger
-> f RepositoryTrigger
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([RepositoryTriggerEventEnum] -> f [RepositoryTriggerEventEnum])
-> [RepositoryTriggerEventEnum] -> f [RepositoryTriggerEventEnum]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON RepositoryTrigger where
  parseJSON :: Value -> Parser RepositoryTrigger
parseJSON =
    String
-> (Object -> Parser RepositoryTrigger)
-> Value
-> Parser RepositoryTrigger
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RepositoryTrigger"
      ( \Object
x ->
          Maybe [Text]
-> Maybe Text
-> Text
-> Text
-> [RepositoryTriggerEventEnum]
-> RepositoryTrigger
RepositoryTrigger'
            (Maybe [Text]
 -> Maybe Text
 -> Text
 -> Text
 -> [RepositoryTriggerEventEnum]
 -> RepositoryTrigger)
-> Parser (Maybe [Text])
-> Parser
     (Maybe Text
      -> Text
      -> Text
      -> [RepositoryTriggerEventEnum]
      -> RepositoryTrigger)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"branches" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Text
   -> Text
   -> Text
   -> [RepositoryTriggerEventEnum]
   -> RepositoryTrigger)
-> Parser (Maybe Text)
-> Parser
     (Text -> Text -> [RepositoryTriggerEventEnum] -> RepositoryTrigger)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"customData")
            Parser
  (Text -> Text -> [RepositoryTriggerEventEnum] -> RepositoryTrigger)
-> Parser Text
-> Parser
     (Text -> [RepositoryTriggerEventEnum] -> RepositoryTrigger)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
            Parser (Text -> [RepositoryTriggerEventEnum] -> RepositoryTrigger)
-> Parser Text
-> Parser ([RepositoryTriggerEventEnum] -> RepositoryTrigger)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"destinationArn")
            Parser ([RepositoryTriggerEventEnum] -> RepositoryTrigger)
-> Parser [RepositoryTriggerEventEnum] -> Parser RepositoryTrigger
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [RepositoryTriggerEventEnum])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"events" Parser (Maybe [RepositoryTriggerEventEnum])
-> [RepositoryTriggerEventEnum]
-> Parser [RepositoryTriggerEventEnum]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [RepositoryTriggerEventEnum]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable RepositoryTrigger

instance Prelude.NFData RepositoryTrigger

instance Core.ToJSON RepositoryTrigger where
  toJSON :: RepositoryTrigger -> Value
toJSON RepositoryTrigger' {[RepositoryTriggerEventEnum]
Maybe [Text]
Maybe Text
Text
events :: [RepositoryTriggerEventEnum]
destinationArn :: Text
name :: Text
customData :: Maybe Text
branches :: Maybe [Text]
$sel:events:RepositoryTrigger' :: RepositoryTrigger -> [RepositoryTriggerEventEnum]
$sel:destinationArn:RepositoryTrigger' :: RepositoryTrigger -> Text
$sel:name:RepositoryTrigger' :: RepositoryTrigger -> Text
$sel:customData:RepositoryTrigger' :: RepositoryTrigger -> Maybe Text
$sel:branches:RepositoryTrigger' :: RepositoryTrigger -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"branches" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
branches,
            (Text
"customData" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
customData,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"destinationArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
destinationArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"events" Text -> [RepositoryTriggerEventEnum] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [RepositoryTriggerEventEnum]
events)
          ]
      )