}
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,
- Mergeable: pr.Mergeable(ctx),
- Deadline: apiIssue.Deadline,
- Created: pr.Issue.CreatedUnix.AsTimePtr(),
- Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
- PinOrder: apiIssue.PinOrder,
+ 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,
+ Draft: pr.IsWorkInProgress(ctx),
+ IsLocked: apiIssue.IsLocked,
+ Comments: apiIssue.Comments,
+ ReviewComments: pr.GetReviewCommentsCount(ctx),
+ HTMLURL: pr.Issue.HTMLURL(),
+ DiffURL: pr.Issue.DiffURL(),
+ PatchURL: pr.Issue.PatchURL(),
+ HasMerged: pr.HasMerged,
+ MergeBase: pr.MergeBase,
+ Mergeable: pr.Mergeable(ctx),
+ Deadline: apiIssue.Deadline,
+ Created: pr.Issue.CreatedUnix.AsTimePtr(),
+ Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
+ PinOrder: apiIssue.PinOrder,
AllowMaintainerEdit: pr.AllowMaintainerEdit,
return nil
}
+ // Outer scope variables to be used in diff calculation
+ var (
+ startCommitID string
+ endCommitID string
+ )
+
if git.IsErrBranchNotExist(err) {
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
if err != nil && !git.IsErrNotExist(err) {
}
if err == nil {
apiPullRequest.Head.Sha = headCommitID
+ endCommitID = headCommitID
}
} else {
commit, err := headBranch.GetCommit()
if err == nil {
apiPullRequest.Head.Ref = pr.HeadBranch
apiPullRequest.Head.Sha = commit.ID.String()
+ endCommitID = commit.ID.String()
}
}
+
+ // Calculate diff
+ startCommitID = pr.MergeBase
+
+ apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
+ if err != nil {
+ log.Error("GetDiffShortStat: %v", err)
+ }
}
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
"description": "PullRequest represents a pull request",
"type": "object",
"properties": {
+ "additions": {
+ "type": "integer",
+ "format": "int64",
+ "x-go-name": "Additions"
+ },
"allow_maintainer_edit": {
"type": "boolean",
"x-go-name": "AllowMaintainerEdit"
"type": "string",
"x-go-name": "Body"
},
+ "changed_files": {
+ "type": "integer",
+ "format": "int64",
+ "x-go-name": "ChangedFiles"
+ },
"closed_at": {
"type": "string",
"format": "date-time",
"format": "date-time",
"x-go-name": "Created"
},
+ "deletions": {
+ "type": "integer",
+ "format": "int64",
+ "x-go-name": "Deletions"
+ },
"diff_url": {
"type": "string",
"x-go-name": "DiffURL"
},
+ "draft": {
+ "type": "boolean",
+ "x-go-name": "Draft"
+ },
"due_date": {
"type": "string",
"format": "date-time",
},
"x-go-name": "RequestedReviewers"
},
+ "review_comments": {
+ "description": "number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)",
+ "type": "integer",
+ "format": "int64",
+ "x-go-name": "ReviewComments"
+ },
"state": {
"$ref": "#/definitions/StateType"
},
"type": "boolean",
"x-go-name": "IsWorkInProgress"
},
+ "html_url": {
+ "type": "string",
+ "x-go-name": "HTMLURL"
+ },
"merged": {
"type": "boolean",
"x-go-name": "HasMerged"
"type": "string",
"x-go-name": "FullName"
},
+ "html_url": {
+ "description": "URL to the user's gitea page",
+ "type": "string",
+ "x-go-name": "HTMLURL"
+ },
"id": {
"description": "the user's id",
"type": "integer",