add:modif and add five api

This commit is contained in:
hang 2021-11-24 15:28:01 +08:00
parent e9fffd74e4
commit 05a30b4a41
6 changed files with 269 additions and 0 deletions

4
linux.bat Normal file
View File

@ -0,0 +1,4 @@
set go111module=on
set GOOS=linux
set GOARCH=amd64
go build -tags='bindata' -o release\linux\gitea

5
mac.bat Normal file
View File

@ -0,0 +1,5 @@
set go111module=on
SET GOOS=darwin
SET GOARCH=amd64
go build -tags='bindata' -o release\mac\gitea

18
options/license/PHengLEI Normal file
View File

@ -0,0 +1,18 @@
本协议是您(如下也称"用户")与中国空气动力研究与发展中心(以下简称"中心"关于国家数值风洞NNW"风雷PHengLEI"软件的协议,请认真阅读.
1. 申请者不得私自以拷贝、刻录等方式向第三者(包括同一单位内的其他人员)传播。所有用户均需填写本协议,向中心申请并获授权后方能免费获取.
2. 用户可以在"风雷PHengLEI"软件上添加、修改源代码,有权提出软件的使用反馈及意见,用户可以发表软件的使用体验及感受,但不得随意诽谤、中伤.
3. 用户享有其开发代码的知识产权。鼓励将开发成果返回至开发团队,或在"风雷PHengLEI"软件中开源,开发者将在代码中署名.
4. 若该软件被申请人用于学术研究,则相关论文成果中应引用国家数值风洞"风雷PHengLEI"软件; 若用于其它用途,需在显要处标注基于"风雷PHengLEI"软件开发.
5. 一旦申请使用本软件,即表示同意接受协议各项条件的约束。如果您不同意协议的条件,则不能获得使用本软件的权利.
6. "风雷PHengLEI"软件由中心开发,一切知识产权,以及与软件相关的所有信息内容,包括但不限于:文字表述及其组合、图标、图饰、图表、色彩、版面框架、有关数据、印刷材料、或电子文档等均受《中华人民共和国著作权法》、《中华人民共和国计算机软件保护条例》、《中华人民共和国商标法》、《中华人民共和国专利法》、反不正当竞争法和相应的国际条约以及其他知识产权法律法规的保护,除涉及第三方授权的软件或技术外,中心享有上述知识产权.
7. 您获得的只是本软件的使用权。本软件仅限中华人民共和国公民申请使用.
8. 本协议的最终解释权归中心.

View File

@ -746,6 +746,22 @@ func Routes() *web.Route {
Delete(repo.DeleteGitHook)
})
}, reqToken(), reqAdmin(), reqGitHook(), context.ReferencesGitRepo(true))
m.Group("/commits/count", func() {
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.GetCommitsCount)
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.GetCommitsCount)
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.GetCommitsCount)
})
m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.GetPullCommits)
m.Get("/files", context.RepoRef(), repo.GetPullFiles)
m.Get("/issues", context.RepoRef(), repo.GetPullIssues)
})
// m.Get("/compare/*", context.RepoAssignment(), repo.MustBeNotEmpty, reqRepoCodeReader,
// repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff)
// m.Get("/src/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.GetFileContents)
//end by coder
m.Group("/hooks", func() {
m.Combo("").Get(repo.ListHooks).
Post(bind(api.CreateHookOption{}), repo.CreateHook)

View File

@ -380,3 +380,19 @@ func CommitSplitSlice(CommitsList []api.Commit) []api.CommitsSlice {
}
return Commits
}
// 获取某一个分支或标签的 commits 数量
func GetCommitsCount(ctx *context.APIContext) {
var err error
// ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
// if err != nil {
// ctx.ServerError("GetBranchCommit", err)
// return
// }
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
if err != nil {
ctx.ServerError("GetCommitsCount", err)
return
}
ctx.JSON(http.StatusOK, &ctx.Repo)
}

View File

@ -1331,3 +1331,213 @@ func GetPullRequestCommits(ctx *context.APIContext) {
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, X-PerPage, X-Total, X-PageCount, X-HasMore, Link")
ctx.JSON(http.StatusOK, &apiCommits)
}
func GetPullCommits(ctx *context.APIContext) {
// issue := checkPullInfo(ctx.Context)
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
issue := pr.Issue
if issue == nil {
ctx.NotFound()
return
}
if ctx.Written() {
return
}
pull := issue.PullRequest
var commits *list.List
var prInfo *git.CompareInfo
if pull.HasMerged {
prInfo = pull_prepare.PrepareMergedViewPullInfo(ctx.Context, issue)
} else {
prInfo = pull_prepare.PrepareViewPullInfo(ctx.Context, issue)
}
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullCommits", nil)
return
}
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
var commitNum int
commits = prInfo.Commits
commits = models.ValidateCommitsWithEmails(commits)
commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
commitNum = commits.Len()
//get pull changedfils
var (
// diffRepoPath string
startCommitID string
endCommitID string
gitRepo = ctx.Repo.GitRepo
)
gitRepo = ctx.Repo.GitRepo
headCommitId, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
}
startCommitID = prInfo.MergeBase
endCommitID = headCommitId
ctx.Data["WhitespaceBehavior"] = ""
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo,
startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
if err != nil {
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
return
}
var changedFiles int
changedFiles = diff.NumFiles
pr.CommitNum = commitNum
pr.ChangedFiles = changedFiles
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr, ctx.User))
}
func GetPullFiles(ctx *context.APIContext) {
issue := checkPullInfo(ctx.Context)
if issue == nil {
ctx.NotFound()
return
}
if ctx.Written() {
return
}
pull := issue.PullRequest
whitespaceFlags := map[string]string{
"ignore-all": "-w",
"ignore-change": "-b",
"ignore-eol": "--ignore-space-at-eol",
"": ""}
var (
// diffRepoPath string
startCommitID string
endCommitID string
gitRepo *git.Repository
)
var prInfo *git.CompareInfo
if pull.HasMerged {
prInfo = pull_prepare.PrepareMergedViewPullInfo(ctx.Context, issue)
} else {
prInfo = pull_prepare.PrepareViewPullInfo(ctx.Context, issue)
}
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullFiles", nil)
return
}
// diffRepoPath = ctx.Repo.GitRepo.Path
gitRepo = ctx.Repo.GitRepo
headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
}
startCommitID = prInfo.MergeBase
endCommitID = headCommitID
ctx.Data["WhitespaceBehavior"] = ""
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(ctx.Repo.GitRepo,
startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
if err != nil {
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
return
}
if err = diff.LoadComments(issue, ctx.User); err != nil {
ctx.ServerError("LoadComments", err)
return
}
fileDiff := struct {
*gitdiff.Diff
LatestSha string
}{
Diff: diff,
LatestSha: endCommitID,
}
ctx.JSON(200, fileDiff)
}
func checkPullInfo(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
// if models.IsErrIssueNotExist(err) {
// ctx.NotFound("GetIssueByIndex", err)
// } else {
// ctx.ServerError("GetIssueByIndex", err)
// }
return nil
}
if err = issue.LoadPoster(); err != nil {
// ctx.ServerError("LoadPoster", err)
return nil
}
if err := issue.LoadRepo(); err != nil {
// ctx.ServerError("LoadRepo", err)
return nil
}
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
ctx.Data["Issue"] = issue
if !issue.IsPull {
// ctx.NotFound("ViewPullCommits", nil)
return nil
}
if err = issue.LoadPullRequest(); err != nil {
// ctx.ServerError("LoadPullRequest", err)
return nil
}
if err = issue.PullRequest.LoadHeadRepo(); err != nil {
// ctx.ServerError("LoadHeadRepo", err)
return nil
}
if ctx.IsSigned {
// Update issue-user.
if err = issue.ReadBy(ctx.User.ID); err != nil {
// ctx.ServerError("ReadBy", err)
return nil
}
}
return issue
}
func GetPullIssues(ctx *context.APIContext) {
issue := checkPullInfo(ctx.Context)
if issue == nil {
ctx.NotFound()
return
}
if ctx.Written() {
return
}
dependencies, err := issue.BlockingDependencies()
if err != nil {
ctx.ServerError("BlockingDependencies", err)
return
}
ctx.JSON(200, dependencies)
}