Skip to content

Commit

Permalink
Return a 204 response instead of 200
Browse files Browse the repository at this point in the history
  • Loading branch information
kemzeb committed Dec 11, 2024
1 parent 83e3528 commit d906662
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
30 changes: 3 additions & 27 deletions routers/api/v1/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions tests/integration/api_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}
Expand Down

0 comments on commit d906662

Please sign in to comment.