From d90666209b30775fa66034d9329b04b11e8dcac2 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Wed, 11 Dec 2024 15:01:18 -0800 Subject: [PATCH] Return a 204 response instead of 200 --- routers/api/v1/repo/branch.go | 30 +++------------------------- templates/swagger/v1_json.tmpl | 4 ++-- tests/integration/api_branch_test.go | 5 +---- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 9699c813dec7e..946203e97ec0a 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -416,8 +416,8 @@ func UpdateBranch(ctx *context.APIContext) { // schema: // "$ref": "#/definitions/UpdateBranchRepoOption" // responses: - // "200": - // "$ref": "#/responses/Branch" + // "204": + // "$ref": "#/responses/empty" // "403": // "$ref": "#/responses/forbidden" // "404": @@ -454,31 +454,7 @@ func UpdateBranch(ctx *context.APIContext) { return } - branch, err := ctx.Repo.GitRepo.GetBranch(opt.Name) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetBranch", err) - return - } - - commit, err := branch.GetCommit() - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetCommit", err) - return - } - - pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, repo.ID, branch.Name) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetFirstMatchProtectedBranchRule", err) - return - } - - br, err := convert.ToBranch(ctx, repo, branch.Name, commit, pb, ctx.Doer, ctx.Repo.IsAdmin()) - if err != nil { - ctx.Error(http.StatusInternalServerError, "ToBranch", err) - return - } - - ctx.JSON(http.StatusOK, br) + ctx.Status(http.StatusNoContent) } // GetBranchProtection gets a branch protection diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index d082cf03a21de..82a301da2fe99 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5089,8 +5089,8 @@ } ], "responses": { - "200": { - "$ref": "#/responses/Branch" + "204": { + "$ref": "#/responses/empty" }, "403": { "$ref": "#/responses/forbidden" diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go index 355e56eb91430..24a041de17e1b 100644 --- a/tests/integration/api_branch_test.go +++ b/tests/integration/api_branch_test.go @@ -205,10 +205,7 @@ func TestAPIUpdateBranch(t *testing.T) { assert.Contains(t, resp.Body.String(), "Branch doesn't exist.") }) t.Run("RenameBranchNormalScenario", func(t *testing.T) { - resp := testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusOK) - var branch api.Branch - DecodeJSON(t, resp, &branch) - assert.EqualValues(t, "new-branch-name", branch.Name) + testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusNoContent) }) }) }