{-# 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.CodeDeploy.Types.GitHubLocation
-- 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.CodeDeploy.Types.GitHubLocation where

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

-- | Information about the location of application artifacts stored in
-- GitHub.
--
-- /See:/ 'newGitHubLocation' smart constructor.
data GitHubLocation = GitHubLocation'
  { -- | The SHA1 commit ID of the GitHub commit that represents the bundled
    -- artifacts for the application revision.
    GitHubLocation -> Maybe Text
commitId :: Prelude.Maybe Prelude.Text,
    -- | The GitHub account and repository pair that stores a reference to the
    -- commit that represents the bundled artifacts for the application
    -- revision.
    --
    -- Specified as account\/repository.
    GitHubLocation -> Maybe Text
repository :: Prelude.Maybe Prelude.Text
  }
  deriving (GitHubLocation -> GitHubLocation -> Bool
(GitHubLocation -> GitHubLocation -> Bool)
-> (GitHubLocation -> GitHubLocation -> Bool) -> Eq GitHubLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GitHubLocation -> GitHubLocation -> Bool
$c/= :: GitHubLocation -> GitHubLocation -> Bool
== :: GitHubLocation -> GitHubLocation -> Bool
$c== :: GitHubLocation -> GitHubLocation -> Bool
Prelude.Eq, ReadPrec [GitHubLocation]
ReadPrec GitHubLocation
Int -> ReadS GitHubLocation
ReadS [GitHubLocation]
(Int -> ReadS GitHubLocation)
-> ReadS [GitHubLocation]
-> ReadPrec GitHubLocation
-> ReadPrec [GitHubLocation]
-> Read GitHubLocation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GitHubLocation]
$creadListPrec :: ReadPrec [GitHubLocation]
readPrec :: ReadPrec GitHubLocation
$creadPrec :: ReadPrec GitHubLocation
readList :: ReadS [GitHubLocation]
$creadList :: ReadS [GitHubLocation]
readsPrec :: Int -> ReadS GitHubLocation
$creadsPrec :: Int -> ReadS GitHubLocation
Prelude.Read, Int -> GitHubLocation -> ShowS
[GitHubLocation] -> ShowS
GitHubLocation -> String
(Int -> GitHubLocation -> ShowS)
-> (GitHubLocation -> String)
-> ([GitHubLocation] -> ShowS)
-> Show GitHubLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GitHubLocation] -> ShowS
$cshowList :: [GitHubLocation] -> ShowS
show :: GitHubLocation -> String
$cshow :: GitHubLocation -> String
showsPrec :: Int -> GitHubLocation -> ShowS
$cshowsPrec :: Int -> GitHubLocation -> ShowS
Prelude.Show, (forall x. GitHubLocation -> Rep GitHubLocation x)
-> (forall x. Rep GitHubLocation x -> GitHubLocation)
-> Generic GitHubLocation
forall x. Rep GitHubLocation x -> GitHubLocation
forall x. GitHubLocation -> Rep GitHubLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GitHubLocation x -> GitHubLocation
$cfrom :: forall x. GitHubLocation -> Rep GitHubLocation x
Prelude.Generic)

-- |
-- Create a value of 'GitHubLocation' 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:
--
-- 'commitId', 'gitHubLocation_commitId' - The SHA1 commit ID of the GitHub commit that represents the bundled
-- artifacts for the application revision.
--
-- 'repository', 'gitHubLocation_repository' - The GitHub account and repository pair that stores a reference to the
-- commit that represents the bundled artifacts for the application
-- revision.
--
-- Specified as account\/repository.
newGitHubLocation ::
  GitHubLocation
newGitHubLocation :: GitHubLocation
newGitHubLocation =
  GitHubLocation' :: Maybe Text -> Maybe Text -> GitHubLocation
GitHubLocation'
    { $sel:commitId:GitHubLocation' :: Maybe Text
commitId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:repository:GitHubLocation' :: Maybe Text
repository = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The SHA1 commit ID of the GitHub commit that represents the bundled
-- artifacts for the application revision.
gitHubLocation_commitId :: Lens.Lens' GitHubLocation (Prelude.Maybe Prelude.Text)
gitHubLocation_commitId :: (Maybe Text -> f (Maybe Text))
-> GitHubLocation -> f GitHubLocation
gitHubLocation_commitId = (GitHubLocation -> Maybe Text)
-> (GitHubLocation -> Maybe Text -> GitHubLocation)
-> Lens GitHubLocation GitHubLocation (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GitHubLocation' {Maybe Text
commitId :: Maybe Text
$sel:commitId:GitHubLocation' :: GitHubLocation -> Maybe Text
commitId} -> Maybe Text
commitId) (\s :: GitHubLocation
s@GitHubLocation' {} Maybe Text
a -> GitHubLocation
s {$sel:commitId:GitHubLocation' :: Maybe Text
commitId = Maybe Text
a} :: GitHubLocation)

-- | The GitHub account and repository pair that stores a reference to the
-- commit that represents the bundled artifacts for the application
-- revision.
--
-- Specified as account\/repository.
gitHubLocation_repository :: Lens.Lens' GitHubLocation (Prelude.Maybe Prelude.Text)
gitHubLocation_repository :: (Maybe Text -> f (Maybe Text))
-> GitHubLocation -> f GitHubLocation
gitHubLocation_repository = (GitHubLocation -> Maybe Text)
-> (GitHubLocation -> Maybe Text -> GitHubLocation)
-> Lens GitHubLocation GitHubLocation (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GitHubLocation' {Maybe Text
repository :: Maybe Text
$sel:repository:GitHubLocation' :: GitHubLocation -> Maybe Text
repository} -> Maybe Text
repository) (\s :: GitHubLocation
s@GitHubLocation' {} Maybe Text
a -> GitHubLocation
s {$sel:repository:GitHubLocation' :: Maybe Text
repository = Maybe Text
a} :: GitHubLocation)

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

instance Prelude.Hashable GitHubLocation

instance Prelude.NFData GitHubLocation

instance Core.ToJSON GitHubLocation where
  toJSON :: GitHubLocation -> Value
toJSON GitHubLocation' {Maybe Text
repository :: Maybe Text
commitId :: Maybe Text
$sel:repository:GitHubLocation' :: GitHubLocation -> Maybe Text
$sel:commitId:GitHubLocation' :: GitHubLocation -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"commitId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
commitId,
            (Text
"repository" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
repository
          ]
      )