{-# 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.CodeBuild.Types.Webhook
-- 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.CodeBuild.Types.Webhook where

import Amazonka.CodeBuild.Types.WebhookBuildType
import Amazonka.CodeBuild.Types.WebhookFilter
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a webhook that connects repository events to a build
-- project in CodeBuild.
--
-- /See:/ 'newWebhook' smart constructor.
data Webhook = Webhook'
  { -- | A regular expression used to determine which repository branches are
    -- built when a webhook is triggered. If the name of a branch matches the
    -- regular expression, then it is built. If @branchFilter@ is empty, then
    -- all branches are built.
    --
    -- It is recommended that you use @filterGroups@ instead of @branchFilter@.
    Webhook -> Maybe Text
branchFilter :: Prelude.Maybe Prelude.Text,
    -- | A timestamp that indicates the last time a repository\'s secret token
    -- was modified.
    Webhook -> Maybe POSIX
lastModifiedSecret :: Prelude.Maybe Core.POSIX,
    -- | The URL to the webhook.
    Webhook -> Maybe Text
url :: Prelude.Maybe Prelude.Text,
    -- | The secret token of the associated repository.
    --
    -- A Bitbucket webhook does not support @secret@.
    Webhook -> Maybe Text
secret :: Prelude.Maybe Prelude.Text,
    -- | An array of arrays of @WebhookFilter@ objects used to determine which
    -- webhooks are triggered. At least one @WebhookFilter@ in the array must
    -- specify @EVENT@ as its @type@.
    --
    -- For a build to be triggered, at least one filter group in the
    -- @filterGroups@ array must pass. For a filter group to pass, each of its
    -- filters must pass.
    Webhook -> Maybe [[WebhookFilter]]
filterGroups :: Prelude.Maybe [[WebhookFilter]],
    -- | The CodeBuild endpoint where webhook events are sent.
    Webhook -> Maybe Text
payloadUrl :: Prelude.Maybe Prelude.Text,
    -- | Specifies the type of build this webhook will trigger.
    Webhook -> Maybe WebhookBuildType
buildType :: Prelude.Maybe WebhookBuildType
  }
  deriving (Webhook -> Webhook -> Bool
(Webhook -> Webhook -> Bool)
-> (Webhook -> Webhook -> Bool) -> Eq Webhook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Webhook -> Webhook -> Bool
$c/= :: Webhook -> Webhook -> Bool
== :: Webhook -> Webhook -> Bool
$c== :: Webhook -> Webhook -> Bool
Prelude.Eq, ReadPrec [Webhook]
ReadPrec Webhook
Int -> ReadS Webhook
ReadS [Webhook]
(Int -> ReadS Webhook)
-> ReadS [Webhook]
-> ReadPrec Webhook
-> ReadPrec [Webhook]
-> Read Webhook
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Webhook]
$creadListPrec :: ReadPrec [Webhook]
readPrec :: ReadPrec Webhook
$creadPrec :: ReadPrec Webhook
readList :: ReadS [Webhook]
$creadList :: ReadS [Webhook]
readsPrec :: Int -> ReadS Webhook
$creadsPrec :: Int -> ReadS Webhook
Prelude.Read, Int -> Webhook -> ShowS
[Webhook] -> ShowS
Webhook -> String
(Int -> Webhook -> ShowS)
-> (Webhook -> String) -> ([Webhook] -> ShowS) -> Show Webhook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Webhook] -> ShowS
$cshowList :: [Webhook] -> ShowS
show :: Webhook -> String
$cshow :: Webhook -> String
showsPrec :: Int -> Webhook -> ShowS
$cshowsPrec :: Int -> Webhook -> ShowS
Prelude.Show, (forall x. Webhook -> Rep Webhook x)
-> (forall x. Rep Webhook x -> Webhook) -> Generic Webhook
forall x. Rep Webhook x -> Webhook
forall x. Webhook -> Rep Webhook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Webhook x -> Webhook
$cfrom :: forall x. Webhook -> Rep Webhook x
Prelude.Generic)

-- |
-- Create a value of 'Webhook' 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:
--
-- 'branchFilter', 'webhook_branchFilter' - A regular expression used to determine which repository branches are
-- built when a webhook is triggered. If the name of a branch matches the
-- regular expression, then it is built. If @branchFilter@ is empty, then
-- all branches are built.
--
-- It is recommended that you use @filterGroups@ instead of @branchFilter@.
--
-- 'lastModifiedSecret', 'webhook_lastModifiedSecret' - A timestamp that indicates the last time a repository\'s secret token
-- was modified.
--
-- 'url', 'webhook_url' - The URL to the webhook.
--
-- 'secret', 'webhook_secret' - The secret token of the associated repository.
--
-- A Bitbucket webhook does not support @secret@.
--
-- 'filterGroups', 'webhook_filterGroups' - An array of arrays of @WebhookFilter@ objects used to determine which
-- webhooks are triggered. At least one @WebhookFilter@ in the array must
-- specify @EVENT@ as its @type@.
--
-- For a build to be triggered, at least one filter group in the
-- @filterGroups@ array must pass. For a filter group to pass, each of its
-- filters must pass.
--
-- 'payloadUrl', 'webhook_payloadUrl' - The CodeBuild endpoint where webhook events are sent.
--
-- 'buildType', 'webhook_buildType' - Specifies the type of build this webhook will trigger.
newWebhook ::
  Webhook
newWebhook :: Webhook
newWebhook =
  Webhook' :: Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe [[WebhookFilter]]
-> Maybe Text
-> Maybe WebhookBuildType
-> Webhook
Webhook'
    { $sel:branchFilter:Webhook' :: Maybe Text
branchFilter = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastModifiedSecret:Webhook' :: Maybe POSIX
lastModifiedSecret = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:url:Webhook' :: Maybe Text
url = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:secret:Webhook' :: Maybe Text
secret = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filterGroups:Webhook' :: Maybe [[WebhookFilter]]
filterGroups = Maybe [[WebhookFilter]]
forall a. Maybe a
Prelude.Nothing,
      $sel:payloadUrl:Webhook' :: Maybe Text
payloadUrl = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:buildType:Webhook' :: Maybe WebhookBuildType
buildType = Maybe WebhookBuildType
forall a. Maybe a
Prelude.Nothing
    }

-- | A regular expression used to determine which repository branches are
-- built when a webhook is triggered. If the name of a branch matches the
-- regular expression, then it is built. If @branchFilter@ is empty, then
-- all branches are built.
--
-- It is recommended that you use @filterGroups@ instead of @branchFilter@.
webhook_branchFilter :: Lens.Lens' Webhook (Prelude.Maybe Prelude.Text)
webhook_branchFilter :: (Maybe Text -> f (Maybe Text)) -> Webhook -> f Webhook
webhook_branchFilter = (Webhook -> Maybe Text)
-> (Webhook -> Maybe Text -> Webhook)
-> Lens Webhook Webhook (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe Text
branchFilter :: Maybe Text
$sel:branchFilter:Webhook' :: Webhook -> Maybe Text
branchFilter} -> Maybe Text
branchFilter) (\s :: Webhook
s@Webhook' {} Maybe Text
a -> Webhook
s {$sel:branchFilter:Webhook' :: Maybe Text
branchFilter = Maybe Text
a} :: Webhook)

-- | A timestamp that indicates the last time a repository\'s secret token
-- was modified.
webhook_lastModifiedSecret :: Lens.Lens' Webhook (Prelude.Maybe Prelude.UTCTime)
webhook_lastModifiedSecret :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Webhook -> f Webhook
webhook_lastModifiedSecret = (Webhook -> Maybe POSIX)
-> (Webhook -> Maybe POSIX -> Webhook)
-> Lens Webhook Webhook (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe POSIX
lastModifiedSecret :: Maybe POSIX
$sel:lastModifiedSecret:Webhook' :: Webhook -> Maybe POSIX
lastModifiedSecret} -> Maybe POSIX
lastModifiedSecret) (\s :: Webhook
s@Webhook' {} Maybe POSIX
a -> Webhook
s {$sel:lastModifiedSecret:Webhook' :: Maybe POSIX
lastModifiedSecret = Maybe POSIX
a} :: Webhook) ((Maybe POSIX -> f (Maybe POSIX)) -> Webhook -> f Webhook)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Webhook
-> f Webhook
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The URL to the webhook.
webhook_url :: Lens.Lens' Webhook (Prelude.Maybe Prelude.Text)
webhook_url :: (Maybe Text -> f (Maybe Text)) -> Webhook -> f Webhook
webhook_url = (Webhook -> Maybe Text)
-> (Webhook -> Maybe Text -> Webhook)
-> Lens Webhook Webhook (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe Text
url :: Maybe Text
$sel:url:Webhook' :: Webhook -> Maybe Text
url} -> Maybe Text
url) (\s :: Webhook
s@Webhook' {} Maybe Text
a -> Webhook
s {$sel:url:Webhook' :: Maybe Text
url = Maybe Text
a} :: Webhook)

-- | The secret token of the associated repository.
--
-- A Bitbucket webhook does not support @secret@.
webhook_secret :: Lens.Lens' Webhook (Prelude.Maybe Prelude.Text)
webhook_secret :: (Maybe Text -> f (Maybe Text)) -> Webhook -> f Webhook
webhook_secret = (Webhook -> Maybe Text)
-> (Webhook -> Maybe Text -> Webhook)
-> Lens Webhook Webhook (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe Text
secret :: Maybe Text
$sel:secret:Webhook' :: Webhook -> Maybe Text
secret} -> Maybe Text
secret) (\s :: Webhook
s@Webhook' {} Maybe Text
a -> Webhook
s {$sel:secret:Webhook' :: Maybe Text
secret = Maybe Text
a} :: Webhook)

-- | An array of arrays of @WebhookFilter@ objects used to determine which
-- webhooks are triggered. At least one @WebhookFilter@ in the array must
-- specify @EVENT@ as its @type@.
--
-- For a build to be triggered, at least one filter group in the
-- @filterGroups@ array must pass. For a filter group to pass, each of its
-- filters must pass.
webhook_filterGroups :: Lens.Lens' Webhook (Prelude.Maybe [[WebhookFilter]])
webhook_filterGroups :: (Maybe [[WebhookFilter]] -> f (Maybe [[WebhookFilter]]))
-> Webhook -> f Webhook
webhook_filterGroups = (Webhook -> Maybe [[WebhookFilter]])
-> (Webhook -> Maybe [[WebhookFilter]] -> Webhook)
-> Lens
     Webhook Webhook (Maybe [[WebhookFilter]]) (Maybe [[WebhookFilter]])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe [[WebhookFilter]]
filterGroups :: Maybe [[WebhookFilter]]
$sel:filterGroups:Webhook' :: Webhook -> Maybe [[WebhookFilter]]
filterGroups} -> Maybe [[WebhookFilter]]
filterGroups) (\s :: Webhook
s@Webhook' {} Maybe [[WebhookFilter]]
a -> Webhook
s {$sel:filterGroups:Webhook' :: Maybe [[WebhookFilter]]
filterGroups = Maybe [[WebhookFilter]]
a} :: Webhook) ((Maybe [[WebhookFilter]] -> f (Maybe [[WebhookFilter]]))
 -> Webhook -> f Webhook)
-> ((Maybe [[WebhookFilter]] -> f (Maybe [[WebhookFilter]]))
    -> Maybe [[WebhookFilter]] -> f (Maybe [[WebhookFilter]]))
-> (Maybe [[WebhookFilter]] -> f (Maybe [[WebhookFilter]]))
-> Webhook
-> f Webhook
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [[WebhookFilter]]
  [[WebhookFilter]]
  [[WebhookFilter]]
  [[WebhookFilter]]
-> Iso
     (Maybe [[WebhookFilter]])
     (Maybe [[WebhookFilter]])
     (Maybe [[WebhookFilter]])
     (Maybe [[WebhookFilter]])
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
  [[WebhookFilter]]
  [[WebhookFilter]]
  [[WebhookFilter]]
  [[WebhookFilter]]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The CodeBuild endpoint where webhook events are sent.
webhook_payloadUrl :: Lens.Lens' Webhook (Prelude.Maybe Prelude.Text)
webhook_payloadUrl :: (Maybe Text -> f (Maybe Text)) -> Webhook -> f Webhook
webhook_payloadUrl = (Webhook -> Maybe Text)
-> (Webhook -> Maybe Text -> Webhook)
-> Lens Webhook Webhook (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe Text
payloadUrl :: Maybe Text
$sel:payloadUrl:Webhook' :: Webhook -> Maybe Text
payloadUrl} -> Maybe Text
payloadUrl) (\s :: Webhook
s@Webhook' {} Maybe Text
a -> Webhook
s {$sel:payloadUrl:Webhook' :: Maybe Text
payloadUrl = Maybe Text
a} :: Webhook)

-- | Specifies the type of build this webhook will trigger.
webhook_buildType :: Lens.Lens' Webhook (Prelude.Maybe WebhookBuildType)
webhook_buildType :: (Maybe WebhookBuildType -> f (Maybe WebhookBuildType))
-> Webhook -> f Webhook
webhook_buildType = (Webhook -> Maybe WebhookBuildType)
-> (Webhook -> Maybe WebhookBuildType -> Webhook)
-> Lens
     Webhook Webhook (Maybe WebhookBuildType) (Maybe WebhookBuildType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Webhook' {Maybe WebhookBuildType
buildType :: Maybe WebhookBuildType
$sel:buildType:Webhook' :: Webhook -> Maybe WebhookBuildType
buildType} -> Maybe WebhookBuildType
buildType) (\s :: Webhook
s@Webhook' {} Maybe WebhookBuildType
a -> Webhook
s {$sel:buildType:Webhook' :: Maybe WebhookBuildType
buildType = Maybe WebhookBuildType
a} :: Webhook)

instance Core.FromJSON Webhook where
  parseJSON :: Value -> Parser Webhook
parseJSON =
    String -> (Object -> Parser Webhook) -> Value -> Parser Webhook
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Webhook"
      ( \Object
x ->
          Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe [[WebhookFilter]]
-> Maybe Text
-> Maybe WebhookBuildType
-> Webhook
Webhook'
            (Maybe Text
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Text
 -> Maybe [[WebhookFilter]]
 -> Maybe Text
 -> Maybe WebhookBuildType
 -> Webhook)
-> Parser (Maybe Text)
-> Parser
     (Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe [[WebhookFilter]]
      -> Maybe Text
      -> Maybe WebhookBuildType
      -> Webhook)
forall (f :: * -> *) a b. Functor 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
"branchFilter")
            Parser
  (Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe [[WebhookFilter]]
   -> Maybe Text
   -> Maybe WebhookBuildType
   -> Webhook)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe [[WebhookFilter]]
      -> Maybe Text
      -> Maybe WebhookBuildType
      -> Webhook)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lastModifiedSecret")
            Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe [[WebhookFilter]]
   -> Maybe Text
   -> Maybe WebhookBuildType
   -> Webhook)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe [[WebhookFilter]]
      -> Maybe Text
      -> Maybe WebhookBuildType
      -> Webhook)
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
"url")
            Parser
  (Maybe Text
   -> Maybe [[WebhookFilter]]
   -> Maybe Text
   -> Maybe WebhookBuildType
   -> Webhook)
-> Parser (Maybe Text)
-> Parser
     (Maybe [[WebhookFilter]]
      -> Maybe Text -> Maybe WebhookBuildType -> Webhook)
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
"secret")
            Parser
  (Maybe [[WebhookFilter]]
   -> Maybe Text -> Maybe WebhookBuildType -> Webhook)
-> Parser (Maybe [[WebhookFilter]])
-> Parser (Maybe Text -> Maybe WebhookBuildType -> Webhook)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [[WebhookFilter]]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"filterGroups" Parser (Maybe (Maybe [[WebhookFilter]]))
-> Maybe [[WebhookFilter]] -> Parser (Maybe [[WebhookFilter]])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [[WebhookFilter]]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe WebhookBuildType -> Webhook)
-> Parser (Maybe Text)
-> Parser (Maybe WebhookBuildType -> Webhook)
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
"payloadUrl")
            Parser (Maybe WebhookBuildType -> Webhook)
-> Parser (Maybe WebhookBuildType) -> Parser Webhook
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe WebhookBuildType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"buildType")
      )

instance Prelude.Hashable Webhook

instance Prelude.NFData Webhook