forked from Gitlink/gitea-1156
fix: add count of commit and changedfiles of the pull
This commit is contained in:
parent
498cae0562
commit
3e44c82aea
|
@ -69,6 +69,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
|
||||||
|
|
|
@ -61,14 +61,17 @@ func ToAPIPullRequest(pr *models.PullRequest, doer *models.User) *api.PullReques
|
||||||
State: apiIssue.State,
|
State: apiIssue.State,
|
||||||
IsLocked: apiIssue.IsLocked,
|
IsLocked: apiIssue.IsLocked,
|
||||||
Comments: apiIssue.Comments,
|
Comments: apiIssue.Comments,
|
||||||
HTMLURL: pr.Issue.HTMLURL(),
|
|
||||||
DiffURL: pr.Issue.DiffURL(),
|
CommitNum: pr.CommitNum,
|
||||||
PatchURL: pr.Issue.PatchURL(),
|
ChangedFiles: pr.ChangedFiles,
|
||||||
HasMerged: pr.HasMerged,
|
HTMLURL: pr.Issue.HTMLURL(),
|
||||||
MergeBase: pr.MergeBase,
|
DiffURL: pr.Issue.DiffURL(),
|
||||||
Deadline: apiIssue.Deadline,
|
PatchURL: pr.Issue.PatchURL(),
|
||||||
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
HasMerged: pr.HasMerged,
|
||||||
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
MergeBase: pr.MergeBase,
|
||||||
|
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,
|
||||||
|
|
|
@ -48,6 +48,9 @@ type PullRequest struct {
|
||||||
Updated *time.Time `json:"updated_at"`
|
Updated *time.Time `json:"updated_at"`
|
||||||
// swagger:strfmt date-time
|
// swagger:strfmt date-time
|
||||||
Closed *time.Time `json:"closed_at"`
|
Closed *time.Time `json:"closed_at"`
|
||||||
|
|
||||||
|
CommitNum int `json:"commit_num"`
|
||||||
|
ChangedFiles int `json:"changed_files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRBranchInfo information about a branch
|
// PRBranchInfo information about a branch
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"container/list"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
@ -19,11 +20,15 @@ import (
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
|
"code.gitea.io/gitea/services/gitdiff"
|
||||||
|
|
||||||
|
pull_prepare "code.gitea.io/gitea/routers/web/repo"
|
||||||
issue_service "code.gitea.io/gitea/services/issue"
|
issue_service "code.gitea.io/gitea/services/issue"
|
||||||
pull_service "code.gitea.io/gitea/services/pull"
|
pull_service "code.gitea.io/gitea/services/pull"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
|
@ -172,6 +177,68 @@ func GetPullRequest(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue := checkPullInfo(ctx.Context)
|
||||||
|
issue := pr.Issue
|
||||||
|
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 = 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
|
||||||
|
}
|
||||||
|
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))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr, ctx.User))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2531,6 +2531,39 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/repos/{owner}/{repo}/branch_tag_count": {
|
||||||
|
"get": {
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"repository"
|
||||||
|
],
|
||||||
|
"summary": "Get branche and tag of a repository",
|
||||||
|
"operationId": "repoBranchAndTagCountGet",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "owner of the repo",
|
||||||
|
"name": "owner",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "name of the repo",
|
||||||
|
"name": "repo",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"$ref": "#/responses/RepoBranchAndTagCount"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/repos/{owner}/{repo}/branches": {
|
"/repos/{owner}/{repo}/branches": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
|
@ -16235,6 +16268,11 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "Body"
|
"x-go-name": "Body"
|
||||||
},
|
},
|
||||||
|
"changed_files": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"x-go-name": "ChangedFiles"
|
||||||
|
},
|
||||||
"closed_at": {
|
"closed_at": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
|
@ -16245,6 +16283,11 @@
|
||||||
"format": "int64",
|
"format": "int64",
|
||||||
"x-go-name": "Comments"
|
"x-go-name": "Comments"
|
||||||
},
|
},
|
||||||
|
"commit_num": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"x-go-name": "CommitNum"
|
||||||
|
},
|
||||||
"created_at": {
|
"created_at": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
|
@ -16616,6 +16659,22 @@
|
||||||
},
|
},
|
||||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
},
|
},
|
||||||
|
"RepoBranchAndTagCount": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"branch_count": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"x-go-name": "BranchCount"
|
||||||
|
},
|
||||||
|
"tag_count": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"x-go-name": "TagCount"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
|
},
|
||||||
"RepoCommit": {
|
"RepoCommit": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "RepoCommit contains information of a commit in the context of a repository.",
|
"title": "RepoCommit contains information of a commit in the context of a repository.",
|
||||||
|
@ -18111,6 +18170,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"RepoBranchAndTagCount": {
|
||||||
|
"description": "RepoBranchAndTagCount",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/RepoBranchAndTagCount"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"body": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"Repository": {
|
"Repository": {
|
||||||
"description": "Repository",
|
"description": "Repository",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
Loading…
Reference in New Issue