Merge pull request '在pulls/{index}接口添加字段' (#31) from wonderful/gitea-1120-rc1:fix_pulls into develop
This commit is contained in:
commit
e9a6a54229
|
@ -65,6 +65,10 @@ type PullRequest struct {
|
|||
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
|
||||
|
||||
isHeadRepoLoaded bool `xorm:"-"`
|
||||
|
||||
//add configure
|
||||
CommitNum int
|
||||
ChangedFiles int
|
||||
}
|
||||
|
||||
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
||||
|
|
|
@ -42,28 +42,29 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
|||
}
|
||||
|
||||
apiPullRequest := &api.PullRequest{
|
||||
ID: pr.ID,
|
||||
URL: pr.Issue.HTMLURL(),
|
||||
Index: pr.Index,
|
||||
Poster: apiIssue.Poster,
|
||||
Title: apiIssue.Title,
|
||||
Body: apiIssue.Body,
|
||||
Labels: apiIssue.Labels,
|
||||
Milestone: apiIssue.Milestone,
|
||||
Assignee: apiIssue.Assignee,
|
||||
Assignees: apiIssue.Assignees,
|
||||
State: apiIssue.State,
|
||||
IsLocked: apiIssue.IsLocked,
|
||||
Comments: apiIssue.Comments,
|
||||
HTMLURL: pr.Issue.HTMLURL(),
|
||||
DiffURL: pr.Issue.DiffURL(),
|
||||
PatchURL: pr.Issue.PatchURL(),
|
||||
HasMerged: pr.HasMerged,
|
||||
MergeBase: pr.MergeBase,
|
||||
Deadline: apiIssue.Deadline,
|
||||
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
||||
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
||||
|
||||
ID: pr.ID,
|
||||
URL: pr.Issue.HTMLURL(),
|
||||
Index: pr.Index,
|
||||
Poster: apiIssue.Poster,
|
||||
Title: apiIssue.Title,
|
||||
Body: apiIssue.Body,
|
||||
Labels: apiIssue.Labels,
|
||||
Milestone: apiIssue.Milestone,
|
||||
Assignee: apiIssue.Assignee,
|
||||
Assignees: apiIssue.Assignees,
|
||||
State: apiIssue.State,
|
||||
IsLocked: apiIssue.IsLocked,
|
||||
Comments: apiIssue.Comments,
|
||||
CommitNum: pr.CommitNum,
|
||||
ChangedFiles: pr.ChangedFiles,
|
||||
HTMLURL: pr.Issue.HTMLURL(),
|
||||
DiffURL: pr.Issue.DiffURL(),
|
||||
PatchURL: pr.Issue.PatchURL(),
|
||||
HasMerged: pr.HasMerged,
|
||||
MergeBase: pr.MergeBase,
|
||||
Deadline: apiIssue.Deadline,
|
||||
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
||||
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
||||
Base: &api.PRBranchInfo{
|
||||
Name: pr.BaseBranch,
|
||||
Ref: pr.BaseBranch,
|
||||
|
|
|
@ -10,19 +10,21 @@ import (
|
|||
|
||||
// PullRequest represents a pull request
|
||||
type PullRequest struct {
|
||||
ID int64 `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Index int64 `json:"number"`
|
||||
Poster *User `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []*Label `json:"labels"`
|
||||
Milestone *Milestone `json:"milestone"`
|
||||
Assignee *User `json:"assignee"`
|
||||
Assignees []*User `json:"assignees"`
|
||||
State StateType `json:"state"`
|
||||
IsLocked bool `json:"is_locked"`
|
||||
Comments int `json:"comments"`
|
||||
ID int64 `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Index int64 `json:"number"`
|
||||
Poster *User `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []*Label `json:"labels"`
|
||||
Milestone *Milestone `json:"milestone"`
|
||||
Assignee *User `json:"assignee"`
|
||||
Assignees []*User `json:"assignees"`
|
||||
State StateType `json:"state"`
|
||||
IsLocked bool `json:"is_locked"`
|
||||
Comments int `json:"comments"`
|
||||
CommitNum int `json:"commit_num"`
|
||||
ChangedFiles int `json:"changed_files"`
|
||||
|
||||
HTMLURL string `json:"html_url"`
|
||||
DiffURL string `json:"diff_url"`
|
||||
|
|
|
@ -169,6 +169,72 @@ func GetPullRequest(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
return
|
||||
}
|
||||
issue := checkPullInfo(ctx.Context)
|
||||
if issue == nil {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
pull := issue.PullRequest
|
||||
// get pull commits nums
|
||||
var commits *list.List
|
||||
var prInfo *git.CompareInfo
|
||||
if pull.HasMerged {
|
||||
prInfo = PrepareMergedViewPullInfo(ctx.Context, issue)
|
||||
} else {
|
||||
prInfo = PrepareViewPullInfo(ctx.Context, issue)
|
||||
}
|
||||
|
||||
if ctx.Written() {
|
||||
return
|
||||
} else if prInfo == nil {
|
||||
ctx.NotFound("ViewPullCommits", nil)
|
||||
return
|
||||
}
|
||||
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 *git.Repository
|
||||
)
|
||||
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
|
||||
whitespaceFlags := map[string]string{
|
||||
"ignore-all": "-w",
|
||||
"ignore-change": "-b",
|
||||
"ignore-eol": "--ignore-space-at-eol",
|
||||
"": ""}
|
||||
|
||||
ctx.Data["WhitespaceBehavior"] = ""
|
||||
|
||||
diff, err1 := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath, startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
|
||||
whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
|
||||
if err1 != nil {
|
||||
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err1)
|
||||
return
|
||||
}
|
||||
var changedFiles int
|
||||
changedFiles = diff.NumFiles
|
||||
pr.CommitNum = commitNum
|
||||
pr.ChangedFiles = changedFiles
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue