diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2016-12-02 12:10:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-02 12:10:39 +0100 |
commit | 0f05470cb84a4dcfd00e69e5af51b4420b74e9d4 (patch) | |
tree | 9b6296dc8cfc660090fe90220397a015725e219f /modules/context | |
parent | d7ed78a91971260169c429f9ee47ebe8fa8f92ad (diff) | |
download | gitea-0f05470cb84a4dcfd00e69e5af51b4420b74e9d4.tar.gz gitea-0f05470cb84a4dcfd00e69e5af51b4420b74e9d4.zip |
[API] Pull Requests (#248)
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/api.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/context/api.go b/modules/context/api.go index 7706e9c499..7a3ff990b6 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -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 + } + } +} |