{-# 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.GetRepository
-- 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 repository.
--
-- The description field for a repository accepts all HTML characters and
-- all valid Unicode characters. Applications that do not HTML-encode the
-- description and display it in a webpage can expose users to potentially
-- malicious code. Make sure that you HTML-encode the description field in
-- any application that uses this API to display the repository description
-- on a webpage.
module Amazonka.CodeCommit.GetRepository
  ( -- * Creating a Request
    GetRepository (..),
    newGetRepository,

    -- * Request Lenses
    getRepository_repositoryName,

    -- * Destructuring the Response
    GetRepositoryResponse (..),
    newGetRepositoryResponse,

    -- * Response Lenses
    getRepositoryResponse_repositoryMetadata,
    getRepositoryResponse_httpStatus,
  )
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 repository operation.
--
-- /See:/ 'newGetRepository' smart constructor.
data GetRepository = GetRepository'
  { -- | The name of the repository to get information about.
    GetRepository -> Text
repositoryName :: Prelude.Text
  }
  deriving (GetRepository -> GetRepository -> Bool
(GetRepository -> GetRepository -> Bool)
-> (GetRepository -> GetRepository -> Bool) -> Eq GetRepository
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRepository -> GetRepository -> Bool
$c/= :: GetRepository -> GetRepository -> Bool
== :: GetRepository -> GetRepository -> Bool
$c== :: GetRepository -> GetRepository -> Bool
Prelude.Eq, ReadPrec [GetRepository]
ReadPrec GetRepository
Int -> ReadS GetRepository
ReadS [GetRepository]
(Int -> ReadS GetRepository)
-> ReadS [GetRepository]
-> ReadPrec GetRepository
-> ReadPrec [GetRepository]
-> Read GetRepository
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRepository]
$creadListPrec :: ReadPrec [GetRepository]
readPrec :: ReadPrec GetRepository
$creadPrec :: ReadPrec GetRepository
readList :: ReadS [GetRepository]
$creadList :: ReadS [GetRepository]
readsPrec :: Int -> ReadS GetRepository
$creadsPrec :: Int -> ReadS GetRepository
Prelude.Read, Int -> GetRepository -> ShowS
[GetRepository] -> ShowS
GetRepository -> String
(Int -> GetRepository -> ShowS)
-> (GetRepository -> String)
-> ([GetRepository] -> ShowS)
-> Show GetRepository
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRepository] -> ShowS
$cshowList :: [GetRepository] -> ShowS
show :: GetRepository -> String
$cshow :: GetRepository -> String
showsPrec :: Int -> GetRepository -> ShowS
$cshowsPrec :: Int -> GetRepository -> ShowS
Prelude.Show, (forall x. GetRepository -> Rep GetRepository x)
-> (forall x. Rep GetRepository x -> GetRepository)
-> Generic GetRepository
forall x. Rep GetRepository x -> GetRepository
forall x. GetRepository -> Rep GetRepository x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRepository x -> GetRepository
$cfrom :: forall x. GetRepository -> Rep GetRepository x
Prelude.Generic)

-- |
-- Create a value of 'GetRepository' 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', 'getRepository_repositoryName' - The name of the repository to get information about.
newGetRepository ::
  -- | 'repositoryName'
  Prelude.Text ->
  GetRepository
newGetRepository :: Text -> GetRepository
newGetRepository Text
pRepositoryName_ =
  GetRepository' :: Text -> GetRepository
GetRepository' {$sel:repositoryName:GetRepository' :: Text
repositoryName = Text
pRepositoryName_}

-- | The name of the repository to get information about.
getRepository_repositoryName :: Lens.Lens' GetRepository Prelude.Text
getRepository_repositoryName :: (Text -> f Text) -> GetRepository -> f GetRepository
getRepository_repositoryName = (GetRepository -> Text)
-> (GetRepository -> Text -> GetRepository)
-> Lens GetRepository GetRepository Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRepository' {Text
repositoryName :: Text
$sel:repositoryName:GetRepository' :: GetRepository -> Text
repositoryName} -> Text
repositoryName) (\s :: GetRepository
s@GetRepository' {} Text
a -> GetRepository
s {$sel:repositoryName:GetRepository' :: Text
repositoryName = Text
a} :: GetRepository)

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

instance Prelude.Hashable GetRepository

instance Prelude.NFData GetRepository

instance Core.ToHeaders GetRepository where
  toHeaders :: GetRepository -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetRepository -> 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.GetRepository" ::
                          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 GetRepository where
  toJSON :: GetRepository -> Value
toJSON GetRepository' {Text
repositoryName :: Text
$sel:repositoryName:GetRepository' :: GetRepository -> 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)
          ]
      )

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

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

-- | Represents the output of a get repository operation.
--
-- /See:/ 'newGetRepositoryResponse' smart constructor.
data GetRepositoryResponse = GetRepositoryResponse'
  { -- | Information about the repository.
    GetRepositoryResponse -> Maybe RepositoryMetadata
repositoryMetadata :: Prelude.Maybe RepositoryMetadata,
    -- | The response's http status code.
    GetRepositoryResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetRepositoryResponse -> GetRepositoryResponse -> Bool
(GetRepositoryResponse -> GetRepositoryResponse -> Bool)
-> (GetRepositoryResponse -> GetRepositoryResponse -> Bool)
-> Eq GetRepositoryResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRepositoryResponse -> GetRepositoryResponse -> Bool
$c/= :: GetRepositoryResponse -> GetRepositoryResponse -> Bool
== :: GetRepositoryResponse -> GetRepositoryResponse -> Bool
$c== :: GetRepositoryResponse -> GetRepositoryResponse -> Bool
Prelude.Eq, ReadPrec [GetRepositoryResponse]
ReadPrec GetRepositoryResponse
Int -> ReadS GetRepositoryResponse
ReadS [GetRepositoryResponse]
(Int -> ReadS GetRepositoryResponse)
-> ReadS [GetRepositoryResponse]
-> ReadPrec GetRepositoryResponse
-> ReadPrec [GetRepositoryResponse]
-> Read GetRepositoryResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRepositoryResponse]
$creadListPrec :: ReadPrec [GetRepositoryResponse]
readPrec :: ReadPrec GetRepositoryResponse
$creadPrec :: ReadPrec GetRepositoryResponse
readList :: ReadS [GetRepositoryResponse]
$creadList :: ReadS [GetRepositoryResponse]
readsPrec :: Int -> ReadS GetRepositoryResponse
$creadsPrec :: Int -> ReadS GetRepositoryResponse
Prelude.Read, Int -> GetRepositoryResponse -> ShowS
[GetRepositoryResponse] -> ShowS
GetRepositoryResponse -> String
(Int -> GetRepositoryResponse -> ShowS)
-> (GetRepositoryResponse -> String)
-> ([GetRepositoryResponse] -> ShowS)
-> Show GetRepositoryResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRepositoryResponse] -> ShowS
$cshowList :: [GetRepositoryResponse] -> ShowS
show :: GetRepositoryResponse -> String
$cshow :: GetRepositoryResponse -> String
showsPrec :: Int -> GetRepositoryResponse -> ShowS
$cshowsPrec :: Int -> GetRepositoryResponse -> ShowS
Prelude.Show, (forall x. GetRepositoryResponse -> Rep GetRepositoryResponse x)
-> (forall x. Rep GetRepositoryResponse x -> GetRepositoryResponse)
-> Generic GetRepositoryResponse
forall x. Rep GetRepositoryResponse x -> GetRepositoryResponse
forall x. GetRepositoryResponse -> Rep GetRepositoryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRepositoryResponse x -> GetRepositoryResponse
$cfrom :: forall x. GetRepositoryResponse -> Rep GetRepositoryResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRepositoryResponse' 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:
--
-- 'repositoryMetadata', 'getRepositoryResponse_repositoryMetadata' - Information about the repository.
--
-- 'httpStatus', 'getRepositoryResponse_httpStatus' - The response's http status code.
newGetRepositoryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRepositoryResponse
newGetRepositoryResponse :: Int -> GetRepositoryResponse
newGetRepositoryResponse Int
pHttpStatus_ =
  GetRepositoryResponse' :: Maybe RepositoryMetadata -> Int -> GetRepositoryResponse
GetRepositoryResponse'
    { $sel:repositoryMetadata:GetRepositoryResponse' :: Maybe RepositoryMetadata
repositoryMetadata =
        Maybe RepositoryMetadata
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRepositoryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the repository.
getRepositoryResponse_repositoryMetadata :: Lens.Lens' GetRepositoryResponse (Prelude.Maybe RepositoryMetadata)
getRepositoryResponse_repositoryMetadata :: (Maybe RepositoryMetadata -> f (Maybe RepositoryMetadata))
-> GetRepositoryResponse -> f GetRepositoryResponse
getRepositoryResponse_repositoryMetadata = (GetRepositoryResponse -> Maybe RepositoryMetadata)
-> (GetRepositoryResponse
    -> Maybe RepositoryMetadata -> GetRepositoryResponse)
-> Lens
     GetRepositoryResponse
     GetRepositoryResponse
     (Maybe RepositoryMetadata)
     (Maybe RepositoryMetadata)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRepositoryResponse' {Maybe RepositoryMetadata
repositoryMetadata :: Maybe RepositoryMetadata
$sel:repositoryMetadata:GetRepositoryResponse' :: GetRepositoryResponse -> Maybe RepositoryMetadata
repositoryMetadata} -> Maybe RepositoryMetadata
repositoryMetadata) (\s :: GetRepositoryResponse
s@GetRepositoryResponse' {} Maybe RepositoryMetadata
a -> GetRepositoryResponse
s {$sel:repositoryMetadata:GetRepositoryResponse' :: Maybe RepositoryMetadata
repositoryMetadata = Maybe RepositoryMetadata
a} :: GetRepositoryResponse)

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

instance Prelude.NFData GetRepositoryResponse