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"`
|
||||
|
||||
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"`
|
||||
|
|
|
@ -8,6 +8,12 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
//add
|
||||
type RepoBranchAndTagCount struct {
|
||||
BranchCount int `json:"branch_count"`
|
||||
TagCount int `json:"tag_count"`
|
||||
}
|
||||
|
||||
// Permission represents a set of permissions
|
||||
type Permission struct {
|
||||
Admin bool `json:"admin"`
|
||||
|
@ -230,6 +236,7 @@ type MigrateRepoOption struct {
|
|||
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||||
AuthUsername string `json:"auth_username"`
|
||||
AuthPassword string `json:"auth_password"`
|
||||
AuthToken string `json:"auth_token"`
|
||||
// required: true
|
||||
UID int `json:"uid" binding:"Required"`
|
||||
// required: true
|
||||
|
|
|
@ -702,7 +702,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Get("/*", viewfile.ReadmeByPath) // reqRepoReader(models.UnitTypeCode),
|
||||
|
||||
})
|
||||
|
||||
m.Group("/count", func() {
|
||||
m.Get("", viewfile.CommitCount) //****
|
||||
})
|
||||
|
@ -717,7 +716,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Group("/contributors", func() {
|
||||
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
|
||||
})
|
||||
|
||||
m.Combo("").Get(reqAnyRepoReader(), repo.Get).
|
||||
Delete(reqToken(), reqOwner(), repo.Delete).
|
||||
Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), context.RepoRef(), repo.Edit)
|
||||
|
@ -725,7 +723,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Combo("/notifications").
|
||||
Get(reqToken(), notify.ListRepoNotifications).
|
||||
Put(reqToken(), notify.ReadRepoNotifications)
|
||||
|
||||
m.Group("/wikies", func() {
|
||||
m.Combo("").Get(repo.WikiList).
|
||||
Post(bind(api.WikiOption{}), repo.CreateWiki)
|
||||
|
@ -809,6 +806,9 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Group("/tags", func() {
|
||||
m.Get("", repo.ListTags)
|
||||
}, 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.Combo("").Get(repo.ListDeployKeys).
|
||||
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"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))
|
||||
}
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
// RepoBranchAndTagCount
|
||||
// swagger:response RepoBranchAndTagCount
|
||||
type swaggerResponseRepoBranchAndTagCount struct {
|
||||
// in:body
|
||||
Body api.RepoBranchAndTagCount `json:"body"`
|
||||
}
|
||||
|
||||
// AnnotatedTag
|
||||
// swagger:response AnnotatedTag
|
||||
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": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -14679,6 +14712,11 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Body"
|
||||
},
|
||||
"changed_files": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "ChangedFiles"
|
||||
},
|
||||
"closed_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
|
@ -14689,6 +14727,11 @@
|
|||
"format": "int64",
|
||||
"x-go-name": "Comments"
|
||||
},
|
||||
"commit_num": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "CommitNum"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
|
@ -15033,6 +15076,23 @@
|
|||
},
|
||||
"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": {
|
||||
"type": "object",
|
||||
"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": {
|
||||
"description": "Repository",
|
||||
"schema": {
|
||||
|
@ -16724,4 +16790,4 @@
|
|||
"TOTPHeader": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue