From cbbf9282b5dc47218caa4a2545a06a6eae069ebc Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 5 Nov 2021 10:01:32 +0800 Subject: [PATCH 01/35] add contributors route --- routers/repo/view.go | 120 +++++++++++++++++++++++++++------------ routers/routes/routes.go | 1 + templates/repo/contributors.tmpl | 6 ++ 3 files changed, 92 insertions(+), 35 deletions(-) mode change 100644 => 100755 routers/repo/view.go create mode 100755 templates/repo/contributors.tmpl diff --git a/routers/repo/view.go b/routers/repo/view.go old mode 100644 new mode 100755 index 9477b27dd..a8b2f239d --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -12,6 +12,7 @@ import ( "fmt" gotemplate "html/template" "io/ioutil" + "net/http" "net/url" "path" "strings" @@ -31,11 +32,12 @@ import ( ) const ( - tplRepoEMPTY base.TplName = "repo/empty" - tplRepoHome base.TplName = "repo/home" - tplWatchers base.TplName = "repo/watchers" - tplForks base.TplName = "repo/forks" - tplMigrating base.TplName = "repo/migrating" + tplRepoEMPTY base.TplName = "repo/empty" + tplRepoHome base.TplName = "repo/home" + tplWatchers base.TplName = "repo/watchers" + tplForks base.TplName = "repo/forks" + tplMigrating base.TplName = "repo/migrating" + tplContributors base.TplName = "repo/contributors" ) type namedBlob struct { @@ -570,19 +572,20 @@ func safeURL(address string) string { } type ContributorInfo struct { - UserInfo *models.User // nil for contributor who is not a registered user - Email string + UserInfo *models.User // nil for contributor who is not a registered user + Email string CommitCnt int } -func getContributorInfo(contributorInfos []*ContributorInfo, email string) *ContributorInfo{ +func getContributorInfo(contributorInfos []*ContributorInfo, email string) *ContributorInfo { for _, c := range contributorInfos { - if strings.Compare(c.Email,email) == 0 { + if strings.Compare(c.Email, email) == 0 { return c } } return nil } + // Home render repository home page func Home(ctx *context.Context) { if len(ctx.Repo.Units) > 0 { @@ -591,34 +594,34 @@ func Home(ctx *context.Context) { if err == nil && contributors != nil { startTime := time.Now() var contributorInfos []*ContributorInfo - contributorInfoHash:= make(map[string]*ContributorInfo) + contributorInfoHash := make(map[string]*ContributorInfo) for _, c := range contributors { - if strings.Compare(c.Email,"") == 0 { + if strings.Compare(c.Email, "") == 0 { continue } // get user info from committer email user, err := models.GetUserByActivateEmail(c.Email) if err == nil { // committer is system user, get info through user's primary email - if existedContributorInfo,ok:=contributorInfoHash[user.Email];ok { + if existedContributorInfo, ok := contributorInfoHash[user.Email]; ok { // existed: same primary email, different committer name existedContributorInfo.CommitCnt += c.CommitCnt - }else{ + } else { // new committer info var newContributor = &ContributorInfo{ - user, user.Email,c.CommitCnt, + user, user.Email, c.CommitCnt, } - contributorInfos = append(contributorInfos, newContributor ) + contributorInfos = append(contributorInfos, newContributor) contributorInfoHash[user.Email] = newContributor } } else { // committer is not system user - if existedContributorInfo,ok:=contributorInfoHash[c.Email];ok { + if existedContributorInfo, ok := contributorInfoHash[c.Email]; ok { // existed: same primary email, different committer name existedContributorInfo.CommitCnt += c.CommitCnt - }else{ + } else { var newContributor = &ContributorInfo{ - user, c.Email,c.CommitCnt, + user, c.Email, c.CommitCnt, } contributorInfos = append(contributorInfos, newContributor) contributorInfoHash[c.Email] = newContributor @@ -627,7 +630,7 @@ func Home(ctx *context.Context) { } ctx.Data["ContributorInfo"] = contributorInfos var duration = time.Since(startTime) - log.Info("getContributorInfo cost: %v seconds",duration.Seconds()) + log.Info("getContributorInfo cost: %v seconds", duration.Seconds()) } if ctx.Repo.Repository.IsBeingCreated() { task, err := models.GetMigratingTask(ctx.Repo.Repository.ID) @@ -694,13 +697,13 @@ func renderLicense(ctx *context.Context) { log.Error("failed to get license content: %v, err:%v", f, err) continue } - if bytes.Compare(buf,license) == 0 { - log.Info("got matched license:%v",f) + if bytes.Compare(buf, license) == 0 { + log.Info("got matched license:%v", f) ctx.Data["LICENSE"] = f return } } - log.Info("not found matched license,repo:%v",ctx.Repo.Repository.Name) + log.Info("not found matched license,repo:%v", ctx.Repo.Repository.Name) } func renderLanguageStats(ctx *context.Context) { @@ -801,31 +804,31 @@ func renderCode(ctx *context.Context) { baseGitRepo, err := git.OpenRepository(ctx.Repo.Repository.BaseRepo.RepoPath()) defer baseGitRepo.Close() if err != nil { - log.Error("error open baseRepo:%s",ctx.Repo.Repository.BaseRepo.RepoPath()) + log.Error("error open baseRepo:%s", ctx.Repo.Repository.BaseRepo.RepoPath()) ctx.Data["FetchUpstreamCnt"] = -1 // minus value indicates error - }else{ - if _,error:= baseGitRepo.GetBranch(ctx.Repo.BranchName);error==nil{ + } else { + if _, error := baseGitRepo.GetBranch(ctx.Repo.BranchName); error == nil { //base repo has the same branch, then compare between current repo branch and base repo's branch - compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.BranchName - ctx.SetParams("*",compareUrl) + compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.BranchName + ctx.SetParams("*", compareUrl) ctx.Data["UpstreamSameBranchName"] = true - }else{ + } else { //else, compare between current repo branch and base repo's default branch - compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.Repository.BaseRepo.DefaultBranch - ctx.SetParams("*",compareUrl) + compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.Repository.BaseRepo.DefaultBranch + ctx.SetParams("*", compareUrl) ctx.Data["UpstreamSameBranchName"] = false } _, _, headGitRepo, compareInfo, _, _ := ParseCompareInfo(ctx) defer headGitRepo.Close() - if compareInfo!= nil { - if compareInfo.Commits!=nil { - log.Info("compareInfoCommits数量:%d",compareInfo.Commits.Len()) + if compareInfo != nil { + if compareInfo.Commits != nil { + log.Info("compareInfoCommits数量:%d", compareInfo.Commits.Len()) ctx.Data["FetchUpstreamCnt"] = compareInfo.Commits.Len() - }else{ + } else { log.Info("compareInfo nothing different") ctx.Data["FetchUpstreamCnt"] = 0 } - }else{ + } else { ctx.Data["FetchUpstreamCnt"] = -1 // minus value indicates error } } @@ -893,3 +896,50 @@ func Forks(ctx *context.Context) { ctx.HTML(200, tplForks) } + +func Contributors(ctx *context.Context) { + //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 { + if strings.Compare(c.Email, "") == 0 { + continue + } + // get user info from committer email + user, err := models.GetUserByActivateEmail(c.Email) + if err == nil { + // committer is system user, get info through user's primary email + if existedContributorInfo, ok := contributorInfoHash[user.Email]; ok { + // existed: same primary email, different committer name + existedContributorInfo.CommitCnt += c.CommitCnt + } else { + // new committer info + var newContributor = &ContributorInfo{ + user, user.Email, c.CommitCnt, + } + contributorInfos = append(contributorInfos, newContributor) + contributorInfoHash[user.Email] = newContributor + } + } else { + // committer is not system user + if existedContributorInfo, ok := contributorInfoHash[c.Email]; ok { + // existed: same primary email, different committer name + existedContributorInfo.CommitCnt += c.CommitCnt + } else { + var newContributor = &ContributorInfo{ + user, c.Email, c.CommitCnt, + } + 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()) + } + ctx.HTML(http.StatusOK, tplContributors) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 7e7d0642a..c8dad85a2 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -789,6 +789,7 @@ func RegisterRoutes(m *macaron.Macaron) { // Grouping for those endpoints not requiring authentication m.Group("/:username/:reponame", func() { + m.Get("/contributors", repo.Contributors) m.Group("/milestone", func() { m.Get("/:id", repo.MilestoneIssuesAndPulls) }, reqRepoIssuesOrPullsReader, context.RepoRef()) diff --git a/templates/repo/contributors.tmpl b/templates/repo/contributors.tmpl new file mode 100755 index 000000000..235ebf23b --- /dev/null +++ b/templates/repo/contributors.tmpl @@ -0,0 +1,6 @@ +{{template "base/head" .}} +
免费私有代码仓库,免费计算资源,大容量数据存储,
多类型硬件环境(GPU、NPU),AI开发流水线(开发-调试-训练-迭代)
你确认删除该任务么?此任务一旦删除不可恢复。
-任务名称: {{.JobName}}
- {{end}} -任务结果:
- {{with .result}} -状态 | -{{.Status}} | -
开始时间 | -{{.CreateTime}} | -
最后更新时间 | -{{.LatestUpdateTime}} | -
配置信息 | |
---|---|
开发环境类型 | -{{.Profile.DeType}} | -
硬件类型 | -{{.Profile.FlavorType}} | -
机器规格详情 | |
---|---|
机器规格 | -{{.Flavor}} | -
规格名称 | -{{.FlavorDetails.Name}} | -
规格销售状态 | -{{.FlavorDetails.Status}} | -
排队个数 | -{{.FlavorDetails.QueuingNum}} | -
排到队的剩余时间(秒) | -{{.FlavorDetails.QueueLeftTime}} | -
自动停止时间(秒) | -{{.FlavorDetails.Duration}} | -
排队信息 | |
---|---|
实例状态 | -{{.QueuingInfo.Status}} | -
实例排队的开始时间 | -{{.QueuingInfo.BeginTime}} | -
排到队的剩余时间(秒) | -{{.QueuingInfo.RemainTime}} | -
实例排队的预计停止时间 | -{{.QueuingInfo.EndTime}} | -
实例在队列中的排位 | -{{.QueuingInfo.Rank}} | -
在这里为你和你的团队创建项目,基于Git工具,提交记录或者回滚代码修改。
不论是公开或者私有仓库,都可免费使用所有功能。
尽情将你喜欢的代码都放在这里,仓库数量、存储容量不受限