mirror of
https://github.com/Smaug123/gitea-repo-config
synced 2025-10-10 09:48:42 +00:00
Add protected branch support (#50)
This commit is contained in:
@@ -38,12 +38,14 @@ type ProtectedBranch =
|
|||||||
{
|
{
|
||||||
BranchName : string
|
BranchName : string
|
||||||
BlockOnOutdatedBranch : bool option
|
BlockOnOutdatedBranch : bool option
|
||||||
|
RequiredStatusChecks : string list option
|
||||||
}
|
}
|
||||||
|
|
||||||
static member OfSerialised (s : SerialisedProtectedBranch) : ProtectedBranch =
|
static member OfSerialised (s : SerialisedProtectedBranch) : ProtectedBranch =
|
||||||
{
|
{
|
||||||
BranchName = s.BranchName
|
BranchName = s.BranchName
|
||||||
BlockOnOutdatedBranch = Option.ofNullable s.BlockOnOutdatedBranch
|
BlockOnOutdatedBranch = Option.ofNullable s.BlockOnOutdatedBranch
|
||||||
|
RequiredStatusChecks = Option.ofObj s.RequiredStatusChecks |> Option.map List.ofArray
|
||||||
}
|
}
|
||||||
|
|
||||||
type NativeRepo =
|
type NativeRepo =
|
||||||
@@ -185,7 +187,7 @@ type Repo =
|
|||||||
elif mirror.Length = 1 then Some mirror.[0]
|
elif mirror.Length = 1 then Some mirror.[0]
|
||||||
else failwith "Multiple mirrors not supported yet"
|
else failwith "Multiple mirrors not supported yet"
|
||||||
|
|
||||||
let! branchProtections =
|
let! (branchProtections : Gitea.BranchProtection[]) =
|
||||||
client.RepoListBranchProtection (u.Owner.LoginName, u.FullName)
|
client.RepoListBranchProtection (u.Owner.LoginName, u.FullName)
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
@@ -223,6 +225,11 @@ type Repo =
|
|||||||
{
|
{
|
||||||
BranchName = bp.BranchName
|
BranchName = bp.BranchName
|
||||||
BlockOnOutdatedBranch = bp.BlockOnOutdatedBranch
|
BlockOnOutdatedBranch = bp.BlockOnOutdatedBranch
|
||||||
|
RequiredStatusChecks =
|
||||||
|
if bp.EnableStatusCheck = Some true then
|
||||||
|
bp.StatusCheckContexts |> List.ofArray |> Some
|
||||||
|
else
|
||||||
|
None
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|> Set.ofSeq
|
|> Set.ofSeq
|
||||||
|
@@ -484,6 +484,8 @@ module Gitea =
|
|||||||
|
|
||||||
do!
|
do!
|
||||||
// TODO: lift this out to a function and then put it into the new-repo flow too
|
// 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 =
|
let extraActualProtected =
|
||||||
Set.difference actual.ProtectedBranches desired.ProtectedBranches
|
Set.difference actual.ProtectedBranches desired.ProtectedBranches
|
||||||
|
|
||||||
@@ -548,6 +550,12 @@ module Gitea =
|
|||||||
let s = Gitea.EditBranchProtectionOption ()
|
let s = Gitea.EditBranchProtectionOption ()
|
||||||
s.BlockOnOutdatedBranch <- y.BlockOnOutdatedBranch
|
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! _ =
|
let! _ =
|
||||||
client.RepoEditBranchProtection (user, r, y.BranchName, s)
|
client.RepoEditBranchProtection (user, r, y.BranchName, s)
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
@@ -227,6 +227,16 @@
|
|||||||
},
|
},
|
||||||
"blockOnOutdatedBranch": {
|
"blockOnOutdatedBranch": {
|
||||||
"type": "boolean"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,9 @@ type SerialisedProtectedBranch =
|
|||||||
BranchName : string
|
BranchName : string
|
||||||
[<JsonProperty(Required = Required.DisallowNull)>]
|
[<JsonProperty(Required = Required.DisallowNull)>]
|
||||||
BlockOnOutdatedBranch : Nullable<bool>
|
BlockOnOutdatedBranch : Nullable<bool>
|
||||||
|
[<JsonProperty(Required = Required.Default)>]
|
||||||
|
[<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.)">]
|
||||||
|
RequiredStatusChecks : string array
|
||||||
}
|
}
|
||||||
|
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
|
Reference in New Issue
Block a user