Browse Source

Merge branch 'V20211115' of git.openi.org.cn:OpenI/aiforge into fix-224

pull/746/head
lewis 3 years ago
parent
commit
943ee77df0
6 changed files with 45 additions and 3 deletions
  1. +1
    -0
      models/org.go
  2. +22
    -1
      models/repo.go
  3. +6
    -0
      routers/repo/http.go
  4. +14
    -0
      routers/repo/user_data_analysis.go
  5. +1
    -1
      routers/routes/routes.go
  6. +1
    -1
      templates/org/home.tmpl

+ 1
- 0
models/org.go View File

@@ -182,6 +182,7 @@ func CreateOrganization(org, owner *User) (err error) {
if _, err = sess.Insert(&OrgUser{
UID: owner.ID,
OrgID: org.ID,
IsPublic: setting.Service.DefaultOrgMemberVisible,
}); err != nil {
return fmt.Errorf("insert org-user relation: %v", err)
}


+ 22
- 1
models/repo.go View File

@@ -210,9 +210,12 @@ type Repository struct {
Balance string `xorm:"NOT NULL DEFAULT '0'"`
BlockChainStatus RepoBlockChainStatus `xorm:"NOT NULL DEFAULT 0"`

// git clone total count
// git clone and git pull total count
CloneCnt int64 `xorm:"NOT NULL DEFAULT 0"`

// only git clone total count
GitCloneCnt int64 `xorm:"NOT NULL DEFAULT 0"`

CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

@@ -2473,6 +2476,24 @@ func (repo *Repository) IncreaseCloneCnt() {
return
}

func (repo *Repository) IncreaseGitCloneCnt() {
sess := x.NewSession()
defer sess.Close()

if err := sess.Begin(); err != nil {
return
}
if _, err := sess.Exec("UPDATE `repository` SET git_clone_cnt = git_clone_cnt + 1 WHERE id = ?", repo.ID); err != nil {
return
}

if err := sess.Commit(); err != nil {
return
}

return
}

func UpdateRepositoryCommitNum(repo *Repository) error {
if _, err := x.Exec("UPDATE `repository` SET num_commit = ? where id = ?", repo.NumCommit, repo.ID); err != nil {
return err


+ 6
- 0
routers/repo/http.go View File

@@ -317,6 +317,12 @@ func HTTP(ctx *context.Context) {
go repo.IncreaseCloneCnt()
}

if ctx.Req.Method == "POST" {
if strings.HasSuffix(ctx.Req.URL.Path, "git-upload-pack") {
go repo.IncreaseGitCloneCnt()
}
}

w := ctx.Resp
r := ctx.Req.Request
cfg := &serviceConfig{


+ 14
- 0
routers/repo/user_data_analysis.go View File

@@ -1,13 +1,27 @@
package repo

import (
"fmt"
"net/http"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
)

func QueryUserStaticData(ctx *context.Context) {
startDate := ctx.Query("startDate")
endDate := ctx.Query("endDate")
log.Info("startDate=" + startDate + " endDate=" + endDate)
startTime, _ := time.Parse("2006-01-02", startDate)
endTime, _ := time.Parse("2006-01-02", endDate)
log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix()))
ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix()))

}

func TimingCountDataByDate(date string) {

t, _ := time.Parse("2006-01-02", date)


+ 1
- 1
routers/routes/routes.go View File

@@ -791,7 +791,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef())

m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action)
m.Get("/tool/query_user_static", repo.QueryUserStaticData)
// Grouping for those endpoints not requiring authentication
m.Group("/:username/:reponame", func() {
m.Get("/contributors", repo.Contributors)


+ 1
- 1
templates/org/home.tmpl View File

@@ -39,7 +39,7 @@
<h4 class="ui top attached header">
<strong>{{.i18n.Tr "org.people"}}</strong>
<div class="ui right">
<a class="text grey" href="{{.OrgLink}}/members">{{.Org.NumMembers}} {{svg "octicon-chevron-right" 16}}</a>
<a class="text grey" href="{{.OrgLink}}/members">{{.MembersTotal}} {{svg "octicon-chevron-right" 16}}</a>
</div>
<!-- {{if .IsOrganizationMember}} -->


Loading…
Cancel
Save