{-# 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.ListBranches
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets information about one or more branches in a repository.
--
-- This operation returns paginated results.
module Amazonka.CodeCommit.ListBranches
  ( -- * Creating a Request
    ListBranches (..),
    newListBranches,

    -- * Request Lenses
    listBranches_nextToken,
    listBranches_repositoryName,

    -- * Destructuring the Response
    ListBranchesResponse (..),
    newListBranchesResponse,

    -- * Response Lenses
    listBranchesResponse_branches,
    listBranchesResponse_nextToken,
    listBranchesResponse_httpStatus,
  )
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

-- | Represents the input of a list branches operation.
--
-- /See:/ 'newListBranches' smart constructor.
data ListBranches = ListBranches'
  { -- | An enumeration token that allows the operation to batch the results.
    ListBranches -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the repository that contains the branches.
    ListBranches -> Text
repositoryName :: Prelude.Text
  }
  deriving (ListBranches -> ListBranches -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBranches -> ListBranches -> Bool
$c/= :: ListBranches -> ListBranches -> Bool
== :: ListBranches -> ListBranches -> Bool
$c== :: ListBranches -> ListBranches -> Bool
Prelude.Eq, ReadPrec [ListBranches]
ReadPrec ListBranches
Int -> ReadS ListBranches
ReadS [ListBranches]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBranches]
$creadListPrec :: ReadPrec [ListBranches]
readPrec :: ReadPrec ListBranches
$creadPrec :: ReadPrec ListBranches
readList :: ReadS [ListBranches]
$creadList :: ReadS [ListBranches]
readsPrec :: Int -> ReadS ListBranches
$creadsPrec :: Int -> ReadS ListBranches
Prelude.Read, Int -> ListBranches -> ShowS
[ListBranches] -> ShowS
ListBranches -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBranches] -> ShowS
$cshowList :: [ListBranches] -> ShowS
show :: ListBranches -> String
$cshow :: ListBranches -> String
showsPrec :: Int -> ListBranches -> ShowS
$cshowsPrec :: Int -> ListBranches -> ShowS
Prelude.Show, forall x. Rep ListBranches x -> ListBranches
forall x. ListBranches -> Rep ListBranches x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBranches x -> ListBranches
$cfrom :: forall x. ListBranches -> Rep ListBranches x
Prelude.Generic)

-- |
-- Create a value of 'ListBranches' 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:
--
-- 'nextToken', 'listBranches_nextToken' - An enumeration token that allows the operation to batch the results.
--
-- 'repositoryName', 'listBranches_repositoryName' - The name of the repository that contains the branches.
newListBranches ::
  -- | 'repositoryName'
  Prelude.Text ->
  ListBranches
newListBranches :: Text -> ListBranches
newListBranches Text
pRepositoryName_ =
  ListBranches'
    { $sel:nextToken:ListBranches' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:repositoryName:ListBranches' :: Text
repositoryName = Text
pRepositoryName_
    }

-- | An enumeration token that allows the operation to batch the results.
listBranches_nextToken :: Lens.Lens' ListBranches (Prelude.Maybe Prelude.Text)
listBranches_nextToken :: Lens' ListBranches (Maybe Text)
listBranches_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBranches' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListBranches' :: ListBranches -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListBranches
s@ListBranches' {} Maybe Text
a -> ListBranches
s {$sel:nextToken:ListBranches' :: Maybe Text
nextToken = Maybe Text
a} :: ListBranches)

-- | The name of the repository that contains the branches.
listBranches_repositoryName :: Lens.Lens' ListBranches Prelude.Text
listBranches_repositoryName :: Lens' ListBranches Text
listBranches_repositoryName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBranches' {Text
repositoryName :: Text
$sel:repositoryName:ListBranches' :: ListBranches -> Text
repositoryName} -> Text
repositoryName) (\s :: ListBranches
s@ListBranches' {} Text
a -> ListBranches
s {$sel:repositoryName:ListBranches' :: Text
repositoryName = Text
a} :: ListBranches)

instance Core.AWSPager ListBranches where
  page :: ListBranches -> AWSResponse ListBranches -> Maybe ListBranches
page ListBranches
rq AWSResponse ListBranches
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListBranches
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBranchesResponse (Maybe Text)
listBranchesResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListBranches
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBranchesResponse (Maybe [Text])
listBranchesResponse_branches
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListBranches
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListBranches (Maybe Text)
listBranches_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListBranches
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBranchesResponse (Maybe Text)
listBranchesResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListBranches where
  type AWSResponse ListBranches = ListBranchesResponse
  request :: (Service -> Service) -> ListBranches -> Request ListBranches
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 ListBranches
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListBranches)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Text] -> Maybe Text -> Int -> ListBranchesResponse
ListBranchesResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"branches" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"nextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

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

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

instance Data.ToHeaders ListBranches where
  toHeaders :: ListBranches -> ResponseHeaders
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 -> ResponseHeaders
Data.=# ( ByteString
"CodeCommit_20150413.ListBranches" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListBranches where
  toJSON :: ListBranches -> Value
toJSON ListBranches' {Maybe Text
Text
repositoryName :: Text
nextToken :: Maybe Text
$sel:repositoryName:ListBranches' :: ListBranches -> Text
$sel:nextToken:ListBranches' :: ListBranches -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"nextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            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 ListBranches where
  toPath :: ListBranches -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | Represents the output of a list branches operation.
--
-- /See:/ 'newListBranchesResponse' smart constructor.
data ListBranchesResponse = ListBranchesResponse'
  { -- | The list of branch names.
    ListBranchesResponse -> Maybe [Text]
branches :: Prelude.Maybe [Prelude.Text],
    -- | An enumeration token that returns the batch of the results.
    ListBranchesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListBranchesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListBranchesResponse -> ListBranchesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBranchesResponse -> ListBranchesResponse -> Bool
$c/= :: ListBranchesResponse -> ListBranchesResponse -> Bool
== :: ListBranchesResponse -> ListBranchesResponse -> Bool
$c== :: ListBranchesResponse -> ListBranchesResponse -> Bool
Prelude.Eq, ReadPrec [ListBranchesResponse]
ReadPrec ListBranchesResponse
Int -> ReadS ListBranchesResponse
ReadS [ListBranchesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBranchesResponse]
$creadListPrec :: ReadPrec [ListBranchesResponse]
readPrec :: ReadPrec ListBranchesResponse
$creadPrec :: ReadPrec ListBranchesResponse
readList :: ReadS [ListBranchesResponse]
$creadList :: ReadS [ListBranchesResponse]
readsPrec :: Int -> ReadS ListBranchesResponse
$creadsPrec :: Int -> ReadS ListBranchesResponse
Prelude.Read, Int -> ListBranchesResponse -> ShowS
[ListBranchesResponse] -> ShowS
ListBranchesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBranchesResponse] -> ShowS
$cshowList :: [ListBranchesResponse] -> ShowS
show :: ListBranchesResponse -> String
$cshow :: ListBranchesResponse -> String
showsPrec :: Int -> ListBranchesResponse -> ShowS
$cshowsPrec :: Int -> ListBranchesResponse -> ShowS
Prelude.Show, forall x. Rep ListBranchesResponse x -> ListBranchesResponse
forall x. ListBranchesResponse -> Rep ListBranchesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBranchesResponse x -> ListBranchesResponse
$cfrom :: forall x. ListBranchesResponse -> Rep ListBranchesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListBranchesResponse' 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:
--
-- 'branches', 'listBranchesResponse_branches' - The list of branch names.
--
-- 'nextToken', 'listBranchesResponse_nextToken' - An enumeration token that returns the batch of the results.
--
-- 'httpStatus', 'listBranchesResponse_httpStatus' - The response's http status code.
newListBranchesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListBranchesResponse
newListBranchesResponse :: Int -> ListBranchesResponse
newListBranchesResponse Int
pHttpStatus_ =
  ListBranchesResponse'
    { $sel:branches:ListBranchesResponse' :: Maybe [Text]
branches = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListBranchesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListBranchesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of branch names.
listBranchesResponse_branches :: Lens.Lens' ListBranchesResponse (Prelude.Maybe [Prelude.Text])
listBranchesResponse_branches :: Lens' ListBranchesResponse (Maybe [Text])
listBranchesResponse_branches = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBranchesResponse' {Maybe [Text]
branches :: Maybe [Text]
$sel:branches:ListBranchesResponse' :: ListBranchesResponse -> Maybe [Text]
branches} -> Maybe [Text]
branches) (\s :: ListBranchesResponse
s@ListBranchesResponse' {} Maybe [Text]
a -> ListBranchesResponse
s {$sel:branches:ListBranchesResponse' :: Maybe [Text]
branches = Maybe [Text]
a} :: ListBranchesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An enumeration token that returns the batch of the results.
listBranchesResponse_nextToken :: Lens.Lens' ListBranchesResponse (Prelude.Maybe Prelude.Text)
listBranchesResponse_nextToken :: Lens' ListBranchesResponse (Maybe Text)
listBranchesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBranchesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListBranchesResponse' :: ListBranchesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListBranchesResponse
s@ListBranchesResponse' {} Maybe Text
a -> ListBranchesResponse
s {$sel:nextToken:ListBranchesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListBranchesResponse)

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

instance Prelude.NFData ListBranchesResponse where
  rnf :: ListBranchesResponse -> ()
rnf ListBranchesResponse' {Int
Maybe [Text]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
branches :: Maybe [Text]
$sel:httpStatus:ListBranchesResponse' :: ListBranchesResponse -> Int
$sel:nextToken:ListBranchesResponse' :: ListBranchesResponse -> Maybe Text
$sel:branches:ListBranchesResponse' :: ListBranchesResponse -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
branches
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus