Skip to content

Commit d1d1f9a

Browse files
6543Yohann Delafollye
authored andcommitted
make branch parameter optional for /api/v1/repos/{owner}/{repo}/contents/{filepath} (go-gitea#11067)
1 parent ad56744 commit d1d1f9a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

routers/api/v1/repo/file.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
199199
// "201":
200200
// "$ref": "#/responses/FileResponse"
201201

202+
if apiOpts.BranchName == "" {
203+
apiOpts.BranchName = ctx.Repo.Repository.DefaultBranch
204+
}
205+
202206
opts := &repofiles.UpdateRepoFileOptions{
203207
Content: apiOpts.Content,
204208
IsNewFile: true,
@@ -271,6 +275,10 @@ func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
271275
// "200":
272276
// "$ref": "#/responses/FileResponse"
273277

278+
if apiOpts.BranchName == "" {
279+
apiOpts.BranchName = ctx.Repo.Repository.DefaultBranch
280+
}
281+
274282
opts := &repofiles.UpdateRepoFileOptions{
275283
Content: apiOpts.Content,
276284
SHA: apiOpts.SHA,
@@ -377,6 +385,10 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
377385
return
378386
}
379387

388+
if apiOpts.BranchName == "" {
389+
apiOpts.BranchName = ctx.Repo.Repository.DefaultBranch
390+
}
391+
380392
opts := &repofiles.DeleteRepoFileOptions{
381393
Message: apiOpts.Message,
382394
OldBranch: apiOpts.BranchName,

0 commit comments

Comments
 (0)