forked from Gitlink/gitea_hat
Compare commits
6 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d70d74a2ae | |
|
|
f513d462e5 | |
|
|
c1d4bdbab0 | |
|
|
9614d81c9a | |
|
|
357d28a2c9 | |
|
|
3e2d43ab77 |
|
|
@ -10,31 +10,68 @@ trigger:
|
|||
ruleset:
|
||||
- param-ref: branch
|
||||
operator: EQ
|
||||
value: '"develop"'
|
||||
value: '"feature"'
|
||||
ruleset-operator: AND
|
||||
workflow:
|
||||
- ref: start
|
||||
name: 开始
|
||||
task: start
|
||||
- ref: ssh_cmd_0
|
||||
name: ssh执行命令
|
||||
task: ssh_cmd@1.1.0
|
||||
- ref: git_clone_0
|
||||
name: git clone
|
||||
on-failure: ignore
|
||||
task: git_clone@1.2.6
|
||||
input:
|
||||
ssh_private_key: ((ssh.siyao))
|
||||
ssh_ip: '"123.59.135.93"'
|
||||
ssh_port: '"51123"'
|
||||
ssh_user: '"pdl"'
|
||||
ssh_cmd: '"ssh root@10.9.69.134 -p30122 \"
|
||||
cd /root
|
||||
&&
|
||||
sh ./update.sh
|
||||
&&
|
||||
echo done \""'
|
||||
remote_url: '"https://gitlink.org.cn/Gitlink/gitea_hat.git"'
|
||||
ref: '"refs/heads/feature"'
|
||||
commit_id: '""'
|
||||
depth: 1
|
||||
needs:
|
||||
- start
|
||||
- ref: golang_build_node_0
|
||||
name: golang_build_node
|
||||
on-failure: ignore
|
||||
task: yystopf/golang_build_node@0.0.2
|
||||
input:
|
||||
workspace: git_clone_0.git_path
|
||||
out_bin_name: '"gitea"'
|
||||
goos: '"linux"'
|
||||
goarch: '"amd64"'
|
||||
needs:
|
||||
- git_clone_0
|
||||
- ref: gitlink_scp_resource_0
|
||||
name: scp复制文件(支持跳板机)
|
||||
on-failure: ignore
|
||||
task: yystopf/gitlink_scp_resource@0.0.7
|
||||
input:
|
||||
ssh_private_key: ((ssh.siyao))
|
||||
remote_host: '"10.9.69.134"'
|
||||
remote_port: '"30122"'
|
||||
remote_user: '"root"'
|
||||
remote_file: '"/root/gitea"'
|
||||
local_file: golang_build_node_0.bin_dir
|
||||
gateway_host: '"123.59.135.93"'
|
||||
gateway_port: '"51123"'
|
||||
gateway_user: '"pdl"'
|
||||
temp_file: '"/home/pdl/gitea"'
|
||||
needs:
|
||||
- golang_build_node_0
|
||||
- ref: gitlink_ssh_cmd_0
|
||||
name: ssh执行命令(支持跳板机)
|
||||
task: yystopf/gitlink_ssh_cmd@0.0.6
|
||||
input:
|
||||
ssh_private_key: ((ssh.siyao))
|
||||
remote_host: '"10.9.69.134"'
|
||||
remote_port: '"30122"'
|
||||
remote_user: '"root"'
|
||||
gateway_host: '"123.59.135.93"'
|
||||
gateway_port: '"51123"'
|
||||
gateway_user: '"pdl"'
|
||||
ssh_cmd: '"sh update.sh"'
|
||||
needs:
|
||||
- gitlink_scp_resource_0
|
||||
- ref: end
|
||||
name: 结束
|
||||
task: end
|
||||
needs:
|
||||
- ssh_cmd_0
|
||||
- gitlink_ssh_cmd_0
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
gitea_git "code.gitea.io/gitea/modules/git"
|
||||
|
|
@ -145,11 +146,12 @@ func GetCodeActivityStatsWithoutSince(repo *gitea_git.Repository, branch string)
|
|||
}
|
||||
|
||||
// GetCodeActivityStats returns code statistics for activity page
|
||||
func GetPaginateCodeAuthorsWithoutSince(repo *gitea_git.Repository, branch string, page, pageSize int) (int64, []*CodeActivityAuthor, error) {
|
||||
func GetPaginateCodeAuthors(repo *gitea_git.Repository, fromTime time.Time, branch string, page, pageSize int) (int64, []*CodeActivityAuthor, error) {
|
||||
var total int64
|
||||
var authors []*CodeActivityAuthor
|
||||
since := fromTime.Format(time.RFC3339)
|
||||
|
||||
authorCmd := gitea_git.NewCommand(repo.Ctx, "log", "--no-merges", "--format=%aN <%aE>", "--date=iso")
|
||||
authorCmd := gitea_git.NewCommand(repo.Ctx, "log", "--no-merges", "--format=%aN <%aE>", "--date=iso", gitea_git.CmdArg(fmt.Sprintf("--since='%s'", since)))
|
||||
if len(branch) == 0 {
|
||||
authorCmd.AddArguments("--branches=*")
|
||||
} else {
|
||||
|
|
@ -199,7 +201,7 @@ func GetPaginateCodeAuthorsWithoutSince(repo *gitea_git.Repository, branch strin
|
|||
_ = stdoutReader.Close()
|
||||
_ = stdoutWriter.Close()
|
||||
}()
|
||||
gitCmd := gitea_git.NewCommand(repo.Ctx, "log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso", gitea_git.CmdArg(fmt.Sprintf("--author=%s", filterAuthor)))
|
||||
gitCmd := gitea_git.NewCommand(repo.Ctx, "log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso", gitea_git.CmdArg(fmt.Sprintf("--author=%s", filterAuthor)), gitea_git.CmdArg(fmt.Sprintf("--since='%s'", since)))
|
||||
if len(branch) == 0 {
|
||||
gitCmd.AddArguments("--branches=*")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ func Routers(ctx gocontext.Context) *web.Route {
|
|||
}, reqRepoReader(unit.TypeReleases))
|
||||
m.Group("/contributors", func() {
|
||||
m.Get("", context.ReferencesGitRepo(), repo.GetContributors)
|
||||
m.Get("/stat", context.ReferencesGitRepo(), repo.GetContributorStat)
|
||||
})
|
||||
m.Group("/count", func() {
|
||||
m.Get("", context.ReferencesGitRepo(), repo.GetCommitCount)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
|
|
@ -498,6 +499,31 @@ func GetContributors(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, list)
|
||||
}
|
||||
|
||||
func GetContributorStat(ctx *context.APIContext) {
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
ref := ctx.FormString("ref")
|
||||
year := ctx.FormInt("pass_year")
|
||||
var timeFrom time.Time = time.Now().AddDate(-1, 0, 0) // 默认近一年
|
||||
|
||||
if year > 0 {
|
||||
timeFrom = time.Now().AddDate(-year, 0, 0) // 近几年
|
||||
}
|
||||
|
||||
total, list, err := hat_git.GetPaginateCodeAuthors(ctx.Repo.GitRepo, timeFrom, ref, listOptions.Page, listOptions.PageSize)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetPaginateCodeAuthors", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(total), listOptions.PageSize)
|
||||
ctx.RespHeader().Set("X-Total", fmt.Sprintf("%d", total))
|
||||
ctx.RespHeader().Set("X-Total-Count", fmt.Sprintf("%d", total))
|
||||
ctx.RespHeader().Set("Access-Control-Expose-Headers", "X-Total-Count, Link, X-Total")
|
||||
|
||||
ctx.JSON(http.StatusOK, list)
|
||||
}
|
||||
|
||||
type CountDTO struct {
|
||||
Branch CountDTOBranch `json:"branch"`
|
||||
ReleaseCount int64 `json:"release_count"`
|
||||
|
|
|
|||
Loading…
Reference in New Issue