Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
|
c9c2aac882 | |
|
e19cd0998e | |
|
987ac773f6 | |
|
52d9414a29 | |
|
6576006a78 | |
|
e9a6a54229 | |
|
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
|
||||||
|
|
|
@ -55,6 +55,8 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
||||||
State: apiIssue.State,
|
State: apiIssue.State,
|
||||||
IsLocked: apiIssue.IsLocked,
|
IsLocked: apiIssue.IsLocked,
|
||||||
Comments: apiIssue.Comments,
|
Comments: apiIssue.Comments,
|
||||||
|
CommitNum: pr.CommitNum,
|
||||||
|
ChangedFiles: pr.ChangedFiles,
|
||||||
HTMLURL: pr.Issue.HTMLURL(),
|
HTMLURL: pr.Issue.HTMLURL(),
|
||||||
DiffURL: pr.Issue.DiffURL(),
|
DiffURL: pr.Issue.DiffURL(),
|
||||||
PatchURL: pr.Issue.PatchURL(),
|
PatchURL: pr.Issue.PatchURL(),
|
||||||
|
@ -63,7 +65,6 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
||||||
Deadline: apiIssue.Deadline,
|
Deadline: apiIssue.Deadline,
|
||||||
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
||||||
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
||||||
|
|
||||||
Base: &api.PRBranchInfo{
|
Base: &api.PRBranchInfo{
|
||||||
Name: pr.BaseBranch,
|
Name: pr.BaseBranch,
|
||||||
Ref: pr.BaseBranch,
|
Ref: pr.BaseBranch,
|
||||||
|
|
|
@ -23,6 +23,8 @@ type PullRequest struct {
|
||||||
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"`
|
||||||
|
|
|
@ -8,6 +8,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//add
|
||||||
|
type RepoBranchAndTagCount struct {
|
||||||
|
BranchCount int `json:"branch_count"`
|
||||||
|
TagCount int `json:"tag_count"`
|
||||||
|
}
|
||||||
|
|
||||||
// Permission represents a set of permissions
|
// Permission represents a set of permissions
|
||||||
type Permission struct {
|
type Permission struct {
|
||||||
Admin bool `json:"admin"`
|
Admin bool `json:"admin"`
|
||||||
|
@ -230,6 +236,7 @@ type MigrateRepoOption struct {
|
||||||
CloneAddr string `json:"clone_addr" binding:"Required"`
|
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||||||
AuthUsername string `json:"auth_username"`
|
AuthUsername string `json:"auth_username"`
|
||||||
AuthPassword string `json:"auth_password"`
|
AuthPassword string `json:"auth_password"`
|
||||||
|
AuthToken string `json:"auth_token"`
|
||||||
// required: true
|
// required: true
|
||||||
UID int `json:"uid" binding:"Required"`
|
UID int `json:"uid" binding:"Required"`
|
||||||
// required: true
|
// required: true
|
||||||
|
|
|
@ -702,7 +702,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Get("/*", viewfile.ReadmeByPath) // reqRepoReader(models.UnitTypeCode),
|
m.Get("/*", viewfile.ReadmeByPath) // reqRepoReader(models.UnitTypeCode),
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/count", func() {
|
m.Group("/count", func() {
|
||||||
m.Get("", viewfile.CommitCount) //****
|
m.Get("", viewfile.CommitCount) //****
|
||||||
})
|
})
|
||||||
|
@ -717,7 +716,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Group("/contributors", func() {
|
m.Group("/contributors", func() {
|
||||||
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
|
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Combo("").Get(reqAnyRepoReader(), repo.Get).
|
m.Combo("").Get(reqAnyRepoReader(), repo.Get).
|
||||||
Delete(reqToken(), reqOwner(), repo.Delete).
|
Delete(reqToken(), reqOwner(), repo.Delete).
|
||||||
Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), context.RepoRef(), repo.Edit)
|
Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), context.RepoRef(), repo.Edit)
|
||||||
|
@ -725,7 +723,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Combo("/notifications").
|
m.Combo("/notifications").
|
||||||
Get(reqToken(), notify.ListRepoNotifications).
|
Get(reqToken(), notify.ListRepoNotifications).
|
||||||
Put(reqToken(), notify.ReadRepoNotifications)
|
Put(reqToken(), notify.ReadRepoNotifications)
|
||||||
|
|
||||||
m.Group("/wikies", func() {
|
m.Group("/wikies", func() {
|
||||||
m.Combo("").Get(repo.WikiList).
|
m.Combo("").Get(repo.WikiList).
|
||||||
Post(bind(api.WikiOption{}), repo.CreateWiki)
|
Post(bind(api.WikiOption{}), repo.CreateWiki)
|
||||||
|
@ -809,6 +806,9 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Group("/tags", func() {
|
m.Group("/tags", func() {
|
||||||
m.Get("", repo.ListTags)
|
m.Get("", repo.ListTags)
|
||||||
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
|
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
|
||||||
|
m.Group("/branch_tag_count", func() {
|
||||||
|
m.Get("", repo.GetRepoBranchAndTagCount)
|
||||||
|
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
|
||||||
m.Group("/keys", func() {
|
m.Group("/keys", func() {
|
||||||
m.Combo("").Get(repo.ListDeployKeys).
|
m.Combo("").Get(repo.ListDeployKeys).
|
||||||
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
|
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
|
||||||
|
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
)
|
)
|
||||||
|
@ -123,3 +124,43 @@ func GetTag(ctx *context.APIContext) {
|
||||||
ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx.Repo.Repository, tag, commit))
|
ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx.Repo.Repository, tag, commit))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetRepoBranchAndTagCount(ctx *context.APIContext) {
|
||||||
|
// swagger:operation GET /repos/{owner}/{repo}/branch_tag_count repository repoBranchAndTagCountGet
|
||||||
|
// ---
|
||||||
|
// summary: Get branche and tag of a repository
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// parameters:
|
||||||
|
// - name: owner
|
||||||
|
// in: path
|
||||||
|
// description: owner of the repo
|
||||||
|
// type: string
|
||||||
|
// required: true
|
||||||
|
// - name: repo
|
||||||
|
// in: path
|
||||||
|
// description: name of the repo
|
||||||
|
// type: string
|
||||||
|
// required: true
|
||||||
|
// responses:
|
||||||
|
// "200":
|
||||||
|
// "$ref": "#/responses/RepoBranchAndTagCount"
|
||||||
|
|
||||||
|
tags, err := ctx.Repo.GitRepo.GetTagInfos(0, 0)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetTags", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := ctx.Repo.Repository
|
||||||
|
branches, err := repo_module.GetBranches(repo)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("GetBranches", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result := api.RepoBranchAndTagCount{
|
||||||
|
BranchCount: len(branches),
|
||||||
|
TagCount: len(tags),
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, result)
|
||||||
|
}
|
||||||
|
|
|
@ -79,6 +79,13 @@ type swaggerResponseTag struct {
|
||||||
Body api.Tag `json:"body"`
|
Body api.Tag `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RepoBranchAndTagCount
|
||||||
|
// swagger:response RepoBranchAndTagCount
|
||||||
|
type swaggerResponseRepoBranchAndTagCount struct {
|
||||||
|
// in:body
|
||||||
|
Body api.RepoBranchAndTagCount `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
// AnnotatedTag
|
// AnnotatedTag
|
||||||
// swagger:response AnnotatedTag
|
// swagger:response AnnotatedTag
|
||||||
type swaggerResponseAnnotatedTag struct {
|
type swaggerResponseAnnotatedTag struct {
|
||||||
|
|
|
@ -2363,6 +2363,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": [
|
||||||
|
@ -14679,6 +14712,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",
|
||||||
|
@ -14689,6 +14727,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",
|
||||||
|
@ -15033,6 +15076,23 @@
|
||||||
},
|
},
|
||||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
},
|
},
|
||||||
|
"RepoBranchAndTagCount": {
|
||||||
|
"description": "add",
|
||||||
|
"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.",
|
||||||
|
@ -16399,6 +16459,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"RepoBranchAndTagCount": {
|
||||||
|
"description": "RepoBranchAndTagCount",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/RepoBranchAndTagCount"
|
||||||
|
}
|
||||||
|
},
|
||||||
"Repository": {
|
"Repository": {
|
||||||
"description": "Repository",
|
"description": "Repository",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
|
Loading…
Reference in New Issue