Let branch/tag name be a valid ref to get CI status (#16400)

* fix #16384#

* refactor: move shared helper func to utils package

* extend Tests

* use ctx.Repo.GitRepo if not nil
This commit is contained in:
6543 2021-07-13 09:14:14 +02:00 committed by GitHub
parent 4ce32c9e93
commit b81106be3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 60 deletions

View file

@ -8,8 +8,8 @@ import (
"net/http"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
)
// GetGitAllRefs get ref or an list all the refs of a repository
@ -73,22 +73,8 @@ func GetGitRefs(ctx *context.APIContext) {
getGitRefsInternal(ctx, ctx.Params("*"))
}
func getGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
if err != nil {
return nil, "OpenRepository", err
}
defer gitRepo.Close()
if len(filter) > 0 {
filter = "refs/" + filter
}
refs, err := gitRepo.GetRefsFiltered(filter)
return refs, "GetRefsFiltered", err
}
func getGitRefsInternal(ctx *context.APIContext, filter string) {
refs, lastMethodName, err := getGitRefs(ctx, filter)
refs, lastMethodName, err := utils.GetGitRefs(ctx, filter)
if err != nil {
ctx.Error(http.StatusInternalServerError, lastMethodName, err)
return