{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeBuild.Types.ProjectSourceVersion where

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

-- | 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
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]
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
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. 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'
      { $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 :: Lens' ProjectSourceVersion Text
projectSourceVersion_sourceIdentifier = 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 :: Lens' ProjectSourceVersion Text
projectSourceVersion_sourceVersion = 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 Data.FromJSON ProjectSourceVersion where
  parseJSON :: Value -> Parser ProjectSourceVersion
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ProjectSourceVersion"
      ( \Object
x ->
          Text -> Text -> ProjectSourceVersion
ProjectSourceVersion'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"sourceIdentifier")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"sourceVersion")
      )

instance Prelude.Hashable ProjectSourceVersion where
  hashWithSalt :: Int -> ProjectSourceVersion -> Int
hashWithSalt Int
_salt ProjectSourceVersion' {Text
sourceVersion :: Text
sourceIdentifier :: Text
$sel:sourceVersion:ProjectSourceVersion' :: ProjectSourceVersion -> Text
$sel:sourceIdentifier:ProjectSourceVersion' :: ProjectSourceVersion -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sourceIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sourceVersion

instance Prelude.NFData ProjectSourceVersion where
  rnf :: ProjectSourceVersion -> ()
rnf ProjectSourceVersion' {Text
sourceVersion :: Text
sourceIdentifier :: Text
$sel:sourceVersion:ProjectSourceVersion' :: ProjectSourceVersion -> Text
$sel:sourceIdentifier:ProjectSourceVersion' :: ProjectSourceVersion -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
sourceIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sourceVersion

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"sourceIdentifier" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sourceIdentifier),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"sourceVersion" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sourceVersion)
          ]
      )