mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-13 21:31:15 +01:00
f26f4a7e01
* Update swagger documentation Add docs for missing endpoints Add documentation for request parameters Make parameter naming consistent Fix response documentation * Restore delete comments
105 lines
2.5 KiB
Go
105 lines
2.5 KiB
Go
// Copyright 2016 The Gogs Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package repo
|
|
|
|
import (
|
|
api "code.gitea.io/sdk/gitea"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
"code.gitea.io/gitea/routers/api/v1/convert"
|
|
)
|
|
|
|
// GetBranch get a branch of a repository
|
|
func GetBranch(ctx *context.APIContext) {
|
|
// swagger:operation GET /repos/{owner}/{repo}/branches/{branch} repository repoGetBranch
|
|
// ---
|
|
// summary: List a repository's branches
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: owner
|
|
// in: path
|
|
// description: owner of the repo
|
|
// type: string
|
|
// required: true
|
|
// - name: repo
|
|
// in: path
|
|
// description: name of the repo
|
|
// type: string
|
|
// required: true
|
|
// - name: branch
|
|
// in: path
|
|
// description: branch to get
|
|
// type: string
|
|
// required: true
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/Branch"
|
|
if ctx.Repo.TreePath != "" {
|
|
// if TreePath != "", then URL contained extra slashes
|
|
// (i.e. "master/subbranch" instead of "master"), so branch does
|
|
// not exist
|
|
ctx.Status(404)
|
|
return
|
|
}
|
|
branch, err := ctx.Repo.Repository.GetBranch(ctx.Repo.BranchName)
|
|
if err != nil {
|
|
if models.IsErrBranchNotExist(err) {
|
|
ctx.Error(404, "GetBranch", err)
|
|
} else {
|
|
ctx.Error(500, "GetBranch", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
c, err := branch.GetCommit()
|
|
if err != nil {
|
|
ctx.Error(500, "GetCommit", err)
|
|
return
|
|
}
|
|
|
|
ctx.JSON(200, convert.ToBranch(branch, c))
|
|
}
|
|
|
|
// ListBranches list all the branches of a repository
|
|
func ListBranches(ctx *context.APIContext) {
|
|
// swagger:operation GET /repos/{owner}/{repo}/branches repository repoListBranches
|
|
// ---
|
|
// summary: List a repository's branches
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: owner
|
|
// in: path
|
|
// description: owner of the repo
|
|
// type: string
|
|
// required: true
|
|
// - name: repo
|
|
// in: path
|
|
// description: name of the repo
|
|
// type: string
|
|
// required: true
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/BranchList"
|
|
branches, err := ctx.Repo.Repository.GetBranches()
|
|
if err != nil {
|
|
ctx.Error(500, "GetBranches", err)
|
|
return
|
|
}
|
|
|
|
apiBranches := make([]*api.Branch, len(branches))
|
|
for i := range branches {
|
|
c, err := branches[i].GetCommit()
|
|
if err != nil {
|
|
ctx.Error(500, "GetCommit", err)
|
|
return
|
|
}
|
|
apiBranches[i] = convert.ToBranch(branches[i], c)
|
|
}
|
|
|
|
ctx.JSON(200, &apiBranches)
|
|
}
|