forked from Gitlink/gitea_hat
新增:获取仓库贡献度
This commit is contained in:
parent
717da8233f
commit
751f11ca09
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue