Browse Source

fix-101贡献者列表部分

tags/v1.21.12.2^2
ychao_1983 3 years ago
parent
commit
4805d5bfb1
2 changed files with 12 additions and 6 deletions
  1. +8
    -4
      modules/git/repo.go
  2. +4
    -2
      routers/repo/view.go

+ 8
- 4
modules/git/repo.go View File

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


+ 4
- 2
routers/repo/view.go View File

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


Loading…
Cancel
Save