From 85c7eec65fb1c5a514b01e42379fa12ceca01d40 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Mon, 8 Nov 2021 15:30:51 +0800 Subject: [PATCH] add contributors --- modules/setting/setting.go | 28 +++++++++++++++------------- routers/repo/view.go | 21 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index abe406de8..2d469b638 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -163,6 +163,7 @@ var ( // UI settings UI = struct { ExplorePagingNum int + ContributorPagingNum int IssuePagingNum int RepoSearchPagingNum int MembersPagingNum int @@ -203,19 +204,20 @@ var ( Keywords string } `ini:"ui.meta"` }{ - ExplorePagingNum: 20, - IssuePagingNum: 10, - RepoSearchPagingNum: 10, - MembersPagingNum: 20, - FeedMaxCommitNum: 5, - GraphMaxCommitNum: 100, - CodeCommentLines: 4, - ReactionMaxUserNum: 10, - ThemeColorMetaTag: `#6cc644`, - MaxDisplayFileSize: 8388608, - DefaultTheme: `gitea`, - Themes: []string{`gitea`, `arc-green`}, - Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`}, + ExplorePagingNum: 20, + ContributorPagingNum: 50, + IssuePagingNum: 10, + RepoSearchPagingNum: 10, + MembersPagingNum: 20, + FeedMaxCommitNum: 5, + GraphMaxCommitNum: 100, + CodeCommentLines: 4, + ReactionMaxUserNum: 10, + ThemeColorMetaTag: `#6cc644`, + MaxDisplayFileSize: 8388608, + DefaultTheme: `gitea`, + Themes: []string{`gitea`, `arc-green`}, + Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`}, Notification: struct { MinTimeout time.Duration TimeoutStep time.Duration diff --git a/routers/repo/view.go b/routers/repo/view.go index a8b2f239d..cc33302e9 100755 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -898,13 +898,24 @@ func Forks(ctx *context.Context) { } func Contributors(ctx *context.Context) { + page := ctx.QueryInt("page") + if page <= 0 { + page = 1 + } + pageSize := setting.UI.ContributorPagingNum + start := (page-1) * pageSize + end := page * pageSize + count := 0 //get repo contributors info contributors, err := git.GetContributors(ctx.Repo.Repository.RepoPath()) if err == nil && contributors != nil { startTime := time.Now() var contributorInfos []*ContributorInfo contributorInfoHash := make(map[string]*ContributorInfo) - for _, c := range contributors { + for i, c := range contributors { + if i < start || i >= end { + continue + } if strings.Compare(c.Email, "") == 0 { continue } @@ -937,9 +948,17 @@ func Contributors(ctx *context.Context) { } } } + count ++ ctx.Data["ContributorInfo"] = contributorInfos var duration= time.Since(startTime) log.Info("getContributorInfo cost: %v seconds", duration.Seconds()) + } else { + ctx.ServerError("GetContributors failed", err) + return } + + pager := context.NewPagination(count, pageSize, page, 5) + ctx.Data["Page"] = pager + ctx.Data["Total"] = count ctx.HTML(http.StatusOK, tplContributors) }