mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 01:39:31 +00:00
894d9b2836
Since `modules/context` has to depend on `models` and many other packages, it should be moved from `modules/context` to `services/context` according to design principles. There is no logic code change on this PR, only move packages. - Move `code.gitea.io/gitea/modules/context` to `code.gitea.io/gitea/services/context` - Move `code.gitea.io/gitea/modules/contexttest` to `code.gitea.io/gitea/services/contexttest` because of depending on context - Move `code.gitea.io/gitea/modules/upload` to `code.gitea.io/gitea/services/context/upload` because of depending on context (cherry picked from commit 29f149bd9f517225a3c9f1ca3fb0a7b5325af696) Conflicts: routers/api/packages/alpine/alpine.go routers/api/v1/repo/issue_reaction.go routers/install/install.go routers/web/admin/config.go routers/web/passkey.go routers/web/repo/search.go routers/web/repo/setting/default_branch.go routers/web/user/home.go routers/web/user/profile.go tests/integration/editor_test.go tests/integration/integration_test.go tests/integration/mirror_push_test.go trivial context conflicts also modified all other occurrences in Forgejo specific files
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
"code.gitea.io/gitea/modules/util"
|
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
|
"code.gitea.io/gitea/services/context"
|
|
)
|
|
|
|
// 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)
|
|
}
|