添加接口:pulls/indext/files #41

Merged
yystopf merged 1 commits from wonderful/gitea-1156:develop into develop 2021-12-28 16:15:23 +08:00
2 changed files with 30 additions and 49 deletions

View File

@ -752,7 +752,7 @@ func Routes() *web.Route {
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.GetCommitsCount)
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.GetCommitsCount)
})
m.Group("/pulls/:index", func() {
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)
@ -967,7 +967,7 @@ func Routes() *web.Route {
m.Get(".diff", repo.DownloadPullDiff)
m.Get(".patch", repo.DownloadPullPatch)
m.Post("/update", reqToken(), repo.UpdatePullRequest)
m.Get("/commits", repo.GetPullRequestCommits)
// m.Get("/commits", repo.GetPullRequestCommits)
m.Combo("/merge").Get(repo.IsPullRequestMerged).
Post(reqToken(), mustNotBeArchived, bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
m.Group("/reviews", func() {

View File

@ -1332,10 +1332,13 @@ func GetPullRequestCommits(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, &apiCommits)
}
type PullRequestCommit struct {
models.SignCommitWithStatuses
Sha string
}
func GetPullCommits(ctx *context.APIContext) {
// issue := checkPullInfo(ctx.Context)
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
issue := pr.Issue
issue := checkPullInfo(ctx.Context)
if issue == nil {
ctx.NotFound()
return
@ -1362,63 +1365,41 @@ func GetPullCommits(ctx *context.APIContext) {
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
result := make([]PullRequestCommit, 0)
// result := make([]models.SignCommitWithStatuses, 0)
for commit := commits.Front(); commit != nil; commit = commit.Next() {
temp := commit.Value.(models.SignCommitWithStatuses)
pullRequestCommit := PullRequestCommit{
temp,
temp.ID.String(),
}
result = append(result, pullRequestCommit)
}
var changedFiles int
changedFiles = diff.NumFiles
pr.CommitNum = commitNum
pr.ChangedFiles = changedFiles
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr, ctx.User))
ctx.JSON(200, result)
}
func GetPullFiles(ctx *context.APIContext) {
issue := checkPullInfo(ctx.Context)
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
issue := pr.Issue
// issue := checkPullInfo(ctx.Context)
log.Info("issue %s", issue)
if issue == nil {
ctx.NotFound()
ctx.NotFound("checkPullInfo", nil)
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
// diffRepoPath
startCommitID string
endCommitID string
gitRepo *git.Repository
@ -1446,15 +1427,15 @@ func GetPullFiles(ctx *context.APIContext) {
ctx.ServerError("GetRefCommitID", err)
return
}
// diffRepoPath = ctx.Repo.GitRepo.Path
startCommitID = prInfo.MergeBase
endCommitID = headCommitID
ctx.Data["WhitespaceBehavior"] = ""
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(ctx.Repo.GitRepo,
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo,
startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
if err != nil {
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
return