{-# 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.GetCommit
-- 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)
--
-- Returns information about a commit, including commit message and
-- committer information.
module Amazonka.CodeCommit.GetCommit
  ( -- * Creating a Request
    GetCommit (..),
    newGetCommit,

    -- * Request Lenses
    getCommit_repositoryName,
    getCommit_commitId,

    -- * Destructuring the Response
    GetCommitResponse (..),
    newGetCommitResponse,

    -- * Response Lenses
    getCommitResponse_httpStatus,
    getCommitResponse_commit,
  )
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

-- | Represents the input of a get commit operation.
--
-- /See:/ 'newGetCommit' smart constructor.
data GetCommit = GetCommit'
  { -- | The name of the repository to which the commit was made.
    GetCommit -> Text
repositoryName :: Prelude.Text,
    -- | The commit ID. Commit IDs are the full SHA ID of the commit.
    GetCommit -> Text
commitId :: Prelude.Text
  }
  deriving (GetCommit -> GetCommit -> Bool
(GetCommit -> GetCommit -> Bool)
-> (GetCommit -> GetCommit -> Bool) -> Eq GetCommit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCommit -> GetCommit -> Bool
$c/= :: GetCommit -> GetCommit -> Bool
== :: GetCommit -> GetCommit -> Bool
$c== :: GetCommit -> GetCommit -> Bool
Prelude.Eq, ReadPrec [GetCommit]
ReadPrec GetCommit
Int -> ReadS GetCommit
ReadS [GetCommit]
(Int -> ReadS GetCommit)
-> ReadS [GetCommit]
-> ReadPrec GetCommit
-> ReadPrec [GetCommit]
-> Read GetCommit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCommit]
$creadListPrec :: ReadPrec [GetCommit]
readPrec :: ReadPrec GetCommit
$creadPrec :: ReadPrec GetCommit
readList :: ReadS [GetCommit]
$creadList :: ReadS [GetCommit]
readsPrec :: Int -> ReadS GetCommit
$creadsPrec :: Int -> ReadS GetCommit
Prelude.Read, Int -> GetCommit -> ShowS
[GetCommit] -> ShowS
GetCommit -> String
(Int -> GetCommit -> ShowS)
-> (GetCommit -> String)
-> ([GetCommit] -> ShowS)
-> Show GetCommit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCommit] -> ShowS
$cshowList :: [GetCommit] -> ShowS
show :: GetCommit -> String
$cshow :: GetCommit -> String
showsPrec :: Int -> GetCommit -> ShowS
$cshowsPrec :: Int -> GetCommit -> ShowS
Prelude.Show, (forall x. GetCommit -> Rep GetCommit x)
-> (forall x. Rep GetCommit x -> GetCommit) -> Generic GetCommit
forall x. Rep GetCommit x -> GetCommit
forall x. GetCommit -> Rep GetCommit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCommit x -> GetCommit
$cfrom :: forall x. GetCommit -> Rep GetCommit x
Prelude.Generic)

-- |
-- Create a value of 'GetCommit' 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:
--
-- 'repositoryName', 'getCommit_repositoryName' - The name of the repository to which the commit was made.
--
-- 'commitId', 'getCommit_commitId' - The commit ID. Commit IDs are the full SHA ID of the commit.
newGetCommit ::
  -- | 'repositoryName'
  Prelude.Text ->
  -- | 'commitId'
  Prelude.Text ->
  GetCommit
newGetCommit :: Text -> Text -> GetCommit
newGetCommit Text
pRepositoryName_ Text
pCommitId_ =
  GetCommit' :: Text -> Text -> GetCommit
GetCommit'
    { $sel:repositoryName:GetCommit' :: Text
repositoryName = Text
pRepositoryName_,
      $sel:commitId:GetCommit' :: Text
commitId = Text
pCommitId_
    }

-- | The name of the repository to which the commit was made.
getCommit_repositoryName :: Lens.Lens' GetCommit Prelude.Text
getCommit_repositoryName :: (Text -> f Text) -> GetCommit -> f GetCommit
getCommit_repositoryName = (GetCommit -> Text)
-> (GetCommit -> Text -> GetCommit)
-> Lens GetCommit GetCommit Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCommit' {Text
repositoryName :: Text
$sel:repositoryName:GetCommit' :: GetCommit -> Text
repositoryName} -> Text
repositoryName) (\s :: GetCommit
s@GetCommit' {} Text
a -> GetCommit
s {$sel:repositoryName:GetCommit' :: Text
repositoryName = Text
a} :: GetCommit)

-- | The commit ID. Commit IDs are the full SHA ID of the commit.
getCommit_commitId :: Lens.Lens' GetCommit Prelude.Text
getCommit_commitId :: (Text -> f Text) -> GetCommit -> f GetCommit
getCommit_commitId = (GetCommit -> Text)
-> (GetCommit -> Text -> GetCommit)
-> Lens GetCommit GetCommit Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCommit' {Text
commitId :: Text
$sel:commitId:GetCommit' :: GetCommit -> Text
commitId} -> Text
commitId) (\s :: GetCommit
s@GetCommit' {} Text
a -> GetCommit
s {$sel:commitId:GetCommit' :: Text
commitId = Text
a} :: GetCommit)

instance Core.AWSRequest GetCommit where
  type AWSResponse GetCommit = GetCommitResponse
  request :: GetCommit -> Request GetCommit
request = Service -> GetCommit -> Request GetCommit
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCommit
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCommit)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetCommit))
-> Logger
-> Service
-> Proxy GetCommit
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCommit)))
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 -> Commit -> GetCommitResponse
GetCommitResponse'
            (Int -> Commit -> GetCommitResponse)
-> Either String Int -> Either String (Commit -> GetCommitResponse)
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 (Commit -> GetCommitResponse)
-> Either String Commit -> Either String GetCommitResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Commit
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"commit")
      )

instance Prelude.Hashable GetCommit

instance Prelude.NFData GetCommit

instance Core.ToHeaders GetCommit where
  toHeaders :: GetCommit -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetCommit -> 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.GetCommit" ::
                          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 GetCommit where
  toJSON :: GetCommit -> Value
toJSON GetCommit' {Text
commitId :: Text
repositoryName :: Text
$sel:commitId:GetCommit' :: GetCommit -> Text
$sel:repositoryName:GetCommit' :: GetCommit -> 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
"repositoryName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
repositoryName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"commitId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
commitId)
          ]
      )

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

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

-- | Represents the output of a get commit operation.
--
-- /See:/ 'newGetCommitResponse' smart constructor.
data GetCommitResponse = GetCommitResponse'
  { -- | The response's http status code.
    GetCommitResponse -> Int
httpStatus :: Prelude.Int,
    -- | A commit data type object that contains information about the specified
    -- commit.
    GetCommitResponse -> Commit
commit :: Commit
  }
  deriving (GetCommitResponse -> GetCommitResponse -> Bool
(GetCommitResponse -> GetCommitResponse -> Bool)
-> (GetCommitResponse -> GetCommitResponse -> Bool)
-> Eq GetCommitResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCommitResponse -> GetCommitResponse -> Bool
$c/= :: GetCommitResponse -> GetCommitResponse -> Bool
== :: GetCommitResponse -> GetCommitResponse -> Bool
$c== :: GetCommitResponse -> GetCommitResponse -> Bool
Prelude.Eq, ReadPrec [GetCommitResponse]
ReadPrec GetCommitResponse
Int -> ReadS GetCommitResponse
ReadS [GetCommitResponse]
(Int -> ReadS GetCommitResponse)
-> ReadS [GetCommitResponse]
-> ReadPrec GetCommitResponse
-> ReadPrec [GetCommitResponse]
-> Read GetCommitResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCommitResponse]
$creadListPrec :: ReadPrec [GetCommitResponse]
readPrec :: ReadPrec GetCommitResponse
$creadPrec :: ReadPrec GetCommitResponse
readList :: ReadS [GetCommitResponse]
$creadList :: ReadS [GetCommitResponse]
readsPrec :: Int -> ReadS GetCommitResponse
$creadsPrec :: Int -> ReadS GetCommitResponse
Prelude.Read, Int -> GetCommitResponse -> ShowS
[GetCommitResponse] -> ShowS
GetCommitResponse -> String
(Int -> GetCommitResponse -> ShowS)
-> (GetCommitResponse -> String)
-> ([GetCommitResponse] -> ShowS)
-> Show GetCommitResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCommitResponse] -> ShowS
$cshowList :: [GetCommitResponse] -> ShowS
show :: GetCommitResponse -> String
$cshow :: GetCommitResponse -> String
showsPrec :: Int -> GetCommitResponse -> ShowS
$cshowsPrec :: Int -> GetCommitResponse -> ShowS
Prelude.Show, (forall x. GetCommitResponse -> Rep GetCommitResponse x)
-> (forall x. Rep GetCommitResponse x -> GetCommitResponse)
-> Generic GetCommitResponse
forall x. Rep GetCommitResponse x -> GetCommitResponse
forall x. GetCommitResponse -> Rep GetCommitResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCommitResponse x -> GetCommitResponse
$cfrom :: forall x. GetCommitResponse -> Rep GetCommitResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCommitResponse' 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', 'getCommitResponse_httpStatus' - The response's http status code.
--
-- 'commit', 'getCommitResponse_commit' - A commit data type object that contains information about the specified
-- commit.
newGetCommitResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'commit'
  Commit ->
  GetCommitResponse
newGetCommitResponse :: Int -> Commit -> GetCommitResponse
newGetCommitResponse Int
pHttpStatus_ Commit
pCommit_ =
  GetCommitResponse' :: Int -> Commit -> GetCommitResponse
GetCommitResponse'
    { $sel:httpStatus:GetCommitResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:commit:GetCommitResponse' :: Commit
commit = Commit
pCommit_
    }

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

-- | A commit data type object that contains information about the specified
-- commit.
getCommitResponse_commit :: Lens.Lens' GetCommitResponse Commit
getCommitResponse_commit :: (Commit -> f Commit) -> GetCommitResponse -> f GetCommitResponse
getCommitResponse_commit = (GetCommitResponse -> Commit)
-> (GetCommitResponse -> Commit -> GetCommitResponse)
-> Lens GetCommitResponse GetCommitResponse Commit Commit
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCommitResponse' {Commit
commit :: Commit
$sel:commit:GetCommitResponse' :: GetCommitResponse -> Commit
commit} -> Commit
commit) (\s :: GetCommitResponse
s@GetCommitResponse' {} Commit
a -> GetCommitResponse
s {$sel:commit:GetCommitResponse' :: Commit
commit = Commit
a} :: GetCommitResponse)

instance Prelude.NFData GetCommitResponse