{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.AssociateApprovalRuleTemplateWithRepository
-- 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)
--
-- Creates an association between an approval rule template and a specified
-- repository. Then, the next time a pull request is created in the
-- repository where the destination reference (if specified) matches the
-- destination reference (branch) for the pull request, an approval rule
-- that matches the template conditions is automatically created for that
-- pull request. If no destination references are specified in the
-- template, an approval rule that matches the template contents is created
-- for all pull requests in that repository.
module Amazonka.CodeCommit.AssociateApprovalRuleTemplateWithRepository
  ( -- * Creating a Request
    AssociateApprovalRuleTemplateWithRepository (..),
    newAssociateApprovalRuleTemplateWithRepository,

    -- * Request Lenses
    associateApprovalRuleTemplateWithRepository_approvalRuleTemplateName,
    associateApprovalRuleTemplateWithRepository_repositoryName,

    -- * Destructuring the Response
    AssociateApprovalRuleTemplateWithRepositoryResponse (..),
    newAssociateApprovalRuleTemplateWithRepositoryResponse,
  )
where

import Amazonka.CodeCommit.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateApprovalRuleTemplateWithRepository' smart constructor.
data AssociateApprovalRuleTemplateWithRepository = AssociateApprovalRuleTemplateWithRepository'
  { -- | The name for the approval rule template.
    AssociateApprovalRuleTemplateWithRepository -> Text
approvalRuleTemplateName :: Prelude.Text,
    -- | The name of the repository that you want to associate with the template.
    AssociateApprovalRuleTemplateWithRepository -> Text
repositoryName :: Prelude.Text
  }
  deriving (AssociateApprovalRuleTemplateWithRepository
-> AssociateApprovalRuleTemplateWithRepository -> Bool
(AssociateApprovalRuleTemplateWithRepository
 -> AssociateApprovalRuleTemplateWithRepository -> Bool)
-> (AssociateApprovalRuleTemplateWithRepository
    -> AssociateApprovalRuleTemplateWithRepository -> Bool)
-> Eq AssociateApprovalRuleTemplateWithRepository
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateApprovalRuleTemplateWithRepository
-> AssociateApprovalRuleTemplateWithRepository -> Bool
$c/= :: AssociateApprovalRuleTemplateWithRepository
-> AssociateApprovalRuleTemplateWithRepository -> Bool
== :: AssociateApprovalRuleTemplateWithRepository
-> AssociateApprovalRuleTemplateWithRepository -> Bool
$c== :: AssociateApprovalRuleTemplateWithRepository
-> AssociateApprovalRuleTemplateWithRepository -> Bool
Prelude.Eq, ReadPrec [AssociateApprovalRuleTemplateWithRepository]
ReadPrec AssociateApprovalRuleTemplateWithRepository
Int -> ReadS AssociateApprovalRuleTemplateWithRepository
ReadS [AssociateApprovalRuleTemplateWithRepository]
(Int -> ReadS AssociateApprovalRuleTemplateWithRepository)
-> ReadS [AssociateApprovalRuleTemplateWithRepository]
-> ReadPrec AssociateApprovalRuleTemplateWithRepository
-> ReadPrec [AssociateApprovalRuleTemplateWithRepository]
-> Read AssociateApprovalRuleTemplateWithRepository
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateApprovalRuleTemplateWithRepository]
$creadListPrec :: ReadPrec [AssociateApprovalRuleTemplateWithRepository]
readPrec :: ReadPrec AssociateApprovalRuleTemplateWithRepository
$creadPrec :: ReadPrec AssociateApprovalRuleTemplateWithRepository
readList :: ReadS [AssociateApprovalRuleTemplateWithRepository]
$creadList :: ReadS [AssociateApprovalRuleTemplateWithRepository]
readsPrec :: Int -> ReadS AssociateApprovalRuleTemplateWithRepository
$creadsPrec :: Int -> ReadS AssociateApprovalRuleTemplateWithRepository
Prelude.Read, Int -> AssociateApprovalRuleTemplateWithRepository -> ShowS
[AssociateApprovalRuleTemplateWithRepository] -> ShowS
AssociateApprovalRuleTemplateWithRepository -> String
(Int -> AssociateApprovalRuleTemplateWithRepository -> ShowS)
-> (AssociateApprovalRuleTemplateWithRepository -> String)
-> ([AssociateApprovalRuleTemplateWithRepository] -> ShowS)
-> Show AssociateApprovalRuleTemplateWithRepository
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateApprovalRuleTemplateWithRepository] -> ShowS
$cshowList :: [AssociateApprovalRuleTemplateWithRepository] -> ShowS
show :: AssociateApprovalRuleTemplateWithRepository -> String
$cshow :: AssociateApprovalRuleTemplateWithRepository -> String
showsPrec :: Int -> AssociateApprovalRuleTemplateWithRepository -> ShowS
$cshowsPrec :: Int -> AssociateApprovalRuleTemplateWithRepository -> ShowS
Prelude.Show, (forall x.
 AssociateApprovalRuleTemplateWithRepository
 -> Rep AssociateApprovalRuleTemplateWithRepository x)
-> (forall x.
    Rep AssociateApprovalRuleTemplateWithRepository x
    -> AssociateApprovalRuleTemplateWithRepository)
-> Generic AssociateApprovalRuleTemplateWithRepository
forall x.
Rep AssociateApprovalRuleTemplateWithRepository x
-> AssociateApprovalRuleTemplateWithRepository
forall x.
AssociateApprovalRuleTemplateWithRepository
-> Rep AssociateApprovalRuleTemplateWithRepository x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateApprovalRuleTemplateWithRepository x
-> AssociateApprovalRuleTemplateWithRepository
$cfrom :: forall x.
AssociateApprovalRuleTemplateWithRepository
-> Rep AssociateApprovalRuleTemplateWithRepository x
Prelude.Generic)

-- |
-- Create a value of 'AssociateApprovalRuleTemplateWithRepository' 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:
--
-- 'approvalRuleTemplateName', 'associateApprovalRuleTemplateWithRepository_approvalRuleTemplateName' - The name for the approval rule template.
--
-- 'repositoryName', 'associateApprovalRuleTemplateWithRepository_repositoryName' - The name of the repository that you want to associate with the template.
newAssociateApprovalRuleTemplateWithRepository ::
  -- | 'approvalRuleTemplateName'
  Prelude.Text ->
  -- | 'repositoryName'
  Prelude.Text ->
  AssociateApprovalRuleTemplateWithRepository
newAssociateApprovalRuleTemplateWithRepository :: Text -> Text -> AssociateApprovalRuleTemplateWithRepository
newAssociateApprovalRuleTemplateWithRepository
  Text
pApprovalRuleTemplateName_
  Text
pRepositoryName_ =
    AssociateApprovalRuleTemplateWithRepository' :: Text -> Text -> AssociateApprovalRuleTemplateWithRepository
AssociateApprovalRuleTemplateWithRepository'
      { $sel:approvalRuleTemplateName:AssociateApprovalRuleTemplateWithRepository' :: Text
approvalRuleTemplateName =
          Text
pApprovalRuleTemplateName_,
        $sel:repositoryName:AssociateApprovalRuleTemplateWithRepository' :: Text
repositoryName =
          Text
pRepositoryName_
      }

-- | The name for the approval rule template.
associateApprovalRuleTemplateWithRepository_approvalRuleTemplateName :: Lens.Lens' AssociateApprovalRuleTemplateWithRepository Prelude.Text
associateApprovalRuleTemplateWithRepository_approvalRuleTemplateName :: (Text -> f Text)
-> AssociateApprovalRuleTemplateWithRepository
-> f AssociateApprovalRuleTemplateWithRepository
associateApprovalRuleTemplateWithRepository_approvalRuleTemplateName = (AssociateApprovalRuleTemplateWithRepository -> Text)
-> (AssociateApprovalRuleTemplateWithRepository
    -> Text -> AssociateApprovalRuleTemplateWithRepository)
-> Lens
     AssociateApprovalRuleTemplateWithRepository
     AssociateApprovalRuleTemplateWithRepository
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateApprovalRuleTemplateWithRepository' {Text
approvalRuleTemplateName :: Text
$sel:approvalRuleTemplateName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
approvalRuleTemplateName} -> Text
approvalRuleTemplateName) (\s :: AssociateApprovalRuleTemplateWithRepository
s@AssociateApprovalRuleTemplateWithRepository' {} Text
a -> AssociateApprovalRuleTemplateWithRepository
s {$sel:approvalRuleTemplateName:AssociateApprovalRuleTemplateWithRepository' :: Text
approvalRuleTemplateName = Text
a} :: AssociateApprovalRuleTemplateWithRepository)

-- | The name of the repository that you want to associate with the template.
associateApprovalRuleTemplateWithRepository_repositoryName :: Lens.Lens' AssociateApprovalRuleTemplateWithRepository Prelude.Text
associateApprovalRuleTemplateWithRepository_repositoryName :: (Text -> f Text)
-> AssociateApprovalRuleTemplateWithRepository
-> f AssociateApprovalRuleTemplateWithRepository
associateApprovalRuleTemplateWithRepository_repositoryName = (AssociateApprovalRuleTemplateWithRepository -> Text)
-> (AssociateApprovalRuleTemplateWithRepository
    -> Text -> AssociateApprovalRuleTemplateWithRepository)
-> Lens
     AssociateApprovalRuleTemplateWithRepository
     AssociateApprovalRuleTemplateWithRepository
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateApprovalRuleTemplateWithRepository' {Text
repositoryName :: Text
$sel:repositoryName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
repositoryName} -> Text
repositoryName) (\s :: AssociateApprovalRuleTemplateWithRepository
s@AssociateApprovalRuleTemplateWithRepository' {} Text
a -> AssociateApprovalRuleTemplateWithRepository
s {$sel:repositoryName:AssociateApprovalRuleTemplateWithRepository' :: Text
repositoryName = Text
a} :: AssociateApprovalRuleTemplateWithRepository)

instance
  Core.AWSRequest
    AssociateApprovalRuleTemplateWithRepository
  where
  type
    AWSResponse
      AssociateApprovalRuleTemplateWithRepository =
      AssociateApprovalRuleTemplateWithRepositoryResponse
  request :: AssociateApprovalRuleTemplateWithRepository
-> Request AssociateApprovalRuleTemplateWithRepository
request = Service
-> AssociateApprovalRuleTemplateWithRepository
-> Request AssociateApprovalRuleTemplateWithRepository
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateApprovalRuleTemplateWithRepository
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse
           (AWSResponse AssociateApprovalRuleTemplateWithRepository)))
response =
    AWSResponse AssociateApprovalRuleTemplateWithRepository
-> Logger
-> Service
-> Proxy AssociateApprovalRuleTemplateWithRepository
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse
           (AWSResponse AssociateApprovalRuleTemplateWithRepository)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse AssociateApprovalRuleTemplateWithRepository
AssociateApprovalRuleTemplateWithRepositoryResponse
AssociateApprovalRuleTemplateWithRepositoryResponse'

instance
  Prelude.Hashable
    AssociateApprovalRuleTemplateWithRepository

instance
  Prelude.NFData
    AssociateApprovalRuleTemplateWithRepository

instance
  Core.ToHeaders
    AssociateApprovalRuleTemplateWithRepository
  where
  toHeaders :: AssociateApprovalRuleTemplateWithRepository -> [Header]
toHeaders =
    [Header] -> AssociateApprovalRuleTemplateWithRepository -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"CodeCommit_20150413.AssociateApprovalRuleTemplateWithRepository" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance
  Core.ToJSON
    AssociateApprovalRuleTemplateWithRepository
  where
  toJSON :: AssociateApprovalRuleTemplateWithRepository -> Value
toJSON
    AssociateApprovalRuleTemplateWithRepository' {Text
repositoryName :: Text
approvalRuleTemplateName :: Text
$sel:repositoryName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
$sel:approvalRuleTemplateName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
..} =
      [Pair] -> Value
Core.object
        ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
            [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
                ( Text
"approvalRuleTemplateName"
                    Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
approvalRuleTemplateName
                ),
              Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
                (Text
"repositoryName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
repositoryName)
            ]
        )

instance
  Core.ToPath
    AssociateApprovalRuleTemplateWithRepository
  where
  toPath :: AssociateApprovalRuleTemplateWithRepository -> ByteString
toPath = ByteString
-> AssociateApprovalRuleTemplateWithRepository -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance
  Core.ToQuery
    AssociateApprovalRuleTemplateWithRepository
  where
  toQuery :: AssociateApprovalRuleTemplateWithRepository -> QueryString
toQuery = QueryString
-> AssociateApprovalRuleTemplateWithRepository -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAssociateApprovalRuleTemplateWithRepositoryResponse' smart constructor.
data AssociateApprovalRuleTemplateWithRepositoryResponse = AssociateApprovalRuleTemplateWithRepositoryResponse'
  {
  }
  deriving (AssociateApprovalRuleTemplateWithRepositoryResponse
-> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool
(AssociateApprovalRuleTemplateWithRepositoryResponse
 -> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool)
-> (AssociateApprovalRuleTemplateWithRepositoryResponse
    -> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool)
-> Eq AssociateApprovalRuleTemplateWithRepositoryResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateApprovalRuleTemplateWithRepositoryResponse
-> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool
$c/= :: AssociateApprovalRuleTemplateWithRepositoryResponse
-> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool
== :: AssociateApprovalRuleTemplateWithRepositoryResponse
-> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool
$c== :: AssociateApprovalRuleTemplateWithRepositoryResponse
-> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool
Prelude.Eq, ReadPrec [AssociateApprovalRuleTemplateWithRepositoryResponse]
ReadPrec AssociateApprovalRuleTemplateWithRepositoryResponse
Int -> ReadS AssociateApprovalRuleTemplateWithRepositoryResponse
ReadS [AssociateApprovalRuleTemplateWithRepositoryResponse]
(Int -> ReadS AssociateApprovalRuleTemplateWithRepositoryResponse)
-> ReadS [AssociateApprovalRuleTemplateWithRepositoryResponse]
-> ReadPrec AssociateApprovalRuleTemplateWithRepositoryResponse
-> ReadPrec [AssociateApprovalRuleTemplateWithRepositoryResponse]
-> Read AssociateApprovalRuleTemplateWithRepositoryResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateApprovalRuleTemplateWithRepositoryResponse]
$creadListPrec :: ReadPrec [AssociateApprovalRuleTemplateWithRepositoryResponse]
readPrec :: ReadPrec AssociateApprovalRuleTemplateWithRepositoryResponse
$creadPrec :: ReadPrec AssociateApprovalRuleTemplateWithRepositoryResponse
readList :: ReadS [AssociateApprovalRuleTemplateWithRepositoryResponse]
$creadList :: ReadS [AssociateApprovalRuleTemplateWithRepositoryResponse]
readsPrec :: Int -> ReadS AssociateApprovalRuleTemplateWithRepositoryResponse
$creadsPrec :: Int -> ReadS AssociateApprovalRuleTemplateWithRepositoryResponse
Prelude.Read, Int -> AssociateApprovalRuleTemplateWithRepositoryResponse -> ShowS
[AssociateApprovalRuleTemplateWithRepositoryResponse] -> ShowS
AssociateApprovalRuleTemplateWithRepositoryResponse -> String
(Int
 -> AssociateApprovalRuleTemplateWithRepositoryResponse -> ShowS)
-> (AssociateApprovalRuleTemplateWithRepositoryResponse -> String)
-> ([AssociateApprovalRuleTemplateWithRepositoryResponse] -> ShowS)
-> Show AssociateApprovalRuleTemplateWithRepositoryResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateApprovalRuleTemplateWithRepositoryResponse] -> ShowS
$cshowList :: [AssociateApprovalRuleTemplateWithRepositoryResponse] -> ShowS
show :: AssociateApprovalRuleTemplateWithRepositoryResponse -> String
$cshow :: AssociateApprovalRuleTemplateWithRepositoryResponse -> String
showsPrec :: Int -> AssociateApprovalRuleTemplateWithRepositoryResponse -> ShowS
$cshowsPrec :: Int -> AssociateApprovalRuleTemplateWithRepositoryResponse -> ShowS
Prelude.Show, (forall x.
 AssociateApprovalRuleTemplateWithRepositoryResponse
 -> Rep AssociateApprovalRuleTemplateWithRepositoryResponse x)
-> (forall x.
    Rep AssociateApprovalRuleTemplateWithRepositoryResponse x
    -> AssociateApprovalRuleTemplateWithRepositoryResponse)
-> Generic AssociateApprovalRuleTemplateWithRepositoryResponse
forall x.
Rep AssociateApprovalRuleTemplateWithRepositoryResponse x
-> AssociateApprovalRuleTemplateWithRepositoryResponse
forall x.
AssociateApprovalRuleTemplateWithRepositoryResponse
-> Rep AssociateApprovalRuleTemplateWithRepositoryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateApprovalRuleTemplateWithRepositoryResponse x
-> AssociateApprovalRuleTemplateWithRepositoryResponse
$cfrom :: forall x.
AssociateApprovalRuleTemplateWithRepositoryResponse
-> Rep AssociateApprovalRuleTemplateWithRepositoryResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateApprovalRuleTemplateWithRepositoryResponse' 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.
newAssociateApprovalRuleTemplateWithRepositoryResponse ::
  AssociateApprovalRuleTemplateWithRepositoryResponse
newAssociateApprovalRuleTemplateWithRepositoryResponse :: AssociateApprovalRuleTemplateWithRepositoryResponse
newAssociateApprovalRuleTemplateWithRepositoryResponse =
  AssociateApprovalRuleTemplateWithRepositoryResponse
AssociateApprovalRuleTemplateWithRepositoryResponse'

instance
  Prelude.NFData
    AssociateApprovalRuleTemplateWithRepositoryResponse