From 8a806e9064fb008db9a4e5d74c7e328aacea7ae1 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 28 Nov 2023 16:22:18 -0600 Subject: [PATCH] feat: create branch protection --- src/Gitea.Repo.BranchProtections.purs | 10 ++++++++-- src/Gitea.Types.purs | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Gitea.Repo.BranchProtections.purs b/src/Gitea.Repo.BranchProtections.purs index 7c2ac34..e309aa9 100644 --- a/src/Gitea.Repo.BranchProtections.purs +++ b/src/Gitea.Repo.BranchProtections.purs @@ -8,9 +8,9 @@ import Data.URL (URL, (/)) import Effect.Aff.Class (class MonadAff) import Gitea.Auth as Auth import Gitea.Error as Error -import Gitea.Trans (GiteaT) -import Gitea.Types (BranchProtection, BranchProtectionName(..), BranchProtectionUpdate, RepoName(..), Username(..)) import Gitea.HTTP (fetch) as HTTP +import Gitea.Trans (GiteaT) +import Gitea.Types (BranchProtection, BranchProtectionName(..), BranchProtectionUpdate, RepoName(..), Username(..), BranchProtectionCreate) import HTTP (Method(..)) as HTTP import HTTP.Request (json) as HTTP import Simple.JSON (class WriteForeign) @@ -54,3 +54,9 @@ delete u r b = do url <- branchProtectionOneURL u r b rep <- HTTP.fetch $ HTTP.DELETE /\ url Error.guardStatusOk rep + +create :: forall m. MonadAff m => Username -> RepoName -> Record BranchProtectionCreate -> GiteaT m (Record BranchProtection) +create u r new = do + url <- branchProtectionURL u r + rep <- HTTP.fetch $ HTTP.POST /\ url /\ HTTP.json new + Error.tryGetRepJSON rep diff --git a/src/Gitea.Types.purs b/src/Gitea.Types.purs index 975e897..d62325f 100644 --- a/src/Gitea.Types.purs +++ b/src/Gitea.Types.purs @@ -433,5 +433,6 @@ type BranchProtectionImmutable r = | r ) +type BranchProtectionCreate = (BranchProtectionMutable + BranchProtectionMutableOnCreate ()) type BranchProtectionUpdate = BranchProtectionMutable () type BranchProtection = (BranchProtectionMutable + BranchProtectionImmutable + BranchProtectionMutableOnCreate ())