summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2016-11-14 17:33:58 -0500
committerEthan Koenig <ethantkoenig@gmail.com>2016-11-16 22:51:54 -0500
commit0834e492c06e30d30c2bc8eec4fcb6c499a62ced (patch)
tree9a7888958b31770b2a4a4411e08095452f1d5e4a /modules
parent871c964ef7aaf70af5e9eab00a3d6642432b122a (diff)
downloadgitea-0834e492c06e30d30c2bc8eec4fcb6c499a62ced.tar.gz
gitea-0834e492c06e30d30c2bc8eec4fcb6c499a62ced.zip
API endpoints for stars
Diffstat (limited to 'modules')
-rw-r--r--modules/context/api.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index 197fbd6df1..0da1823797 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
+ "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -70,3 +71,33 @@ func APIContexter() macaron.Handler {
c.Map(ctx)
}
}
+
+// ExtractOwnerAndRepo returns a handler that populates the `Repo.Owner` and
+// `Repo.Repository` fields of an APIContext
+func ExtractOwnerAndRepo() macaron.Handler {
+ return func(ctx *APIContext) {
+ owner, err := models.GetUserByName(ctx.Params(":username"))
+ if err != nil {
+ if models.IsErrUserNotExist(err) {
+ ctx.Error(422, "", err)
+ } else {
+ ctx.Error(500, "GetUserByName", err)
+ }
+ return
+ }
+
+ repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
+ if err != nil {
+ if models.IsErrRepoNotExist(err) {
+ ctx.Status(404)
+ } else {
+ ctx.Error(500, "GetRepositoryByName", err)
+ }
+ return
+ }
+ ctx.Repo.Owner = owner
+ ctx.Data["Owner"] = owner
+ ctx.Repo.Repository = repo
+ ctx.Data["Repository"] = repo
+ }
+}