{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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.
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'
      { $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 :: Lens' AssociateApprovalRuleTemplateWithRepository Text
associateApprovalRuleTemplateWithRepository_approvalRuleTemplateName = 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 :: Lens' AssociateApprovalRuleTemplateWithRepository Text
associateApprovalRuleTemplateWithRepository_repositoryName = 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 :: (Service -> Service)
-> AssociateApprovalRuleTemplateWithRepository
-> Request AssociateApprovalRuleTemplateWithRepository
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateApprovalRuleTemplateWithRepository
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse
           (AWSResponse AssociateApprovalRuleTemplateWithRepository)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AssociateApprovalRuleTemplateWithRepositoryResponse
AssociateApprovalRuleTemplateWithRepositoryResponse'

instance
  Prelude.Hashable
    AssociateApprovalRuleTemplateWithRepository
  where
  hashWithSalt :: Int -> AssociateApprovalRuleTemplateWithRepository -> Int
hashWithSalt
    Int
_salt
    AssociateApprovalRuleTemplateWithRepository' {Text
repositoryName :: Text
approvalRuleTemplateName :: Text
$sel:repositoryName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
$sel:approvalRuleTemplateName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
approvalRuleTemplateName
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
repositoryName

instance
  Prelude.NFData
    AssociateApprovalRuleTemplateWithRepository
  where
  rnf :: AssociateApprovalRuleTemplateWithRepository -> ()
rnf AssociateApprovalRuleTemplateWithRepository' {Text
repositoryName :: Text
approvalRuleTemplateName :: Text
$sel:repositoryName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
$sel:approvalRuleTemplateName:AssociateApprovalRuleTemplateWithRepository' :: AssociateApprovalRuleTemplateWithRepository -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
approvalRuleTemplateName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
repositoryName

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

instance
  Data.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
Data.object
        ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
            [ forall a. a -> Maybe a
Prelude.Just
                ( Key
"approvalRuleTemplateName"
                    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
approvalRuleTemplateName
                ),
              forall a. a -> Maybe a
Prelude.Just
                (Key
"repositoryName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
repositoryName)
            ]
        )

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

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

-- | /See:/ 'newAssociateApprovalRuleTemplateWithRepositoryResponse' smart constructor.
data AssociateApprovalRuleTemplateWithRepositoryResponse = AssociateApprovalRuleTemplateWithRepositoryResponse'
  {
  }
  deriving (AssociateApprovalRuleTemplateWithRepositoryResponse
-> AssociateApprovalRuleTemplateWithRepositoryResponse -> Bool
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]
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
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.
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
  where
  rnf :: AssociateApprovalRuleTemplateWithRepositoryResponse -> ()
rnf AssociateApprovalRuleTemplateWithRepositoryResponse
_ = ()