Browse Source

add commit_cnt into repo

tags/v1.21.9.1^2
lewis 4 years ago
parent
commit
9acf1d291e
2 changed files with 29 additions and 0 deletions
  1. +1
    -0
      models/repo.go
  2. +28
    -0
      routers/private/hook.go

+ 1
- 0
models/repo.go View File

@@ -175,6 +175,7 @@ type Repository struct {
NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumOpenMilestones int `xorm:"-"`
NumCommit int64

IsPrivate bool `xorm:"INDEX"`
IsEmpty bool `xorm:"INDEX"`


+ 28
- 0
routers/private/hook.go View File

@@ -520,12 +520,40 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
}
}
}
if err := updateRepoCommitCnt(ctx, repo); err != nil {
log.Error("updateRepoCommitCnt failed:%v", err.Error(), ctx.Data["MsgID"])
}

ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
Results: results,
RepoWasEmpty: wasEmpty,
})
}

func updateRepoCommitCnt(ctx *macaron.Context, repo *models.Repository) error {
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
log.Error("OpenRepository failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}
defer gitRepo.Close()

count, err := gitRepo.GetAllCommitsCount()
if err != nil {
log.Error("GetAllCommitsCount failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}

repo.NumCommit = count
if err = models.UpdateRepositoryCols(repo, "num_commit"); err != nil {
log.Error("UpdateRepositoryCols failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}

return nil
}

// SetDefaultBranch updates the default branch
func SetDefaultBranch(ctx *macaron.Context) {
ownerName := ctx.Params(":owner")


Loading…
Cancel
Save