aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorInfinoid <mark@glines.org>2023-08-24 01:36:04 -0400
committerGitHub <noreply@github.com>2023-08-24 05:36:04 +0000
commit86ee5b4b1b6acdba89912a3c89c39f9948e67f07 (patch)
treed8426cb40bbb133f7505b511ae9ac07bae5deb5e /routers
parentd2e4039def61d9cc9952be462216001125327270 (diff)
downloadgitea-86ee5b4b1b6acdba89912a3c89c39f9948e67f07.tar.gz
gitea-86ee5b4b1b6acdba89912a3c89c39f9948e67f07.zip
PATCH branch-protection updates check list even when checks are disabled (#26351)
Fixes: #26333. Previously, this endpoint only updates the `StatusCheckContexts` field when `EnableStatusCheck==true`, which makes it impossible to clear the array otherwise. This patch uses slice `nil`-ness to decide whether to update the list of checks. The field is ignored when either the client explicitly passes in a null, or just omits the field from the json ([which causes `json.Unmarshal` to leave the struct field unchanged](https://go.dev/play/p/Z2XHOILuB1Q)). I think this is a better measure of intent than whether the `EnableStatusCheck` flag was set, because it matches the semantics of other field types. Also adds a test case. I noticed that [`testAPIEditBranchProtection` only checks the branch name](https://github.com/go-gitea/gitea/blob/c1c83dbaec840871c1247f4bc3f875309b0de6bb/tests/integration/api_branch_test.go#L68) and no other fields, so I added some extra `GET` calls and specific checks to make sure the fields are changing properly. I added those checks the existing integration test; is that the right place for it?
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/branch.go3
1 files changed, 2 insertions, 1 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 577776dadd..cdc176b8e4 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -768,7 +768,8 @@ func EditBranchProtection(ctx *context.APIContext) {
if form.EnableStatusCheck != nil {
protectBranch.EnableStatusCheck = *form.EnableStatusCheck
}
- if protectBranch.EnableStatusCheck {
+
+ if form.StatusCheckContexts != nil {
protectBranch.StatusCheckContexts = form.StatusCheckContexts
}