| @@ -578,8 +578,16 @@ func safeURL(address string) string { | |||
| type ContributorInfo struct { | |||
| UserInfo *models.User // nil for contributor who is not a registered user | |||
| Email string | |||
| CommitCnt int | |||
| UserName string `json:"user_name"` | |||
| Email string `json:"email"` | |||
| CommitCnt int `json:"commit_cnt"` | |||
| } | |||
| type GetContributorsInfo struct { | |||
| ErrorCode int `json:"error_code"` | |||
| ErrorMsg string `json:"error_msg"` | |||
| Count int `json:"count"` | |||
| ContributorInfo []*ContributorInfo `json:"contributor_info"` | |||
| } | |||
| func getContributorInfo(contributorInfos []*ContributorInfo, email string) *ContributorInfo { | |||
| @@ -618,7 +626,7 @@ func Home(ctx *context.Context) { | |||
| } else { | |||
| // new committer info | |||
| var newContributor = &ContributorInfo{ | |||
| user, user.Email, c.CommitCnt, | |||
| user, user.Name, user.Email, c.CommitCnt, | |||
| } | |||
| count++ | |||
| contributorInfos = append(contributorInfos, newContributor) | |||
| @@ -631,7 +639,7 @@ func Home(ctx *context.Context) { | |||
| existedContributorInfo.CommitCnt += c.CommitCnt | |||
| } else { | |||
| var newContributor = &ContributorInfo{ | |||
| user, c.Email, c.CommitCnt, | |||
| user, "", c.Email, c.CommitCnt, | |||
| } | |||
| count++ | |||
| contributorInfos = append(contributorInfos, newContributor) | |||
| @@ -909,24 +917,14 @@ 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 | |||
| errorCode := 0 | |||
| errorMsg := "" | |||
| contributors, err := git.GetContributors(ctx.Repo.Repository.RepoPath()) | |||
| var contributorInfos []*ContributorInfo | |||
| if err == nil && contributors != nil { | |||
| startTime := time.Now() | |||
| var contributorInfos []*ContributorInfo | |||
| contributorInfoHash := make(map[string]*ContributorInfo) | |||
| for i, c := range contributors { | |||
| if i < start || i >= end { | |||
| continue | |||
| } | |||
| for _, c := range contributors { | |||
| if strings.Compare(c.Email, "") == 0 { | |||
| continue | |||
| } | |||
| @@ -940,9 +938,9 @@ func Contributors(ctx *context.Context) { | |||
| } else { | |||
| // new committer info | |||
| var newContributor = &ContributorInfo{ | |||
| user, user.Email, c.CommitCnt, | |||
| user, user.Name, user.Email, c.CommitCnt, | |||
| } | |||
| count ++ | |||
| count++ | |||
| contributorInfos = append(contributorInfos, newContributor) | |||
| contributorInfoHash[user.Email] = newContributor | |||
| } | |||
| @@ -953,24 +951,24 @@ func Contributors(ctx *context.Context) { | |||
| existedContributorInfo.CommitCnt += c.CommitCnt | |||
| } else { | |||
| var newContributor = &ContributorInfo{ | |||
| user, c.Email, c.CommitCnt, | |||
| user, "", c.Email, c.CommitCnt, | |||
| } | |||
| count ++ | |||
| count++ | |||
| contributorInfos = append(contributorInfos, newContributor) | |||
| contributorInfoHash[c.Email] = newContributor | |||
| } | |||
| } | |||
| } | |||
| ctx.Data["ContributorInfo"] = contributorInfos | |||
| var duration= time.Since(startTime) | |||
| log.Info("getContributorInfo cost: %v seconds", duration.Seconds()) | |||
| } else { | |||
| ctx.ServerError("GetContributors failed", err) | |||
| return | |||
| log.Error("GetContributors failed: %v", err) | |||
| errorCode = -1 | |||
| errorMsg = err.Error() | |||
| } | |||
| pager := context.NewPagination(count, pageSize, page, 5) | |||
| ctx.Data["Page"] = pager | |||
| ctx.Data["Total"] = count | |||
| ctx.HTML(http.StatusOK, tplContributors) | |||
| ctx.JSON(http.StatusOK, GetContributorsInfo{ | |||
| ErrorCode: errorCode, | |||
| ErrorMsg: errorMsg, | |||
| Count: count, | |||
| ContributorInfo: contributorInfos, | |||
| }) | |||
| } | |||