From 751f11ca09c77c8cc591c88bb69356db2e2c8338 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 9 Dec 2022 15:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=B4=A1=E7=8C=AE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/action.go | 27 +++++++++++++++++++++++++++ routers/hat/hat.go | 3 +++ routers/hat/repo/repo.go | 11 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 models/action.go diff --git a/models/action.go b/models/action.go new file mode 100644 index 0000000..513cb4b --- /dev/null +++ b/models/action.go @@ -0,0 +1,27 @@ +package models + +import ( + "code.gitea.io/gitea/models/db" +) + +type Contributor struct { + ID int64 `json:"id"` + Name string `json:"name"` + Email string `json:"email"` + Contributions int64 `json:"contributions"` +} + +func GetContributors(repoID, userID int64) (result []Contributor, err error) { + sql := + `select a.act_user_id as id , + u.name as login, + u.email as email, + count(act_user_id) as contributions + from action a + left join user u on a.act_user_id=u.id + where repo_id=? and user_id=? + group by repo_id,act_user_id ` + + err = db.GetEngine(db.DefaultContext).SQL(sql, repoID, userID).Find(&result) + return +} diff --git a/routers/hat/hat.go b/routers/hat/hat.go index 9ac5231..63dc604 100644 --- a/routers/hat/hat.go +++ b/routers/hat/hat.go @@ -94,6 +94,9 @@ func Routers() *web.Route { m.Group("/releases", func() { m.Get("/latest", context.ReferencesGitRepo(), repo.GetLatestRelease) }, reqRepoReader(unit.TypeReleases)) + m.Group("/contributors", func() { + m.Get("", repo.GetContributors) + }) }, repoAssignment()) }) m.Post("/orgs", reqToken(), bind(gitea_api.CreateOrgOption{}), org.Create) diff --git a/routers/hat/repo/repo.go b/routers/hat/repo/repo.go index 176ea57..5a401ec 100644 --- a/routers/hat/repo/repo.go +++ b/routers/hat/repo/repo.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/gitdiff" + hat_models "code.gitlink.org.cn/Gitlink/gitea_hat.git/models" ) func PrepareComapreDiff( @@ -478,3 +479,13 @@ func SetDiffViewStyle(ctx *context.Context) { ctx.ServerError("ErrUpdateDiffViewStyle", err) } } + +func GetContributors(ctx *context.APIContext) { + list, err := hat_models.GetContributors(ctx.Repo.Repository.ID, ctx.Repo.Owner.ID) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetContributors", err) + return + } + + ctx.JSON(http.StatusOK, list) +}