{-# 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.CodePipeline.StartPipelineExecution
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts the specified pipeline. Specifically, it begins processing the
-- latest commit to the source location specified as part of the pipeline.
module Amazonka.CodePipeline.StartPipelineExecution
  ( -- * Creating a Request
    StartPipelineExecution (..),
    newStartPipelineExecution,

    -- * Request Lenses
    startPipelineExecution_clientRequestToken,
    startPipelineExecution_name,

    -- * Destructuring the Response
    StartPipelineExecutionResponse (..),
    newStartPipelineExecutionResponse,

    -- * Response Lenses
    startPipelineExecutionResponse_pipelineExecutionId,
    startPipelineExecutionResponse_httpStatus,
  )
where

import Amazonka.CodePipeline.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 @StartPipelineExecution@ action.
--
-- /See:/ 'newStartPipelineExecution' smart constructor.
data StartPipelineExecution = StartPipelineExecution'
  { -- | The system-generated unique ID used to identify a unique execution
    -- request.
    StartPipelineExecution -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the pipeline to start.
    StartPipelineExecution -> Text
name :: Prelude.Text
  }
  deriving (StartPipelineExecution -> StartPipelineExecution -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartPipelineExecution -> StartPipelineExecution -> Bool
$c/= :: StartPipelineExecution -> StartPipelineExecution -> Bool
== :: StartPipelineExecution -> StartPipelineExecution -> Bool
$c== :: StartPipelineExecution -> StartPipelineExecution -> Bool
Prelude.Eq, ReadPrec [StartPipelineExecution]
ReadPrec StartPipelineExecution
Int -> ReadS StartPipelineExecution
ReadS [StartPipelineExecution]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartPipelineExecution]
$creadListPrec :: ReadPrec [StartPipelineExecution]
readPrec :: ReadPrec StartPipelineExecution
$creadPrec :: ReadPrec StartPipelineExecution
readList :: ReadS [StartPipelineExecution]
$creadList :: ReadS [StartPipelineExecution]
readsPrec :: Int -> ReadS StartPipelineExecution
$creadsPrec :: Int -> ReadS StartPipelineExecution
Prelude.Read, Int -> StartPipelineExecution -> ShowS
[StartPipelineExecution] -> ShowS
StartPipelineExecution -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartPipelineExecution] -> ShowS
$cshowList :: [StartPipelineExecution] -> ShowS
show :: StartPipelineExecution -> String
$cshow :: StartPipelineExecution -> String
showsPrec :: Int -> StartPipelineExecution -> ShowS
$cshowsPrec :: Int -> StartPipelineExecution -> ShowS
Prelude.Show, forall x. Rep StartPipelineExecution x -> StartPipelineExecution
forall x. StartPipelineExecution -> Rep StartPipelineExecution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartPipelineExecution x -> StartPipelineExecution
$cfrom :: forall x. StartPipelineExecution -> Rep StartPipelineExecution x
Prelude.Generic)

-- |
-- Create a value of 'StartPipelineExecution' 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:
--
-- 'clientRequestToken', 'startPipelineExecution_clientRequestToken' - The system-generated unique ID used to identify a unique execution
-- request.
--
-- 'name', 'startPipelineExecution_name' - The name of the pipeline to start.
newStartPipelineExecution ::
  -- | 'name'
  Prelude.Text ->
  StartPipelineExecution
newStartPipelineExecution :: Text -> StartPipelineExecution
newStartPipelineExecution Text
pName_ =
  StartPipelineExecution'
    { $sel:clientRequestToken:StartPipelineExecution' :: Maybe Text
clientRequestToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:name:StartPipelineExecution' :: Text
name = Text
pName_
    }

-- | The system-generated unique ID used to identify a unique execution
-- request.
startPipelineExecution_clientRequestToken :: Lens.Lens' StartPipelineExecution (Prelude.Maybe Prelude.Text)
startPipelineExecution_clientRequestToken :: Lens' StartPipelineExecution (Maybe Text)
startPipelineExecution_clientRequestToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartPipelineExecution' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:StartPipelineExecution' :: StartPipelineExecution -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: StartPipelineExecution
s@StartPipelineExecution' {} Maybe Text
a -> StartPipelineExecution
s {$sel:clientRequestToken:StartPipelineExecution' :: Maybe Text
clientRequestToken = Maybe Text
a} :: StartPipelineExecution)

-- | The name of the pipeline to start.
startPipelineExecution_name :: Lens.Lens' StartPipelineExecution Prelude.Text
startPipelineExecution_name :: Lens' StartPipelineExecution Text
startPipelineExecution_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartPipelineExecution' {Text
name :: Text
$sel:name:StartPipelineExecution' :: StartPipelineExecution -> Text
name} -> Text
name) (\s :: StartPipelineExecution
s@StartPipelineExecution' {} Text
a -> StartPipelineExecution
s {$sel:name:StartPipelineExecution' :: Text
name = Text
a} :: StartPipelineExecution)

instance Core.AWSRequest StartPipelineExecution where
  type
    AWSResponse StartPipelineExecution =
      StartPipelineExecutionResponse
  request :: (Service -> Service)
-> StartPipelineExecution -> Request StartPipelineExecution
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 StartPipelineExecution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartPipelineExecution)))
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 -> Int -> StartPipelineExecutionResponse
StartPipelineExecutionResponse'
            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
"pipelineExecutionId")
            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 StartPipelineExecution where
  hashWithSalt :: Int -> StartPipelineExecution -> Int
hashWithSalt Int
_salt StartPipelineExecution' {Maybe Text
Text
name :: Text
clientRequestToken :: Maybe Text
$sel:name:StartPipelineExecution' :: StartPipelineExecution -> Text
$sel:clientRequestToken:StartPipelineExecution' :: StartPipelineExecution -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientRequestToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

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

instance Data.ToHeaders StartPipelineExecution where
  toHeaders :: StartPipelineExecution -> 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
"CodePipeline_20150709.StartPipelineExecution" ::
                          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 StartPipelineExecution where
  toJSON :: StartPipelineExecution -> Value
toJSON StartPipelineExecution' {Maybe Text
Text
name :: Text
clientRequestToken :: Maybe Text
$sel:name:StartPipelineExecution' :: StartPipelineExecution -> Text
$sel:clientRequestToken:StartPipelineExecution' :: StartPipelineExecution -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"clientRequestToken" 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
clientRequestToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

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

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

-- | Represents the output of a @StartPipelineExecution@ action.
--
-- /See:/ 'newStartPipelineExecutionResponse' smart constructor.
data StartPipelineExecutionResponse = StartPipelineExecutionResponse'
  { -- | The unique system-generated ID of the pipeline execution that was
    -- started.
    StartPipelineExecutionResponse -> Maybe Text
pipelineExecutionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    StartPipelineExecutionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
$c/= :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
== :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
$c== :: StartPipelineExecutionResponse
-> StartPipelineExecutionResponse -> Bool
Prelude.Eq, ReadPrec [StartPipelineExecutionResponse]
ReadPrec StartPipelineExecutionResponse
Int -> ReadS StartPipelineExecutionResponse
ReadS [StartPipelineExecutionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartPipelineExecutionResponse]
$creadListPrec :: ReadPrec [StartPipelineExecutionResponse]
readPrec :: ReadPrec StartPipelineExecutionResponse
$creadPrec :: ReadPrec StartPipelineExecutionResponse
readList :: ReadS [StartPipelineExecutionResponse]
$creadList :: ReadS [StartPipelineExecutionResponse]
readsPrec :: Int -> ReadS StartPipelineExecutionResponse
$creadsPrec :: Int -> ReadS StartPipelineExecutionResponse
Prelude.Read, Int -> StartPipelineExecutionResponse -> ShowS
[StartPipelineExecutionResponse] -> ShowS
StartPipelineExecutionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartPipelineExecutionResponse] -> ShowS
$cshowList :: [StartPipelineExecutionResponse] -> ShowS
show :: StartPipelineExecutionResponse -> String
$cshow :: StartPipelineExecutionResponse -> String
showsPrec :: Int -> StartPipelineExecutionResponse -> ShowS
$cshowsPrec :: Int -> StartPipelineExecutionResponse -> ShowS
Prelude.Show, forall x.
Rep StartPipelineExecutionResponse x
-> StartPipelineExecutionResponse
forall x.
StartPipelineExecutionResponse
-> Rep StartPipelineExecutionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartPipelineExecutionResponse x
-> StartPipelineExecutionResponse
$cfrom :: forall x.
StartPipelineExecutionResponse
-> Rep StartPipelineExecutionResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartPipelineExecutionResponse' 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:
--
-- 'pipelineExecutionId', 'startPipelineExecutionResponse_pipelineExecutionId' - The unique system-generated ID of the pipeline execution that was
-- started.
--
-- 'httpStatus', 'startPipelineExecutionResponse_httpStatus' - The response's http status code.
newStartPipelineExecutionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartPipelineExecutionResponse
newStartPipelineExecutionResponse :: Int -> StartPipelineExecutionResponse
newStartPipelineExecutionResponse Int
pHttpStatus_ =
  StartPipelineExecutionResponse'
    { $sel:pipelineExecutionId:StartPipelineExecutionResponse' :: Maybe Text
pipelineExecutionId =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartPipelineExecutionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique system-generated ID of the pipeline execution that was
-- started.
startPipelineExecutionResponse_pipelineExecutionId :: Lens.Lens' StartPipelineExecutionResponse (Prelude.Maybe Prelude.Text)
startPipelineExecutionResponse_pipelineExecutionId :: Lens' StartPipelineExecutionResponse (Maybe Text)
startPipelineExecutionResponse_pipelineExecutionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartPipelineExecutionResponse' {Maybe Text
pipelineExecutionId :: Maybe Text
$sel:pipelineExecutionId:StartPipelineExecutionResponse' :: StartPipelineExecutionResponse -> Maybe Text
pipelineExecutionId} -> Maybe Text
pipelineExecutionId) (\s :: StartPipelineExecutionResponse
s@StartPipelineExecutionResponse' {} Maybe Text
a -> StartPipelineExecutionResponse
s {$sel:pipelineExecutionId:StartPipelineExecutionResponse' :: Maybe Text
pipelineExecutionId = Maybe Text
a} :: StartPipelineExecutionResponse)

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

instance
  Prelude.NFData
    StartPipelineExecutionResponse
  where
  rnf :: StartPipelineExecutionResponse -> ()
rnf StartPipelineExecutionResponse' {Int
Maybe Text
httpStatus :: Int
pipelineExecutionId :: Maybe Text
$sel:httpStatus:StartPipelineExecutionResponse' :: StartPipelineExecutionResponse -> Int
$sel:pipelineExecutionId:StartPipelineExecutionResponse' :: StartPipelineExecutionResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
pipelineExecutionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus