1
0
Fork 0
forked from forgejo/forgejo

[API] Pull Requests (#248)

This commit is contained in:
Kim "BKC" Carlbäcker 2016-12-02 12:10:39 +01:00 committed by GitHub
parent d7ed78a919
commit 0f05470cb8
6 changed files with 592 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"code.gitea.io/git"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
@ -103,3 +104,24 @@ func ExtractOwnerAndRepo() macaron.Handler {
ctx.Data["Repository"] = repo
}
}
// ReferencesGitRepo injects the GitRepo into the Context
func ReferencesGitRepo() macaron.Handler {
return func(ctx *APIContext) {
// Empty repository does not have reference information.
if ctx.Repo.Repository.IsBare {
return
}
// For API calls.
if ctx.Repo.GitRepo == nil {
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
ctx.Error(500, "RepoRef Invalid repo "+repoPath, err)
return
}
ctx.Repo.GitRepo = gitRepo
}
}
}