From 6b42b3031961920bdb719227893566dbd81f9ce5 Mon Sep 17 00:00:00 2001 From: Robbie McMichael <2044464+robbiemcmichael@users.noreply.github.com> Date: Sun, 15 Dec 2019 22:13:36 +1100 Subject: [PATCH 1/3] Manage orgs in GitHub Enterprise --- github.cabal | 2 + src/GitHub.hs | 9 +++ src/GitHub/Data.hs | 2 + src/GitHub/Data/Enterprise/Organizations.hs | 64 +++++++++++++++++++ .../Endpoints/Enterprise/Organizations.hs | 27 ++++++++ 5 files changed, 104 insertions(+) create mode 100644 src/GitHub/Data/Enterprise/Organizations.hs create mode 100644 src/GitHub/Endpoints/Enterprise/Organizations.hs diff --git a/github.cabal b/github.cabal index b3a18432..669bbb77 100644 --- a/github.cabal +++ b/github.cabal @@ -90,6 +90,7 @@ library GitHub.Data.DeployKeys GitHub.Data.Deployments GitHub.Data.Email + GitHub.Data.Enterprise.Organizations GitHub.Data.Events GitHub.Data.Gists GitHub.Data.GitData @@ -116,6 +117,7 @@ library GitHub.Endpoints.Activity.Notifications GitHub.Endpoints.Activity.Starring GitHub.Endpoints.Activity.Watching + GitHub.Endpoints.Enterprise.Organizations GitHub.Endpoints.Gists GitHub.Endpoints.Gists.Comments GitHub.Endpoints.GitData.Blobs diff --git a/src/GitHub.hs b/src/GitHub.hs index 2faf1618..d5845972 100644 --- a/src/GitHub.hs +++ b/src/GitHub.hs @@ -56,6 +56,14 @@ module GitHub ( watchersForR, reposWatchedByR, + -- * Enterprise + -- | See + + -- ** Organizations + -- | See + createOrganizationR, + renameOrganizationR, + -- * Gists -- | See -- @@ -401,6 +409,7 @@ import GitHub.Endpoints.Activity.Events import GitHub.Endpoints.Activity.Notifications import GitHub.Endpoints.Activity.Starring import GitHub.Endpoints.Activity.Watching +import GitHub.Endpoints.Enterprise.Organizations import GitHub.Endpoints.Gists import GitHub.Endpoints.Gists.Comments import GitHub.Endpoints.GitData.Blobs diff --git a/src/GitHub/Data.hs b/src/GitHub/Data.hs index 6acc0bf2..bdedb894 100644 --- a/src/GitHub/Data.hs +++ b/src/GitHub/Data.hs @@ -41,6 +41,7 @@ module GitHub.Data ( module GitHub.Data.DeployKeys, module GitHub.Data.Deployments, module GitHub.Data.Email, + module GitHub.Data.Enterprise.Organizations, module GitHub.Data.Events, module GitHub.Data.Gists, module GitHub.Data.GitData, @@ -73,6 +74,7 @@ import GitHub.Data.Definitions import GitHub.Data.DeployKeys import GitHub.Data.Deployments import GitHub.Data.Email +import GitHub.Data.Enterprise.Organizations import GitHub.Data.Events import GitHub.Data.Gists import GitHub.Data.GitData diff --git a/src/GitHub/Data/Enterprise/Organizations.hs b/src/GitHub/Data/Enterprise/Organizations.hs new file mode 100644 index 00000000..967cd718 --- /dev/null +++ b/src/GitHub/Data/Enterprise/Organizations.hs @@ -0,0 +1,64 @@ +----------------------------------------------------------------------------- +-- | +-- License : BSD-3-Clause +-- Maintainer : Oleg Grenrus +-- +module GitHub.Data.Enterprise.Organizations where + +import GitHub.Data.Definitions +import GitHub.Data.Name (Name) +import GitHub.Data.URL (URL) +import GitHub.Internal.Prelude +import Prelude () + +data CreateOrganization = CreateOrganization + { createOrganizationLogin :: !(Name Organization) + , createOrganizationAdmin :: !(Name User) + , createOrganizationProfileName :: !(Maybe Text) + } + deriving (Show, Data, Typeable, Eq, Ord, Generic) + +instance NFData CreateOrganization where rnf = genericRnf +instance Binary CreateOrganization + +data RenameOrganization = RenameOrganization + { renameOrganizationLogin :: !(Name Organization) + } + deriving (Show, Data, Typeable, Eq, Ord, Generic) + +instance NFData RenameOrganization where rnf = genericRnf +instance Binary RenameOrganization + +data RenameOrganizationResponse = RenameOrganizationResponse + { renameOrganizationResponseMessage :: !Text + , renameOrganizationResponseUrl :: !URL + } + deriving (Show, Data, Typeable, Eq, Ord, Generic) + +instance NFData RenameOrganizationResponse where rnf = genericRnf +instance Binary RenameOrganizationResponse + +-- JSON Instances + +instance ToJSON CreateOrganization where + toJSON (CreateOrganization login admin profileName) = + object $ filter notNull + [ "login" .= login + , "admin" .= admin + , "profile_name" .= profileName + ] + where + notNull (_, Null) = False + notNull (_, _) = True + +instance ToJSON RenameOrganization where + toJSON (RenameOrganization login) = + object + [ "login" .= login + ] + +instance FromJSON RenameOrganizationResponse where + parseJSON = withObject "RenameOrganizationResponse" $ \o -> + RenameOrganizationResponse + <$> o .: "message" + <*> o .: "url" diff --git a/src/GitHub/Endpoints/Enterprise/Organizations.hs b/src/GitHub/Endpoints/Enterprise/Organizations.hs new file mode 100644 index 00000000..d94c7c72 --- /dev/null +++ b/src/GitHub/Endpoints/Enterprise/Organizations.hs @@ -0,0 +1,27 @@ +----------------------------------------------------------------------------- +-- | +-- License : BSD-3-Clause +-- Maintainer : Oleg Grenrus +-- +-- The GitHub Enterprise orgs API as described on . +module GitHub.Endpoints.Enterprise.Organizations ( + createOrganizationR, + renameOrganizationR, + module GitHub.Data, + ) where + +import GitHub.Data +import GitHub.Internal.Prelude +import Prelude () + +-- | Create an organization. +-- See +createOrganizationR :: CreateOrganization -> Request 'RW SimpleOrganization +createOrganizationR = + command Post ["admin", "organizations"] . encode + +-- | Rename an organization. +-- See +renameOrganizationR :: Name Organization -> RenameOrganization -> Request 'RW RenameOrganizationResponse +renameOrganizationR org = + command Patch ["admin", "organizations", toPathPart org] . encode From b277deb25f76b88cd28d2c97b715041e05346d7f Mon Sep 17 00:00:00 2001 From: Robbie McMichael <2044464+robbiemcmichael@users.noreply.github.com> Date: Mon, 16 Dec 2019 19:24:18 +1100 Subject: [PATCH 2/3] Add samples for GitHub Enterprise org management --- samples/Enterprise/CreateOrganization.hs | 29 ++++++++++++++++++++++++ samples/Enterprise/RenameOrganization.hs | 28 +++++++++++++++++++++++ samples/github-samples.cabal | 10 ++++++++ 3 files changed, 67 insertions(+) create mode 100644 samples/Enterprise/CreateOrganization.hs create mode 100644 samples/Enterprise/RenameOrganization.hs diff --git a/samples/Enterprise/CreateOrganization.hs b/samples/Enterprise/CreateOrganization.hs new file mode 100644 index 00000000..897e7cd5 --- /dev/null +++ b/samples/Enterprise/CreateOrganization.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +module Main (main) where + +import Common + +import qualified GitHub + +main :: IO () +main = do + args <- getArgs + result <- case args of + [api_endpoint, token, org_login, org_admin, org_profile_name] -> + GitHub.github + (GitHub.EnterpriseOAuth + (fromString api_endpoint) + (fromString token) + ) + GitHub.createOrganizationR + (GitHub.CreateOrganization + (GitHub.mkOrganizationName $ fromString org_login) + (GitHub.mkUserName $ fromString org_admin) + (Just $ fromString org_profile_name) + ) + _ -> + error "usage: CreateOrganization " + case result of + Left err -> putStrLn $ "Error: " <> tshow err + Right org -> putStrLn $ tshow org diff --git a/samples/Enterprise/RenameOrganization.hs b/samples/Enterprise/RenameOrganization.hs new file mode 100644 index 00000000..bee86142 --- /dev/null +++ b/samples/Enterprise/RenameOrganization.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +module Main (main) where + +import Common + +import qualified GitHub + +main :: IO () +main = do + args <- getArgs + result <- case args of + [api_endpoint, token, current_name, new_name] -> + GitHub.github + (GitHub.EnterpriseOAuth + (fromString api_endpoint) + (fromString token) + ) + GitHub.renameOrganizationR + (GitHub.mkOrganizationName $ fromString current_name) + (GitHub.RenameOrganization + (GitHub.mkOrganizationName $ fromString new_name) + ) + _ -> + error "usage: RenameOrganization " + case result of + Left err -> putStrLn $ "Error: " <> tshow err + Right x -> putStrLn $ tshow x diff --git a/samples/github-samples.cabal b/samples/github-samples.cabal index 2b4d2f69..b6a75728 100644 --- a/samples/github-samples.cabal +++ b/samples/github-samples.cabal @@ -98,6 +98,16 @@ executable github-create-deploy-key -- main-is: DeleteTeamMembershipFor.hs -- hs-source-dirs: Teams/Memberships +executable github-enterprise-create-organization + import: deps + main-is: CreateOrganization.hs + hs-source-dirs: Enterprise + +executable github-enterprise-rename-organization + import: deps + main-is: RenameOrganization.hs + hs-source-dirs: Enterprise + executable github-edit-team import: deps main-is: EditTeam.hs From 3fb5f0ce6c0359f37909d3315cee6c6ef9b38db8 Mon Sep 17 00:00:00 2001 From: Robbie McMichael <2044464+robbiemcmichael@users.noreply.github.com> Date: Mon, 16 Dec 2019 20:42:26 +1100 Subject: [PATCH 3/3] Add GitHub.Enterprise module --- github.cabal | 2 ++ samples/Enterprise/CreateOrganization.hs | 1 + samples/Enterprise/RenameOrganization.hs | 1 + src/GitHub.hs | 2 +- src/GitHub/Data.hs | 2 -- src/GitHub/Data/Enterprise.hs | 12 ++++++++++ .../Endpoints/Enterprise/Organizations.hs | 1 + src/GitHub/Enterprise.hs | 23 +++++++++++++++++++ 8 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/GitHub/Data/Enterprise.hs create mode 100644 src/GitHub/Enterprise.hs diff --git a/github.cabal b/github.cabal index 669bbb77..700d80cf 100644 --- a/github.cabal +++ b/github.cabal @@ -90,6 +90,7 @@ library GitHub.Data.DeployKeys GitHub.Data.Deployments GitHub.Data.Email + GitHub.Data.Enterprise GitHub.Data.Enterprise.Organizations GitHub.Data.Events GitHub.Data.Gists @@ -153,6 +154,7 @@ library GitHub.Endpoints.Users.Emails GitHub.Endpoints.Users.Followers GitHub.Endpoints.Users.PublicSSHKeys + GitHub.Enterprise GitHub.Internal.Prelude GitHub.Request diff --git a/samples/Enterprise/CreateOrganization.hs b/samples/Enterprise/CreateOrganization.hs index 897e7cd5..32fc97cc 100644 --- a/samples/Enterprise/CreateOrganization.hs +++ b/samples/Enterprise/CreateOrganization.hs @@ -5,6 +5,7 @@ module Main (main) where import Common import qualified GitHub +import qualified GitHub.Enterprise as GitHub main :: IO () main = do diff --git a/samples/Enterprise/RenameOrganization.hs b/samples/Enterprise/RenameOrganization.hs index bee86142..c16fdf56 100644 --- a/samples/Enterprise/RenameOrganization.hs +++ b/samples/Enterprise/RenameOrganization.hs @@ -5,6 +5,7 @@ module Main (main) where import Common import qualified GitHub +import qualified GitHub.Enterprise as GitHub main :: IO () main = do diff --git a/src/GitHub.hs b/src/GitHub.hs index d5845972..850258d1 100644 --- a/src/GitHub.hs +++ b/src/GitHub.hs @@ -3,7 +3,7 @@ -- License : BSD-3-Clause -- Maintainer : Oleg Grenrus -- --- This module re-exports all request constructrors and data definitions from +-- This module re-exports all request constructors and data definitions from -- this package. -- -- See "GitHub.Request" module for executing 'Request', in short diff --git a/src/GitHub/Data.hs b/src/GitHub/Data.hs index bdedb894..6acc0bf2 100644 --- a/src/GitHub/Data.hs +++ b/src/GitHub/Data.hs @@ -41,7 +41,6 @@ module GitHub.Data ( module GitHub.Data.DeployKeys, module GitHub.Data.Deployments, module GitHub.Data.Email, - module GitHub.Data.Enterprise.Organizations, module GitHub.Data.Events, module GitHub.Data.Gists, module GitHub.Data.GitData, @@ -74,7 +73,6 @@ import GitHub.Data.Definitions import GitHub.Data.DeployKeys import GitHub.Data.Deployments import GitHub.Data.Email -import GitHub.Data.Enterprise.Organizations import GitHub.Data.Events import GitHub.Data.Gists import GitHub.Data.GitData diff --git a/src/GitHub/Data/Enterprise.hs b/src/GitHub/Data/Enterprise.hs new file mode 100644 index 00000000..125a8d69 --- /dev/null +++ b/src/GitHub/Data/Enterprise.hs @@ -0,0 +1,12 @@ +----------------------------------------------------------------------------- +-- | +-- License : BSD-3-Clause +-- Maintainer : Oleg Grenrus +-- +-- This module re-exports the @GitHub.Data.Enterprise.@ submodules. +module GitHub.Data.Enterprise ( + -- * Module re-exports + module GitHub.Data.Enterprise.Organizations, + ) where + +import GitHub.Data.Enterprise.Organizations diff --git a/src/GitHub/Endpoints/Enterprise/Organizations.hs b/src/GitHub/Endpoints/Enterprise/Organizations.hs index d94c7c72..589c3d35 100644 --- a/src/GitHub/Endpoints/Enterprise/Organizations.hs +++ b/src/GitHub/Endpoints/Enterprise/Organizations.hs @@ -11,6 +11,7 @@ module GitHub.Endpoints.Enterprise.Organizations ( ) where import GitHub.Data +import GitHub.Data.Enterprise import GitHub.Internal.Prelude import Prelude () diff --git a/src/GitHub/Enterprise.hs b/src/GitHub/Enterprise.hs new file mode 100644 index 00000000..bb64b7d7 --- /dev/null +++ b/src/GitHub/Enterprise.hs @@ -0,0 +1,23 @@ +----------------------------------------------------------------------------- +-- | +-- License : BSD-3-Clause +-- Maintainer : Oleg Grenrus +-- +-- This module re-exports all request constructors and data definitions for +-- working with GitHub Enterprise. +-- +module GitHub.Enterprise ( + -- * Enterprise Admin + -- | See + + -- ** Organizations + -- | See + createOrganizationR, + renameOrganizationR, + + -- * Data definitions + module GitHub.Data.Enterprise, + ) where + +import GitHub.Data.Enterprise +import GitHub.Endpoints.Enterprise.Organizations