diff options
author | Steven <soud@protonmail.com> | 2015-10-01 15:17:27 +0200 |
---|---|---|
committer | Steven <soud@protonmail.com> | 2015-10-01 15:51:46 +0200 |
commit | c8aa9c6cb1ed79398b825c6110b5a6a7002d1a35 (patch) | |
tree | 3da97bdcac380cb5af2f43a063b8466b58f63313 /models | |
parent | e0a099ec112e2746ec1f6dcd3276d19e14e50b06 (diff) | |
download | gitea-c8aa9c6cb1ed79398b825c6110b5a6a7002d1a35.tar.gz gitea-c8aa9c6cb1ed79398b825c6110b5a6a7002d1a35.zip |
implemented #1721: see users who forked/starred/watched a repository
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go index f3a32d6877..fc155fa5f5 100644 --- a/models/repo.go +++ b/models/repo.go @@ -46,6 +46,9 @@ var ( var ( Gitignores, Licenses, Readmes []string + + // Maximum items per page in forks, watchers and stars of a repo + ItemsPerPage = 3 ) func LoadRepoConfig() { @@ -1612,6 +1615,16 @@ func GetWatchers(rid int64) ([]*Watch, error) { return getWatchers(x, rid) } +// Repository.GetWatchers returns all users watching given repository. +func (repo *Repository) GetWatchers(offset int) ([]*User, error) { + users := make([]*User, 0, 10) + offset = (offset - 1) * ItemsPerPage + + err := x.Limit(ItemsPerPage, offset).Where("repo_id=?", repo.ID).Join("LEFT", "watch", "user.id=watch.user_id").Find(&users) + + return users, err +} + func notifyWatchers(e Engine, act *Action) error { // Add feeds for user self and all watchers. watches, err := getWatchers(e, act.RepoID) @@ -1689,6 +1702,15 @@ func IsStaring(uid, repoId int64) bool { return has } +func (repo *Repository) GetStars(offset int) ([]*User, error) { + users := make([]*User, 0, 10) + offset = (offset - 1) * ItemsPerPage + + err := x.Limit(ItemsPerPage, offset).Where("repo_id=?", repo.ID).Join("LEFT", "star", "user.id=star.uid").Find(&users) + + return users, err +} + // ___________ __ // \_ _____/__________| | __ // | __)/ _ \_ __ \ |/ / @@ -1756,3 +1778,11 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit return repo, sess.Commit() } + +func (repo *Repository) GetForks() ([]*Repository, error) { + forks := make([]*Repository, 0, 10) + + err := x.Find(&forks, &Repository{ForkID: repo.ID}) + + return forks, err +} |