diff options
author | 6543 <6543@obermui.de> | 2020-11-14 17:13:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-14 11:13:55 -0500 |
commit | 7d2700c8be5da8f2073a576dae209ae07ac6ed22 (patch) | |
tree | 072698eb27e6b8a1e1da3aa0313283d89127598a /routers/api/v1/repo/branch.go | |
parent | 3f3447a1ea8ed0d89ed862b7da506c97030d670e (diff) | |
download | gitea-7d2700c8be5da8f2073a576dae209ae07ac6ed22.tar.gz gitea-7d2700c8be5da8f2073a576dae209ae07ac6ed22.zip |
[API] Only Return Json (#13511)
* Let Branch and Raw Endpoint return json error if not found
* Revert "RM RepoRefByTypeForAPI and move needed parts into GetRawFile directly"
This reverts commit d826d08577b23765cb3c257e7a861191d1aa9a04.
* more similar to RepoRefByType
* dedub-code
* API should just speak JSON
* nice name
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers/api/v1/repo/branch.go')
-rw-r--r-- | routers/api/v1/repo/branch.go | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 384225d742..2b20ab048d 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -46,15 +46,12 @@ func GetBranch(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/Branch" + // "404": + // "$ref": "#/responses/notFound" - if ctx.Repo.TreePath != "" { - // if TreePath != "", then URL contained extra slashes - // (i.e. "master/subbranch" instead of "master"), so branch does - // not exist - ctx.NotFound() - return - } - branch, err := repo_module.GetBranch(ctx.Repo.Repository, ctx.Repo.BranchName) + branchName := ctx.Params("*") + + branch, err := repo_module.GetBranch(ctx.Repo.Repository, branchName) if err != nil { if git.IsErrBranchNotExist(err) { ctx.NotFound(err) @@ -70,7 +67,7 @@ func GetBranch(ctx *context.APIContext) { return } - branchProtection, err := ctx.Repo.Repository.GetBranchProtection(ctx.Repo.BranchName) + branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branchName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) return @@ -113,21 +110,17 @@ func DeleteBranch(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "403": // "$ref": "#/responses/error" + // "404": + // "$ref": "#/responses/notFound" - if ctx.Repo.TreePath != "" { - // if TreePath != "", then URL contained extra slashes - // (i.e. "master/subbranch" instead of "master"), so branch does - // not exist - ctx.NotFound() - return - } + branchName := ctx.Params("*") - if ctx.Repo.Repository.DefaultBranch == ctx.Repo.BranchName { + if ctx.Repo.Repository.DefaultBranch == branchName { ctx.Error(http.StatusForbidden, "DefaultBranch", fmt.Errorf("can not delete default branch")) return } - isProtected, err := ctx.Repo.Repository.IsProtectedBranch(ctx.Repo.BranchName, ctx.User) + isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User) if err != nil { ctx.InternalServerError(err) return @@ -137,7 +130,7 @@ func DeleteBranch(ctx *context.APIContext) { return } - branch, err := repo_module.GetBranch(ctx.Repo.Repository, ctx.Repo.BranchName) + branch, err := repo_module.GetBranch(ctx.Repo.Repository, branchName) if err != nil { if git.IsErrBranchNotExist(err) { ctx.NotFound(err) @@ -153,7 +146,7 @@ func DeleteBranch(ctx *context.APIContext) { return } - if err := ctx.Repo.GitRepo.DeleteBranch(ctx.Repo.BranchName, git.DeleteBranchOptions{ + if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{ Force: true, }); err != nil { ctx.Error(http.StatusInternalServerError, "DeleteBranch", err) @@ -163,7 +156,7 @@ func DeleteBranch(ctx *context.APIContext) { // Don't return error below this if err := repo_service.PushUpdate( &repo_module.PushUpdateOptions{ - RefFullName: git.BranchPrefix + ctx.Repo.BranchName, + RefFullName: git.BranchPrefix + branchName, OldCommitID: c.ID.String(), NewCommitID: git.EmptySHA, PusherID: ctx.User.ID, @@ -174,7 +167,7 @@ func DeleteBranch(ctx *context.APIContext) { log.Error("Update: %v", err) } - if err := ctx.Repo.Repository.AddDeletedBranch(ctx.Repo.BranchName, c.ID.String(), ctx.User.ID); err != nil { + if err := ctx.Repo.Repository.AddDeletedBranch(branchName, c.ID.String(), ctx.User.ID); err != nil { log.Warn("AddDeletedBranch: %v", err) } |