summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorSteven <soud@protonmail.com>2015-10-01 15:17:27 +0200
committerSteven <soud@protonmail.com>2015-10-01 15:51:46 +0200
commitc8aa9c6cb1ed79398b825c6110b5a6a7002d1a35 (patch)
tree3da97bdcac380cb5af2f43a063b8466b58f63313 /routers/repo
parente0a099ec112e2746ec1f6dcd3276d19e14e50b06 (diff)
downloadgitea-c8aa9c6cb1ed79398b825c6110b5a6a7002d1a35.tar.gz
gitea-c8aa9c6cb1ed79398b825c6110b5a6a7002d1a35.zip
implemented #1721: see users who forked/starred/watched a repository
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/forks.go37
-rw-r--r--routers/repo/stars.go44
-rw-r--r--routers/repo/watchers.go44
3 files changed, 125 insertions, 0 deletions
diff --git a/routers/repo/forks.go b/routers/repo/forks.go
new file mode 100644
index 0000000000..099f0cc4f6
--- /dev/null
+++ b/routers/repo/forks.go
@@ -0,0 +1,37 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ "fmt"
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/middleware"
+)
+
+const (
+ FORKS base.TplName = "repo/forks"
+)
+
+func Forks(ctx *middleware.Context) {
+ ctx.Data["Title"] = ctx.Tr("repos.forks")
+
+ forks, err := ctx.Repo.Repository.GetForks()
+
+ if err != nil {
+ ctx.Handle(500, "GetForks", err)
+ return
+ }
+
+ for _, fork := range forks {
+ if err = fork.GetOwner(); err != nil {
+ ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", fork.ID, err))
+ return
+ }
+ }
+
+ ctx.Data["Forks"] = forks
+
+ ctx.HTML(200, FORKS)
+}
diff --git a/routers/repo/stars.go b/routers/repo/stars.go
new file mode 100644
index 0000000000..ffccd1765b
--- /dev/null
+++ b/routers/repo/stars.go
@@ -0,0 +1,44 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ "github.com/Unknwon/paginater"
+
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/middleware"
+)
+
+const (
+ STARS base.TplName = "repo/stars"
+)
+
+func Stars(ctx *middleware.Context) {
+ ctx.Data["Title"] = ctx.Tr("repos.stars")
+
+ page := ctx.ParamsInt(":index")
+ if page <= 0 {
+ page = 1
+ }
+
+ ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumStars, models.ItemsPerPage, page, 5)
+
+ stars, err := ctx.Repo.Repository.GetStars(ctx.ParamsInt(":index"))
+
+ if err != nil {
+ ctx.Handle(500, "GetStars", err)
+ return
+ }
+
+ if (ctx.ParamsInt(":index")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumStars {
+ ctx.Handle(404, "ctx.Repo.Repository.NumStars", nil)
+ return
+ }
+
+ ctx.Data["Stars"] = stars
+
+ ctx.HTML(200, STARS)
+}
diff --git a/routers/repo/watchers.go b/routers/repo/watchers.go
new file mode 100644
index 0000000000..8765b18376
--- /dev/null
+++ b/routers/repo/watchers.go
@@ -0,0 +1,44 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ "github.com/Unknwon/paginater"
+
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/middleware"
+)
+
+const (
+ WATCHERS base.TplName = "repo/watchers"
+)
+
+func Watchers(ctx *middleware.Context) {
+ ctx.Data["Title"] = ctx.Tr("repos.watches")
+
+ page := ctx.ParamsInt(":index")
+ if page <= 0 {
+ page = 1
+ }
+
+ ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumWatches, models.ItemsPerPage, page, 5)
+
+ watchers, err := ctx.Repo.Repository.GetWatchers(ctx.ParamsInt(":index"))
+
+ if err != nil {
+ ctx.Handle(500, "GetWatchers", err)
+ return
+ }
+
+ if (ctx.ParamsInt(":index")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumWatches {
+ ctx.Handle(404, "ctx.Repo.Repository.NumWatches", nil)
+ return
+ }
+
+ ctx.Data["Watchers"] = watchers
+
+ ctx.HTML(200, WATCHERS)
+}