forked from Gitlink/gitea-1120-rc1
fix pulls/{index}
This commit is contained in:
parent
de0f7764c7
commit
a6ac790d1a
|
@ -65,6 +65,10 @@ type PullRequest struct {
|
||||||
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
|
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
|
||||||
|
|
||||||
isHeadRepoLoaded bool `xorm:"-"`
|
isHeadRepoLoaded bool `xorm:"-"`
|
||||||
|
|
||||||
|
//add configure
|
||||||
|
CommitNum int
|
||||||
|
ChangedFiles int
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
||||||
|
|
|
@ -42,28 +42,29 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
apiPullRequest := &api.PullRequest{
|
apiPullRequest := &api.PullRequest{
|
||||||
ID: pr.ID,
|
ID: pr.ID,
|
||||||
URL: pr.Issue.HTMLURL(),
|
URL: pr.Issue.HTMLURL(),
|
||||||
Index: pr.Index,
|
Index: pr.Index,
|
||||||
Poster: apiIssue.Poster,
|
Poster: apiIssue.Poster,
|
||||||
Title: apiIssue.Title,
|
Title: apiIssue.Title,
|
||||||
Body: apiIssue.Body,
|
Body: apiIssue.Body,
|
||||||
Labels: apiIssue.Labels,
|
Labels: apiIssue.Labels,
|
||||||
Milestone: apiIssue.Milestone,
|
Milestone: apiIssue.Milestone,
|
||||||
Assignee: apiIssue.Assignee,
|
Assignee: apiIssue.Assignee,
|
||||||
Assignees: apiIssue.Assignees,
|
Assignees: apiIssue.Assignees,
|
||||||
State: apiIssue.State,
|
State: apiIssue.State,
|
||||||
IsLocked: apiIssue.IsLocked,
|
IsLocked: apiIssue.IsLocked,
|
||||||
Comments: apiIssue.Comments,
|
Comments: apiIssue.Comments,
|
||||||
HTMLURL: pr.Issue.HTMLURL(),
|
CommitNum: pr.CommitNum,
|
||||||
DiffURL: pr.Issue.DiffURL(),
|
ChangedFiles: pr.ChangedFiles,
|
||||||
PatchURL: pr.Issue.PatchURL(),
|
HTMLURL: pr.Issue.HTMLURL(),
|
||||||
HasMerged: pr.HasMerged,
|
DiffURL: pr.Issue.DiffURL(),
|
||||||
MergeBase: pr.MergeBase,
|
PatchURL: pr.Issue.PatchURL(),
|
||||||
Deadline: apiIssue.Deadline,
|
HasMerged: pr.HasMerged,
|
||||||
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
MergeBase: pr.MergeBase,
|
||||||
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
Deadline: apiIssue.Deadline,
|
||||||
|
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
||||||
|
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
||||||
Base: &api.PRBranchInfo{
|
Base: &api.PRBranchInfo{
|
||||||
Name: pr.BaseBranch,
|
Name: pr.BaseBranch,
|
||||||
Ref: pr.BaseBranch,
|
Ref: pr.BaseBranch,
|
||||||
|
|
|
@ -10,19 +10,21 @@ import (
|
||||||
|
|
||||||
// PullRequest represents a pull request
|
// PullRequest represents a pull request
|
||||||
type PullRequest struct {
|
type PullRequest struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Index int64 `json:"number"`
|
Index int64 `json:"number"`
|
||||||
Poster *User `json:"user"`
|
Poster *User `json:"user"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
Assignee *User `json:"assignee"`
|
Assignee *User `json:"assignee"`
|
||||||
Assignees []*User `json:"assignees"`
|
Assignees []*User `json:"assignees"`
|
||||||
State StateType `json:"state"`
|
State StateType `json:"state"`
|
||||||
IsLocked bool `json:"is_locked"`
|
IsLocked bool `json:"is_locked"`
|
||||||
Comments int `json:"comments"`
|
Comments int `json:"comments"`
|
||||||
|
CommitNum int `json:"commit_num"`
|
||||||
|
ChangedFiles int `json:"changed_files"`
|
||||||
|
|
||||||
HTMLURL string `json:"html_url"`
|
HTMLURL string `json:"html_url"`
|
||||||
DiffURL string `json:"diff_url"`
|
DiffURL string `json:"diff_url"`
|
||||||
|
|
|
@ -169,6 +169,72 @@ func GetPullRequest(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||||
return
|
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))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue