diff --git a/Gitea.Declarative.Lib/ConfigSchema.fs b/Gitea.Declarative.Lib/ConfigSchema.fs index e30fa68..4013c14 100644 --- a/Gitea.Declarative.Lib/ConfigSchema.fs +++ b/Gitea.Declarative.Lib/ConfigSchema.fs @@ -38,12 +38,14 @@ type ProtectedBranch = { BranchName : string BlockOnOutdatedBranch : bool option + RequiredStatusChecks : string list option } static member OfSerialised (s : SerialisedProtectedBranch) : ProtectedBranch = { BranchName = s.BranchName BlockOnOutdatedBranch = Option.ofNullable s.BlockOnOutdatedBranch + RequiredStatusChecks = Option.ofObj s.RequiredStatusChecks |> Option.map List.ofArray } type NativeRepo = @@ -185,7 +187,7 @@ type Repo = elif mirror.Length = 1 then Some mirror.[0] else failwith "Multiple mirrors not supported yet" - let! branchProtections = + let! (branchProtections : Gitea.BranchProtection[]) = client.RepoListBranchProtection (u.Owner.LoginName, u.FullName) |> Async.AwaitTask @@ -223,6 +225,11 @@ type Repo = { BranchName = bp.BranchName BlockOnOutdatedBranch = bp.BlockOnOutdatedBranch + RequiredStatusChecks = + if bp.EnableStatusCheck = Some true then + bp.StatusCheckContexts |> List.ofArray |> Some + else + None } ) |> Set.ofSeq diff --git a/Gitea.Declarative.Lib/Gitea.fs b/Gitea.Declarative.Lib/Gitea.fs index 746b68e..86cb52a 100644 --- a/Gitea.Declarative.Lib/Gitea.fs +++ b/Gitea.Declarative.Lib/Gitea.fs @@ -484,6 +484,8 @@ module Gitea = do! // TODO: lift this out to a function and then put it into the new-repo flow too + // The current behaviour is kind of desirable, because it gives you a chance to push to + // the protected branch before it becomes protected. let extraActualProtected = Set.difference actual.ProtectedBranches desired.ProtectedBranches @@ -548,6 +550,12 @@ module Gitea = let s = Gitea.EditBranchProtectionOption () s.BlockOnOutdatedBranch <- y.BlockOnOutdatedBranch + match y.RequiredStatusChecks with + | None -> s.EnableStatusCheck <- Some false + | Some checks -> + s.EnableStatusCheck <- Some true + s.StatusCheckContexts <- Array.ofList checks + let! _ = client.RepoEditBranchProtection (user, r, y.BranchName, s) |> Async.AwaitTask diff --git a/Gitea.Declarative.Lib/GiteaConfig.schema.json b/Gitea.Declarative.Lib/GiteaConfig.schema.json index 425f633..6edf033 100644 --- a/Gitea.Declarative.Lib/GiteaConfig.schema.json +++ b/Gitea.Declarative.Lib/GiteaConfig.schema.json @@ -227,6 +227,16 @@ }, "blockOnOutdatedBranch": { "type": "boolean" + }, + "requiredStatusChecks": { + "type": [ + "array", + "null" + ], + "description": "A list of status check patterns; merge into this branch will be blocked unless all these checks have run and passed. (Probably go with alphanumeric strings, I can't find any docs.)", + "items": { + "type": "string" + } } } } diff --git a/Gitea.Declarative.Lib/SerialisedConfigSchema.fs b/Gitea.Declarative.Lib/SerialisedConfigSchema.fs index 233e0c6..c7498bb 100644 --- a/Gitea.Declarative.Lib/SerialisedConfigSchema.fs +++ b/Gitea.Declarative.Lib/SerialisedConfigSchema.fs @@ -27,6 +27,9 @@ type SerialisedProtectedBranch = BranchName : string [] BlockOnOutdatedBranch : Nullable + [] + [] + RequiredStatusChecks : string array } []