{-# 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.UpdatePullRequestStatus
-- 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)
--
-- Updates the status of a pull request.
module Amazonka.CodeCommit.UpdatePullRequestStatus
  ( -- * Creating a Request
    UpdatePullRequestStatus (..),
    newUpdatePullRequestStatus,

    -- * Request Lenses
    updatePullRequestStatus_pullRequestId,
    updatePullRequestStatus_pullRequestStatus,

    -- * Destructuring the Response
    UpdatePullRequestStatusResponse (..),
    newUpdatePullRequestStatusResponse,

    -- * Response Lenses
    updatePullRequestStatusResponse_httpStatus,
    updatePullRequestStatusResponse_pullRequest,
  )
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:/ 'newUpdatePullRequestStatus' smart constructor.
data UpdatePullRequestStatus = UpdatePullRequestStatus'
  { -- | The system-generated ID of the pull request. To get this ID, use
    -- ListPullRequests.
    UpdatePullRequestStatus -> Text
pullRequestId :: Prelude.Text,
    -- | The status of the pull request. The only valid operations are to update
    -- the status from @OPEN@ to @OPEN@, @OPEN@ to @CLOSED@ or from @CLOSED@ to
    -- @CLOSED@.
    UpdatePullRequestStatus -> PullRequestStatusEnum
pullRequestStatus :: PullRequestStatusEnum
  }
  deriving (UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool
(UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool)
-> (UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool)
-> Eq UpdatePullRequestStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool
$c/= :: UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool
== :: UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool
$c== :: UpdatePullRequestStatus -> UpdatePullRequestStatus -> Bool
Prelude.Eq, ReadPrec [UpdatePullRequestStatus]
ReadPrec UpdatePullRequestStatus
Int -> ReadS UpdatePullRequestStatus
ReadS [UpdatePullRequestStatus]
(Int -> ReadS UpdatePullRequestStatus)
-> ReadS [UpdatePullRequestStatus]
-> ReadPrec UpdatePullRequestStatus
-> ReadPrec [UpdatePullRequestStatus]
-> Read UpdatePullRequestStatus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePullRequestStatus]
$creadListPrec :: ReadPrec [UpdatePullRequestStatus]
readPrec :: ReadPrec UpdatePullRequestStatus
$creadPrec :: ReadPrec UpdatePullRequestStatus
readList :: ReadS [UpdatePullRequestStatus]
$creadList :: ReadS [UpdatePullRequestStatus]
readsPrec :: Int -> ReadS UpdatePullRequestStatus
$creadsPrec :: Int -> ReadS UpdatePullRequestStatus
Prelude.Read, Int -> UpdatePullRequestStatus -> ShowS
[UpdatePullRequestStatus] -> ShowS
UpdatePullRequestStatus -> String
(Int -> UpdatePullRequestStatus -> ShowS)
-> (UpdatePullRequestStatus -> String)
-> ([UpdatePullRequestStatus] -> ShowS)
-> Show UpdatePullRequestStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePullRequestStatus] -> ShowS
$cshowList :: [UpdatePullRequestStatus] -> ShowS
show :: UpdatePullRequestStatus -> String
$cshow :: UpdatePullRequestStatus -> String
showsPrec :: Int -> UpdatePullRequestStatus -> ShowS
$cshowsPrec :: Int -> UpdatePullRequestStatus -> ShowS
Prelude.Show, (forall x.
 UpdatePullRequestStatus -> Rep UpdatePullRequestStatus x)
-> (forall x.
    Rep UpdatePullRequestStatus x -> UpdatePullRequestStatus)
-> Generic UpdatePullRequestStatus
forall x. Rep UpdatePullRequestStatus x -> UpdatePullRequestStatus
forall x. UpdatePullRequestStatus -> Rep UpdatePullRequestStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdatePullRequestStatus x -> UpdatePullRequestStatus
$cfrom :: forall x. UpdatePullRequestStatus -> Rep UpdatePullRequestStatus x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePullRequestStatus' 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:
--
-- 'pullRequestId', 'updatePullRequestStatus_pullRequestId' - The system-generated ID of the pull request. To get this ID, use
-- ListPullRequests.
--
-- 'pullRequestStatus', 'updatePullRequestStatus_pullRequestStatus' - The status of the pull request. The only valid operations are to update
-- the status from @OPEN@ to @OPEN@, @OPEN@ to @CLOSED@ or from @CLOSED@ to
-- @CLOSED@.
newUpdatePullRequestStatus ::
  -- | 'pullRequestId'
  Prelude.Text ->
  -- | 'pullRequestStatus'
  PullRequestStatusEnum ->
  UpdatePullRequestStatus
newUpdatePullRequestStatus :: Text -> PullRequestStatusEnum -> UpdatePullRequestStatus
newUpdatePullRequestStatus
  Text
pPullRequestId_
  PullRequestStatusEnum
pPullRequestStatus_ =
    UpdatePullRequestStatus' :: Text -> PullRequestStatusEnum -> UpdatePullRequestStatus
UpdatePullRequestStatus'
      { $sel:pullRequestId:UpdatePullRequestStatus' :: Text
pullRequestId =
          Text
pPullRequestId_,
        $sel:pullRequestStatus:UpdatePullRequestStatus' :: PullRequestStatusEnum
pullRequestStatus = PullRequestStatusEnum
pPullRequestStatus_
      }

-- | The system-generated ID of the pull request. To get this ID, use
-- ListPullRequests.
updatePullRequestStatus_pullRequestId :: Lens.Lens' UpdatePullRequestStatus Prelude.Text
updatePullRequestStatus_pullRequestId :: (Text -> f Text)
-> UpdatePullRequestStatus -> f UpdatePullRequestStatus
updatePullRequestStatus_pullRequestId = (UpdatePullRequestStatus -> Text)
-> (UpdatePullRequestStatus -> Text -> UpdatePullRequestStatus)
-> Lens UpdatePullRequestStatus UpdatePullRequestStatus Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePullRequestStatus' {Text
pullRequestId :: Text
$sel:pullRequestId:UpdatePullRequestStatus' :: UpdatePullRequestStatus -> Text
pullRequestId} -> Text
pullRequestId) (\s :: UpdatePullRequestStatus
s@UpdatePullRequestStatus' {} Text
a -> UpdatePullRequestStatus
s {$sel:pullRequestId:UpdatePullRequestStatus' :: Text
pullRequestId = Text
a} :: UpdatePullRequestStatus)

-- | The status of the pull request. The only valid operations are to update
-- the status from @OPEN@ to @OPEN@, @OPEN@ to @CLOSED@ or from @CLOSED@ to
-- @CLOSED@.
updatePullRequestStatus_pullRequestStatus :: Lens.Lens' UpdatePullRequestStatus PullRequestStatusEnum
updatePullRequestStatus_pullRequestStatus :: (PullRequestStatusEnum -> f PullRequestStatusEnum)
-> UpdatePullRequestStatus -> f UpdatePullRequestStatus
updatePullRequestStatus_pullRequestStatus = (UpdatePullRequestStatus -> PullRequestStatusEnum)
-> (UpdatePullRequestStatus
    -> PullRequestStatusEnum -> UpdatePullRequestStatus)
-> Lens
     UpdatePullRequestStatus
     UpdatePullRequestStatus
     PullRequestStatusEnum
     PullRequestStatusEnum
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePullRequestStatus' {PullRequestStatusEnum
pullRequestStatus :: PullRequestStatusEnum
$sel:pullRequestStatus:UpdatePullRequestStatus' :: UpdatePullRequestStatus -> PullRequestStatusEnum
pullRequestStatus} -> PullRequestStatusEnum
pullRequestStatus) (\s :: UpdatePullRequestStatus
s@UpdatePullRequestStatus' {} PullRequestStatusEnum
a -> UpdatePullRequestStatus
s {$sel:pullRequestStatus:UpdatePullRequestStatus' :: PullRequestStatusEnum
pullRequestStatus = PullRequestStatusEnum
a} :: UpdatePullRequestStatus)

instance Core.AWSRequest UpdatePullRequestStatus where
  type
    AWSResponse UpdatePullRequestStatus =
      UpdatePullRequestStatusResponse
  request :: UpdatePullRequestStatus -> Request UpdatePullRequestStatus
request = Service
-> UpdatePullRequestStatus -> Request UpdatePullRequestStatus
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdatePullRequestStatus
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdatePullRequestStatus)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdatePullRequestStatus))
-> Logger
-> Service
-> Proxy UpdatePullRequestStatus
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdatePullRequestStatus)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> PullRequest -> UpdatePullRequestStatusResponse
UpdatePullRequestStatusResponse'
            (Int -> PullRequest -> UpdatePullRequestStatusResponse)
-> Either String Int
-> Either String (PullRequest -> UpdatePullRequestStatusResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (PullRequest -> UpdatePullRequestStatusResponse)
-> Either String PullRequest
-> Either String UpdatePullRequestStatusResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String PullRequest
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"pullRequest")
      )

instance Prelude.Hashable UpdatePullRequestStatus

instance Prelude.NFData UpdatePullRequestStatus

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

instance Core.ToJSON UpdatePullRequestStatus where
  toJSON :: UpdatePullRequestStatus -> Value
toJSON UpdatePullRequestStatus' {Text
PullRequestStatusEnum
pullRequestStatus :: PullRequestStatusEnum
pullRequestId :: Text
$sel:pullRequestStatus:UpdatePullRequestStatus' :: UpdatePullRequestStatus -> PullRequestStatusEnum
$sel:pullRequestId:UpdatePullRequestStatus' :: UpdatePullRequestStatus -> 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
"pullRequestId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
pullRequestId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"pullRequestStatus" Text -> PullRequestStatusEnum -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PullRequestStatusEnum
pullRequestStatus)
          ]
      )

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

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

-- | /See:/ 'newUpdatePullRequestStatusResponse' smart constructor.
data UpdatePullRequestStatusResponse = UpdatePullRequestStatusResponse'
  { -- | The response's http status code.
    UpdatePullRequestStatusResponse -> Int
httpStatus :: Prelude.Int,
    -- | Information about the pull request.
    UpdatePullRequestStatusResponse -> PullRequest
pullRequest :: PullRequest
  }
  deriving (UpdatePullRequestStatusResponse
-> UpdatePullRequestStatusResponse -> Bool
(UpdatePullRequestStatusResponse
 -> UpdatePullRequestStatusResponse -> Bool)
-> (UpdatePullRequestStatusResponse
    -> UpdatePullRequestStatusResponse -> Bool)
-> Eq UpdatePullRequestStatusResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePullRequestStatusResponse
-> UpdatePullRequestStatusResponse -> Bool
$c/= :: UpdatePullRequestStatusResponse
-> UpdatePullRequestStatusResponse -> Bool
== :: UpdatePullRequestStatusResponse
-> UpdatePullRequestStatusResponse -> Bool
$c== :: UpdatePullRequestStatusResponse
-> UpdatePullRequestStatusResponse -> Bool
Prelude.Eq, ReadPrec [UpdatePullRequestStatusResponse]
ReadPrec UpdatePullRequestStatusResponse
Int -> ReadS UpdatePullRequestStatusResponse
ReadS [UpdatePullRequestStatusResponse]
(Int -> ReadS UpdatePullRequestStatusResponse)
-> ReadS [UpdatePullRequestStatusResponse]
-> ReadPrec UpdatePullRequestStatusResponse
-> ReadPrec [UpdatePullRequestStatusResponse]
-> Read UpdatePullRequestStatusResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePullRequestStatusResponse]
$creadListPrec :: ReadPrec [UpdatePullRequestStatusResponse]
readPrec :: ReadPrec UpdatePullRequestStatusResponse
$creadPrec :: ReadPrec UpdatePullRequestStatusResponse
readList :: ReadS [UpdatePullRequestStatusResponse]
$creadList :: ReadS [UpdatePullRequestStatusResponse]
readsPrec :: Int -> ReadS UpdatePullRequestStatusResponse
$creadsPrec :: Int -> ReadS UpdatePullRequestStatusResponse
Prelude.Read, Int -> UpdatePullRequestStatusResponse -> ShowS
[UpdatePullRequestStatusResponse] -> ShowS
UpdatePullRequestStatusResponse -> String
(Int -> UpdatePullRequestStatusResponse -> ShowS)
-> (UpdatePullRequestStatusResponse -> String)
-> ([UpdatePullRequestStatusResponse] -> ShowS)
-> Show UpdatePullRequestStatusResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePullRequestStatusResponse] -> ShowS
$cshowList :: [UpdatePullRequestStatusResponse] -> ShowS
show :: UpdatePullRequestStatusResponse -> String
$cshow :: UpdatePullRequestStatusResponse -> String
showsPrec :: Int -> UpdatePullRequestStatusResponse -> ShowS
$cshowsPrec :: Int -> UpdatePullRequestStatusResponse -> ShowS
Prelude.Show, (forall x.
 UpdatePullRequestStatusResponse
 -> Rep UpdatePullRequestStatusResponse x)
-> (forall x.
    Rep UpdatePullRequestStatusResponse x
    -> UpdatePullRequestStatusResponse)
-> Generic UpdatePullRequestStatusResponse
forall x.
Rep UpdatePullRequestStatusResponse x
-> UpdatePullRequestStatusResponse
forall x.
UpdatePullRequestStatusResponse
-> Rep UpdatePullRequestStatusResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdatePullRequestStatusResponse x
-> UpdatePullRequestStatusResponse
$cfrom :: forall x.
UpdatePullRequestStatusResponse
-> Rep UpdatePullRequestStatusResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePullRequestStatusResponse' 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:
--
-- 'httpStatus', 'updatePullRequestStatusResponse_httpStatus' - The response's http status code.
--
-- 'pullRequest', 'updatePullRequestStatusResponse_pullRequest' - Information about the pull request.
newUpdatePullRequestStatusResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'pullRequest'
  PullRequest ->
  UpdatePullRequestStatusResponse
newUpdatePullRequestStatusResponse :: Int -> PullRequest -> UpdatePullRequestStatusResponse
newUpdatePullRequestStatusResponse
  Int
pHttpStatus_
  PullRequest
pPullRequest_ =
    UpdatePullRequestStatusResponse' :: Int -> PullRequest -> UpdatePullRequestStatusResponse
UpdatePullRequestStatusResponse'
      { $sel:httpStatus:UpdatePullRequestStatusResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:pullRequest:UpdatePullRequestStatusResponse' :: PullRequest
pullRequest = PullRequest
pPullRequest_
      }

-- | The response's http status code.
updatePullRequestStatusResponse_httpStatus :: Lens.Lens' UpdatePullRequestStatusResponse Prelude.Int
updatePullRequestStatusResponse_httpStatus :: (Int -> f Int)
-> UpdatePullRequestStatusResponse
-> f UpdatePullRequestStatusResponse
updatePullRequestStatusResponse_httpStatus = (UpdatePullRequestStatusResponse -> Int)
-> (UpdatePullRequestStatusResponse
    -> Int -> UpdatePullRequestStatusResponse)
-> Lens
     UpdatePullRequestStatusResponse
     UpdatePullRequestStatusResponse
     Int
     Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePullRequestStatusResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdatePullRequestStatusResponse' :: UpdatePullRequestStatusResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: UpdatePullRequestStatusResponse
s@UpdatePullRequestStatusResponse' {} Int
a -> UpdatePullRequestStatusResponse
s {$sel:httpStatus:UpdatePullRequestStatusResponse' :: Int
httpStatus = Int
a} :: UpdatePullRequestStatusResponse)

-- | Information about the pull request.
updatePullRequestStatusResponse_pullRequest :: Lens.Lens' UpdatePullRequestStatusResponse PullRequest
updatePullRequestStatusResponse_pullRequest :: (PullRequest -> f PullRequest)
-> UpdatePullRequestStatusResponse
-> f UpdatePullRequestStatusResponse
updatePullRequestStatusResponse_pullRequest = (UpdatePullRequestStatusResponse -> PullRequest)
-> (UpdatePullRequestStatusResponse
    -> PullRequest -> UpdatePullRequestStatusResponse)
-> Lens
     UpdatePullRequestStatusResponse
     UpdatePullRequestStatusResponse
     PullRequest
     PullRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePullRequestStatusResponse' {PullRequest
pullRequest :: PullRequest
$sel:pullRequest:UpdatePullRequestStatusResponse' :: UpdatePullRequestStatusResponse -> PullRequest
pullRequest} -> PullRequest
pullRequest) (\s :: UpdatePullRequestStatusResponse
s@UpdatePullRequestStatusResponse' {} PullRequest
a -> UpdatePullRequestStatusResponse
s {$sel:pullRequest:UpdatePullRequestStatusResponse' :: PullRequest
pullRequest = PullRequest
a} :: UpdatePullRequestStatusResponse)

instance
  Prelude.NFData
    UpdatePullRequestStatusResponse