mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 19:08:37 +00:00 
			
		
		
		
	* 1.19 gofumpt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change CSV test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Commit whitespace fixes from @zeripath Co-authored-by: zeripath <art27@cantab.net> * Update emoji Signed-off-by: jolheiser <john.olheiser@gmail.com> * bump swagger & fix generate-swagger Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv>
		
			
				
	
	
		
			109 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2018 The Gitea 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 (
 | |
| 	"net/http"
 | |
| 	"net/url"
 | |
| 
 | |
| 	"code.gitea.io/gitea/modules/context"
 | |
| 	api "code.gitea.io/gitea/modules/structs"
 | |
| 	"code.gitea.io/gitea/modules/util"
 | |
| 	"code.gitea.io/gitea/routers/api/v1/utils"
 | |
| )
 | |
| 
 | |
| // GetGitAllRefs get ref or an list all the refs of a repository
 | |
| func GetGitAllRefs(ctx *context.APIContext) {
 | |
| 	// swagger:operation GET /repos/{owner}/{repo}/git/refs repository repoListAllGitRefs
 | |
| 	// ---
 | |
| 	// summary: Get specified ref or filtered repository's refs
 | |
| 	// 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/Reference" TODO: swagger doesnt support different output formats by ref
 | |
| 	//     "$ref": "#/responses/ReferenceList"
 | |
| 	//   "404":
 | |
| 	//     "$ref": "#/responses/notFound"
 | |
| 
 | |
| 	getGitRefsInternal(ctx, "")
 | |
| }
 | |
| 
 | |
| // GetGitRefs get ref or an filteresd list of refs of a repository
 | |
| func GetGitRefs(ctx *context.APIContext) {
 | |
| 	// swagger:operation GET /repos/{owner}/{repo}/git/refs/{ref} repository repoListGitRefs
 | |
| 	// ---
 | |
| 	// summary: Get specified ref or filtered repository's refs
 | |
| 	// 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: ref
 | |
| 	//   in: path
 | |
| 	//   description: part or full name of the ref
 | |
| 	//   type: string
 | |
| 	//   required: true
 | |
| 	// responses:
 | |
| 	//   "200":
 | |
| 	// #   "$ref": "#/responses/Reference" TODO: swagger doesnt support different output formats by ref
 | |
| 	//     "$ref": "#/responses/ReferenceList"
 | |
| 	//   "404":
 | |
| 	//     "$ref": "#/responses/notFound"
 | |
| 
 | |
| 	getGitRefsInternal(ctx, ctx.Params("*"))
 | |
| }
 | |
| 
 | |
| func getGitRefsInternal(ctx *context.APIContext, filter string) {
 | |
| 	refs, lastMethodName, err := utils.GetGitRefs(ctx, filter)
 | |
| 	if err != nil {
 | |
| 		ctx.Error(http.StatusInternalServerError, lastMethodName, err)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	if len(refs) == 0 {
 | |
| 		ctx.NotFound()
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	apiRefs := make([]*api.Reference, len(refs))
 | |
| 	for i := range refs {
 | |
| 		apiRefs[i] = &api.Reference{
 | |
| 			Ref: refs[i].Name,
 | |
| 			URL: ctx.Repo.Repository.APIURL() + "/git/" + util.PathEscapeSegments(refs[i].Name),
 | |
| 			Object: &api.GitObject{
 | |
| 				SHA:  refs[i].Object.String(),
 | |
| 				Type: refs[i].Type,
 | |
| 				URL:  ctx.Repo.Repository.APIURL() + "/git/" + url.PathEscape(refs[i].Type) + "s/" + url.PathEscape(refs[i].Object.String()),
 | |
| 			},
 | |
| 		}
 | |
| 	}
 | |
| 	// If single reference is found and it matches filter exactly return it as object
 | |
| 	if len(apiRefs) == 1 && apiRefs[0].Ref == filter {
 | |
| 		ctx.JSON(http.StatusOK, &apiRefs[0])
 | |
| 		return
 | |
| 	}
 | |
| 	ctx.JSON(http.StatusOK, &apiRefs)
 | |
| }
 |