Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83e3528

Browse files
committed
Make thename PATCH field required
1 parent6a82204 commit83e3528

File tree

4 files changed

+19
-44
lines changed

4 files changed

+19
-44
lines changed

‎modules/structs/repo.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ type CreateBranchRepoOption struct {
283283
typeUpdateBranchRepoOptionstruct {
284284
// New branch name
285285
//
286+
// required: true
286287
// unique: true
287-
Namestring`json:"name" binding:"GitRefName;MaxSize(100)"`
288+
Namestring`json:"name" binding:"Required;GitRefName;MaxSize(100)"`
288289
}
289290

290291
// TransferRepoOption options when transfer a repository's ownership

‎routers/api/v1/repo/branch.go‎

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -440,33 +440,22 @@ func UpdateBranch(ctx *context.APIContext) {
440440
return
441441
}
442442

443-
branchName:=opt.Name
444-
ifbranchName!="" {
445-
msg,err:=repo_service.RenameBranch(ctx,repo,ctx.Doer,ctx.Repo.GitRepo,oldName,branchName)
446-
iferr!=nil {
447-
ctx.Error(http.StatusInternalServerError,"RenameBranch",err)
448-
return
449-
}
450-
ifmsg=="target_exist" {
451-
ctx.Error(http.StatusUnprocessableEntity,"","Cannot rename a branch using the same name or rename to a branch that already exists.")
452-
return
453-
}
454-
ifmsg=="from_not_exist" {
455-
ctx.Error(http.StatusNotFound,"","Branch doesn't exist.")
456-
return
457-
}
458-
}else {
459-
branchName=oldName
443+
msg,err:=repo_service.RenameBranch(ctx,repo,ctx.Doer,ctx.Repo.GitRepo,oldName,opt.Name)
444+
iferr!=nil {
445+
ctx.Error(http.StatusInternalServerError,"RenameBranch",err)
446+
return
447+
}
448+
ifmsg=="target_exist" {
449+
ctx.Error(http.StatusUnprocessableEntity,"","Cannot rename a branch using the same name or rename to a branch that already exists.")
450+
return
451+
}
452+
ifmsg=="from_not_exist" {
453+
ctx.Error(http.StatusNotFound,"","Branch doesn't exist.")
454+
return
460455
}
461456

462-
branch,err:=ctx.Repo.GitRepo.GetBranch(branchName)
457+
branch,err:=ctx.Repo.GitRepo.GetBranch(opt.Name)
463458
iferr!=nil {
464-
ifgit.IsErrBranchNotExist(err) {
465-
// This could occur if the client passes a non-existent branch and we
466-
// skip executing the branch that contains the RenameBranch() call.
467-
ctx.Error(http.StatusNotFound,"","Branch doesn't exist.")
468-
return
469-
}
470459
ctx.Error(http.StatusInternalServerError,"GetBranch",err)
471460
return
472461
}
@@ -485,7 +474,7 @@ func UpdateBranch(ctx *context.APIContext) {
485474

486475
br,err:=convert.ToBranch(ctx,repo,branch.Name,commit,pb,ctx.Doer,ctx.Repo.IsAdmin())
487476
iferr!=nil {
488-
ctx.Error(http.StatusInternalServerError,"convert.ToBranch",err)
477+
ctx.Error(http.StatusInternalServerError,"ToBranch",err)
489478
return
490479
}
491480

‎templates/swagger/v1_json.tmpl‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎tests/integration/api_branch_test.go‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net/http"
88
"net/http/httptest"
99
"net/url"
10-
"slices"
1110
"testing"
1211

1312
auth_model"code.gitea.io/gitea/models/auth"
@@ -205,23 +204,6 @@ func TestAPIUpdateBranch(t *testing.T) {
205204
resp:=testAPIUpdateBranch(t,"user2","repo1","i-dont-exist","new-branch-name",http.StatusNotFound)
206205
assert.Contains(t,resp.Body.String(),"Branch doesn't exist.")
207206
})
208-
t.Run("UpdateBranchWithEmptyStringAsNewName",func(t*testing.T) {
209-
resp:=testAPIUpdateBranch(t,"user13","repo11","master","",http.StatusOK)
210-
varbranch api.Branch
211-
DecodeJSON(t,resp,&branch)
212-
assert.EqualValues(t,"master",branch.Name)
213-
214-
// Make sure the branch name did not change in the db.
215-
branches,err:=db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
216-
RepoID:11,
217-
})
218-
assert.NoError(t,err)
219-
branchWasUnchanged:=slices.ContainsFunc(branches,func(b*git_model.Branch)bool {returnb.Name=="master" })
220-
assert.True(t,branchWasUnchanged,"master branch shouldn't have been renamed")
221-
})
222-
t.Run("UpdateBranchWithNonExistentBranchAndNewNameIsTheEmptyString",func(t*testing.T) {
223-
testAPIUpdateBranch(t,"user2","repo1","i-dont-exist","",http.StatusNotFound)
224-
})
225207
t.Run("RenameBranchNormalScenario",func(t*testing.T) {
226208
resp:=testAPIUpdateBranch(t,"user2","repo1","branch2","new-branch-name",http.StatusOK)
227209
varbranch api.Branch

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp