Skip to content

Commit 1597e2d

Browse files
authored
Use middleware to open gitRepo (#19559)
1 parent d23f220 commit 1597e2d

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ func Routes() *web.Route {
10141014
m.Group("/{ref}", func() {
10151015
m.Get("/status", repo.GetCombinedCommitStatusByRef)
10161016
m.Get("/statuses", repo.GetCommitStatusesByRef)
1017-
})
1017+
}, context.ReferencesGitRepo())
10181018
}, reqRepoReader(unit.TypeCode))
10191019
m.Group("/git", func() {
10201020
m.Group("/commits", func() {

routers/api/v1/utils/git.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package utils
66

77
import (
8+
"fmt"
89
"net/http"
910

1011
"code.gitea.io/gitea/modules/context"
@@ -35,12 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
3536
// GetGitRefs return git references based on filter
3637
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
3738
if ctx.Repo.GitRepo == nil {
38-
var err error
39-
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
40-
if err != nil {
41-
return nil, "OpenRepository", err
42-
}
43-
defer ctx.Repo.GitRepo.Close()
39+
return nil, "", fmt.Errorf("no open git repo found in context")
4440
}
4541
if len(filter) > 0 {
4642
filter = "refs/" + filter

0 commit comments

Comments
 (0)