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"`
|
||||
|
||||
isHeadRepoLoaded bool `xorm:"-"`
|
||||
|
||||
// add configure
|
||||
CommitNum int
|
||||
ChangedFiles int
|
||||
}
|
||||
|
||||
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
||||
|
|
|
@ -61,6 +61,9 @@ func ToAPIPullRequest(pr *models.PullRequest, doer *models.User) *api.PullReques
|
|||
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(),
|
||||
|
|
|
@ -48,6 +48,9 @@ type PullRequest struct {
|
|||
Updated *time.Time `json:"updated_at"`
|
||||
// swagger:strfmt date-time
|
||||
Closed *time.Time `json:"closed_at"`
|
||||
|
||||
CommitNum int `json:"commit_num"`
|
||||
ChangedFiles int `json:"changed_files"`
|
||||
}
|
||||
|
||||
// PRBranchInfo information about a branch
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
@ -19,11 +20,15 @@ import (
|
|||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"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"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
|
@ -172,6 +177,68 @@ func GetPullRequest(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
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))
|
||||
}
|
||||
|
||||
|
|
|
@ -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": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -16235,6 +16268,11 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Body"
|
||||
},
|
||||
"changed_files": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "ChangedFiles"
|
||||
},
|
||||
"closed_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
|
@ -16245,6 +16283,11 @@
|
|||
"format": "int64",
|
||||
"x-go-name": "Comments"
|
||||
},
|
||||
"commit_num": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "CommitNum"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
|
@ -16616,6 +16659,22 @@
|
|||
},
|
||||
"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": {
|
||||
"type": "object",
|
||||
"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": {
|
||||
"description": "Repository",
|
||||
"schema": {
|
||||
|
|
Loading…
Reference in New Issue