From 4805d5bfb17787e22a688b8eda5f7cc6c5157aa5 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 16 Dec 2021 10:52:40 +0800 Subject: [PATCH] =?UTF-8?q?fix-101=E8=B4=A1=E7=8C=AE=E8=80=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/git/repo.go | 12 ++++++++---- routers/repo/view.go | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/git/repo.go b/modules/git/repo.go index 772f1d149..f72f5df7e 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -445,8 +445,12 @@ type Contributor struct { Email string } -func GetContributors(repoPath string) ([]Contributor, error){ - cmd := NewCommand("shortlog", "-sne", "--all") +func GetContributors(repoPath string, branchOrTag ...string) ([]Contributor, error) { + targetBranchOrTag := "HEAD" + if len(branchOrTag) > 0 && branchOrTag[0] != "" { + targetBranchOrTag = branchOrTag[0] + } + cmd := NewCommand("shortlog", "-sne", targetBranchOrTag) stdout, err := cmd.RunInDir(repoPath) if err != nil { return nil, err @@ -462,9 +466,9 @@ func GetContributors(repoPath string) ([]Contributor, error){ } number := oneCount[0:strings.Index(oneCount, "\t")] commitCnt, _ := strconv.Atoi(number) - committer := oneCount[strings.Index(oneCount, "\t")+1:strings.LastIndex(oneCount, " ")] + committer := oneCount[strings.Index(oneCount, "\t")+1 : strings.LastIndex(oneCount, " ")] committer = strings.Trim(committer, " ") - email := oneCount[strings.Index(oneCount, "<")+1:strings.Index(oneCount, ">")] + email := oneCount[strings.Index(oneCount, "<")+1 : strings.Index(oneCount, ">")] contributorsInfo[i] = Contributor{ commitCnt, committer, email, } diff --git a/routers/repo/view.go b/routers/repo/view.go index a5f2e1477..b08243240 100755 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -605,7 +605,7 @@ func getContributorInfo(contributorInfos []*ContributorInfo, email string) *Cont func Home(ctx *context.Context) { if len(ctx.Repo.Units) > 0 { //get repo contributors info - contributors, err := git.GetContributors(ctx.Repo.Repository.RepoPath()) + contributors, err := git.GetContributors(ctx.Repo.Repository.RepoPath(), ctx.Repo.BranchName) if err == nil && contributors != nil { startTime := time.Now() var contributorInfos []*ContributorInfo @@ -924,7 +924,9 @@ func ContributorsAPI(ctx *context.Context) { count := 0 errorCode := 0 errorMsg := "" - contributors, err := git.GetContributors(ctx.Repo.Repository.RepoPath()) + + branchOrTag := ctx.Query("name") + contributors, err := git.GetContributors(ctx.Repo.Repository.RepoPath(), branchOrTag) var contributorInfos []*ContributorInfo if err == nil && contributors != nil { contributorInfoHash := make(map[string]*ContributorInfo)