From 1597e2da3e72b9a846f7b17bf38c1d192f43c182 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 30 Apr 2022 16:32:01 +0200 Subject: [PATCH] Use middleware to open gitRepo (#19559) --- routers/api/v1/api.go | 2 +- routers/api/v1/utils/git.go | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 9351cc1510..ce0719ddd8 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1014,7 +1014,7 @@ func Routes() *web.Route { m.Group("/{ref}", func() { m.Get("/status", repo.GetCombinedCommitStatusByRef) m.Get("/statuses", repo.GetCommitStatusesByRef) - }) + }, context.ReferencesGitRepo()) }, reqRepoReader(unit.TypeCode)) m.Group("/git", func() { m.Group("/commits", func() { diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go index 9f02bc8083..ac64d5b87b 100644 --- a/routers/api/v1/utils/git.go +++ b/routers/api/v1/utils/git.go @@ -5,6 +5,7 @@ package utils import ( + "fmt" "net/http" "code.gitea.io/gitea/modules/context" @@ -35,12 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string { // GetGitRefs return git references based on filter func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) { if ctx.Repo.GitRepo == nil { - var err error - ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) - if err != nil { - return nil, "OpenRepository", err - } - defer ctx.Repo.GitRepo.Close() + return nil, "", fmt.Errorf("no open git repo found in context") } if len(filter) > 0 { filter = "refs/" + filter