|
|
@@ -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) |
|
|
|
} |