diff --git a/models/issues/pull.go b/models/issues/pull.go index 3707f66bb9a0..0666edc1822b 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -430,10 +430,11 @@ func (pr *PullRequest) GetGitHeadBranchRefName() string { return fmt.Sprintf("%s%s", git.BranchPrefix, pr.HeadBranch) } +// GetReviewCommentsCount returns the number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR) func (pr *PullRequest) GetReviewCommentsCount(ctx context.Context) int { opts := FindCommentsOptions{ - Type: CommentTypeReview, - IssueID: pr.IssueID, + Type: CommentTypeReview, + IssueID: pr.IssueID, } conds := opts.ToConds() if pr.ID == 0 { diff --git a/modules/structs/pull.go b/modules/structs/pull.go index f6b498df009c..abf1df36fd3d 100644 --- a/modules/structs/pull.go +++ b/modules/structs/pull.go @@ -24,10 +24,11 @@ type PullRequest struct { Draft bool `json:"draft"` IsLocked bool `json:"is_locked"` Comments int `json:"comments"` - ReviewComments int `json:"review_comments"` - Additions int `json:"additions"` - Deletions int `json:"deletions"` - ChangedFiles int `json:"changed_files"` + // number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR) + ReviewComments int `json:"review_comments"` + Additions int `json:"additions"` + Deletions int `json:"deletions"` + ChangedFiles int `json:"changed_files"` HTMLURL string `json:"html_url"` DiffURL string `json:"diff_url"` diff --git a/services/convert/pull.go b/services/convert/pull.go index 06d879a6a871..d3679d26a9e3 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -13,9 +13,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/services/gitdiff" ) // ToAPIPullRequest assumes following fields have been assigned with valid values: @@ -203,24 +201,11 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u // Calculate diff startCommitID = pr.MergeBase - // FIXME: If there are too many files in the repo, may cause some unpredictable issues. - diff, err := gitdiff.GetDiff(ctx, gitRepo, - &gitdiff.DiffOptions{ - BeforeCommitID: startCommitID, - AfterCommitID: endCommitID, - MaxLines: setting.Git.MaxGitDiffLines, - MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, - MaxFiles: -1, // GetDiff() will return all files - WhitespaceBehavior: gitdiff.GetWhitespaceFlag("show-all"), - }) + apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID) if err != nil { - log.Error("GetDiff: %v", err) + log.Error("GetDiffShortStat: %v", err) return nil } - - apiPullRequest.Additions = diff.TotalAddition - apiPullRequest.Deletions = diff.TotalDeletion - apiPullRequest.ChangedFiles = diff.NumFiles } if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {