{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeBuild.Types.ProjectSourceVersion
-- 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)
module Amazonka.CodeBuild.Types.ProjectSourceVersion where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A source identifier and its corresponding version.
--
-- /See:/ 'newProjectSourceVersion' smart constructor.
data ProjectSourceVersion = ProjectSourceVersion'
  { -- | An identifier for a source in the build project. The identifier can only
    -- contain alphanumeric characters and underscores, and must be less than
    -- 128 characters in length.
    ProjectSourceVersion -> Text
sourceIdentifier :: Prelude.Text,
    -- | The source version for the corresponding source identifier. If
    -- specified, must be one of:
    --
    -- -   For CodeCommit: the commit ID, branch, or Git tag to use.
    --
    -- -   For GitHub: the commit ID, pull request ID, branch name, or tag name
    --     that corresponds to the version of the source code you want to
    --     build. If a pull request ID is specified, it must use the format
    --     @pr\/pull-request-ID@ (for example, @pr\/25@). If a branch name is
    --     specified, the branch\'s HEAD commit ID is used. If not specified,
    --     the default branch\'s HEAD commit ID is used.
    --
    -- -   For Bitbucket: the commit ID, branch name, or tag name that
    --     corresponds to the version of the source code you want to build. If
    --     a branch name is specified, the branch\'s HEAD commit ID is used. If
    --     not specified, the default branch\'s HEAD commit ID is used.
    --
    -- -   For Amazon S3: the version ID of the object that represents the
    --     build input ZIP file to use.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/codebuild/latest/userguide/sample-source-version.html Source Version Sample with CodeBuild>
    -- in the /CodeBuild User Guide/.
    ProjectSourceVersion -> Text
sourceVersion :: Prelude.Text
  }
  deriving (ProjectSourceVersion -> ProjectSourceVersion -> Bool
(ProjectSourceVersion -> ProjectSourceVersion -> Bool)
-> (ProjectSourceVersion -> ProjectSourceVersion -> Bool)
-> Eq ProjectSourceVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProjectSourceVersion -> ProjectSourceVersion -> Bool
$c/= :: ProjectSourceVersion -> ProjectSourceVersion -> Bool
== :: ProjectSourceVersion -> ProjectSourceVersion -> Bool
$c== :: ProjectSourceVersion -> ProjectSourceVersion -> Bool
Prelude.Eq, ReadPrec [ProjectSourceVersion]
ReadPrec ProjectSourceVersion
Int -> ReadS ProjectSourceVersion
ReadS [ProjectSourceVersion]
(Int -> ReadS ProjectSourceVersion)
-> ReadS [ProjectSourceVersion]
-> ReadPrec ProjectSourceVersion
-> ReadPrec [ProjectSourceVersion]
-> Read ProjectSourceVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProjectSourceVersion]
$creadListPrec :: ReadPrec [ProjectSourceVersion]
readPrec :: ReadPrec ProjectSourceVersion
$creadPrec :: ReadPrec ProjectSourceVersion
readList :: ReadS [ProjectSourceVersion]
$creadList :: ReadS [ProjectSourceVersion]
readsPrec :: Int -> ReadS ProjectSourceVersion
$creadsPrec :: Int -> ReadS ProjectSourceVersion
Prelude.Read, Int -> ProjectSourceVersion -> ShowS
[ProjectSourceVersion] -> ShowS
ProjectSourceVersion -> String
(Int -> ProjectSourceVersion -> ShowS)
-> (ProjectSourceVersion -> String)
-> ([ProjectSourceVersion] -> ShowS)
-> Show ProjectSourceVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProjectSourceVersion] -> ShowS
$cshowList :: [ProjectSourceVersion] -> ShowS
show :: ProjectSourceVersion -> String
$cshow :: ProjectSourceVersion -> String
showsPrec :: Int -> ProjectSourceVersion -> ShowS
$cshowsPrec :: Int -> ProjectSourceVersion -> ShowS
Prelude.Show, (forall x. ProjectSourceVersion -> Rep ProjectSourceVersion x)
-> (forall x. Rep ProjectSourceVersion x -> ProjectSourceVersion)
-> Generic ProjectSourceVersion
forall x. Rep ProjectSourceVersion x -> ProjectSourceVersion
forall x. ProjectSourceVersion -> Rep ProjectSourceVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProjectSourceVersion x -> ProjectSourceVersion
$cfrom :: forall x. ProjectSourceVersion -> Rep ProjectSourceVersion x
Prelude.Generic)

-- |
-- Create a value of 'ProjectSourceVersion' 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:
--
-- 'sourceIdentifier', 'projectSourceVersion_sourceIdentifier' - An identifier for a source in the build project. The identifier can only
-- contain alphanumeric characters and underscores, and must be less than
-- 128 characters in length.
--
-- 'sourceVersion', 'projectSourceVersion_sourceVersion' - The source version for the corresponding source identifier. If
-- specified, must be one of:
--
-- -   For CodeCommit: the commit ID, branch, or Git tag to use.
--
-- -   For GitHub: the commit ID, pull request ID, branch name, or tag name
--     that corresponds to the version of the source code you want to
--     build. If a pull request ID is specified, it must use the format
--     @pr\/pull-request-ID@ (for example, @pr\/25@). If a branch name is
--     specified, the branch\'s HEAD commit ID is used. If not specified,
--     the default branch\'s HEAD commit ID is used.
--
-- -   For Bitbucket: the commit ID, branch name, or tag name that
--     corresponds to the version of the source code you want to build. If
--     a branch name is specified, the branch\'s HEAD commit ID is used. If
--     not specified, the default branch\'s HEAD commit ID is used.
--
-- -   For Amazon S3: the version ID of the object that represents the
--     build input ZIP file to use.
--
-- For more information, see
-- <https://docs.aws.amazon.com/codebuild/latest/userguide/sample-source-version.html Source Version Sample with CodeBuild>
-- in the /CodeBuild User Guide/.
newProjectSourceVersion ::
  -- | 'sourceIdentifier'
  Prelude.Text ->
  -- | 'sourceVersion'
  Prelude.Text ->
  ProjectSourceVersion
newProjectSourceVersion :: Text -> Text -> ProjectSourceVersion
newProjectSourceVersion
  Text
pSourceIdentifier_
  Text
pSourceVersion_ =
    ProjectSourceVersion' :: Text -> Text -> ProjectSourceVersion
ProjectSourceVersion'
      { $sel:sourceIdentifier:ProjectSourceVersion' :: Text
sourceIdentifier =
          Text
pSourceIdentifier_,
        $sel:sourceVersion:ProjectSourceVersion' :: Text
sourceVersion = Text
pSourceVersion_
      }

-- | An identifier for a source in the build project. The identifier can only
-- contain alphanumeric characters and underscores, and must be less than
-- 128 characters in length.
projectSourceVersion_sourceIdentifier :: Lens.Lens' ProjectSourceVersion Prelude.Text
projectSourceVersion_sourceIdentifier :: (Text -> f Text) -> ProjectSourceVersion -> f ProjectSourceVersion
projectSourceVersion_sourceIdentifier = (ProjectSourceVersion -> Text)
-> (ProjectSourceVersion -> Text -> ProjectSourceVersion)
-> Lens ProjectSourceVersion ProjectSourceVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectSourceVersion' {Text
sourceIdentifier :: Text
$sel:sourceIdentifier:ProjectSourceVersion' :: ProjectSourceVersion -> Text
sourceIdentifier} -> Text
sourceIdentifier) (\s :: ProjectSourceVersion
s@ProjectSourceVersion' {} Text
a -> ProjectSourceVersion
s {$sel:sourceIdentifier:ProjectSourceVersion' :: Text
sourceIdentifier = Text
a} :: ProjectSourceVersion)

-- | The source version for the corresponding source identifier. If
-- specified, must be one of:
--
-- -   For CodeCommit: the commit ID, branch, or Git tag to use.
--
-- -   For GitHub: the commit ID, pull request ID, branch name, or tag name
--     that corresponds to the version of the source code you want to
--     build. If a pull request ID is specified, it must use the format
--     @pr\/pull-request-ID@ (for example, @pr\/25@). If a branch name is
--     specified, the branch\'s HEAD commit ID is used. If not specified,
--     the default branch\'s HEAD commit ID is used.
--
-- -   For Bitbucket: the commit ID, branch name, or tag name that
--     corresponds to the version of the source code you want to build. If
--     a branch name is specified, the branch\'s HEAD commit ID is used. If
--     not specified, the default branch\'s HEAD commit ID is used.
--
-- -   For Amazon S3: the version ID of the object that represents the
--     build input ZIP file to use.
--
-- For more information, see
-- <https://docs.aws.amazon.com/codebuild/latest/userguide/sample-source-version.html Source Version Sample with CodeBuild>
-- in the /CodeBuild User Guide/.
projectSourceVersion_sourceVersion :: Lens.Lens' ProjectSourceVersion Prelude.Text
projectSourceVersion_sourceVersion :: (Text -> f Text) -> ProjectSourceVersion -> f ProjectSourceVersion
projectSourceVersion_sourceVersion = (ProjectSourceVersion -> Text)
-> (ProjectSourceVersion -> Text -> ProjectSourceVersion)
-> Lens ProjectSourceVersion ProjectSourceVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectSourceVersion' {Text
sourceVersion :: Text
$sel:sourceVersion:ProjectSourceVersion' :: ProjectSourceVersion -> Text
sourceVersion} -> Text
sourceVersion) (\s :: ProjectSourceVersion
s@ProjectSourceVersion' {} Text
a -> ProjectSourceVersion
s {$sel:sourceVersion:ProjectSourceVersion' :: Text
sourceVersion = Text
a} :: ProjectSourceVersion)

instance Core.FromJSON ProjectSourceVersion where
  parseJSON :: Value -> Parser ProjectSourceVersion
parseJSON =
    String
-> (Object -> Parser ProjectSourceVersion)
-> Value
-> Parser ProjectSourceVersion
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProjectSourceVersion"
      ( \Object
x ->
          Text -> Text -> ProjectSourceVersion
ProjectSourceVersion'
            (Text -> Text -> ProjectSourceVersion)
-> Parser Text -> Parser (Text -> ProjectSourceVersion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"sourceIdentifier")
            Parser (Text -> ProjectSourceVersion)
-> Parser Text -> Parser ProjectSourceVersion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"sourceVersion")
      )

instance Prelude.Hashable ProjectSourceVersion

instance Prelude.NFData ProjectSourceVersion

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