Skip to content

Commit f0c640c

Browse files
Use GetDiffShortStat to obtain diff changes. Add descriptive comments.
1 parent 65241f0 commit f0c640c

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

models/issues/pull.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,11 @@ func (pr *PullRequest) GetGitHeadBranchRefName() string {
448448
return fmt.Sprintf("%s%s", git.BranchPrefix, pr.HeadBranch)
449449
}
450450

451+
// 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)
451452
func (pr *PullRequest) GetReviewCommentsCount(ctx context.Context) int {
452453
opts := FindCommentsOptions{
453-
Type: CommentTypeReview,
454-
IssueID: pr.IssueID,
454+
Type: CommentTypeReview,
455+
IssueID: pr.IssueID,
455456
}
456457
conds := opts.ToConds()
457458
if pr.ID == 0 {

modules/structs/pull.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ type PullRequest struct {
2424
Draft bool `json:"draft"`
2525
IsLocked bool `json:"is_locked"`
2626
Comments int `json:"comments"`
27-
ReviewComments int `json:"review_comments"`
28-
Additions int `json:"additions"`
29-
Deletions int `json:"deletions"`
30-
ChangedFiles int `json:"changed_files"`
27+
// number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)
28+
ReviewComments int `json:"review_comments"`
29+
Additions int `json:"additions"`
30+
Deletions int `json:"deletions"`
31+
ChangedFiles int `json:"changed_files"`
3132

3233
HTMLURL string `json:"html_url"`
3334
DiffURL string `json:"diff_url"`

services/convert/pull.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/git"
1515
"code.gitea.io/gitea/modules/log"
16-
"code.gitea.io/gitea/modules/setting"
1716
api "code.gitea.io/gitea/modules/structs"
18-
"code.gitea.io/gitea/services/gitdiff"
1917
)
2018

2119
// 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
203201
// Calculate diff
204202
startCommitID = pr.MergeBase
205203

206-
// FIXME: If there are too many files in the repo, may cause some unpredictable issues.
207-
diff, err := gitdiff.GetDiff(ctx, gitRepo,
208-
&gitdiff.DiffOptions{
209-
BeforeCommitID: startCommitID,
210-
AfterCommitID: endCommitID,
211-
MaxLines: setting.Git.MaxGitDiffLines,
212-
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
213-
MaxFiles: -1, // GetDiff() will return all files
214-
WhitespaceBehavior: gitdiff.GetWhitespaceFlag("show-all"),
215-
})
204+
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
216205
if err != nil {
217-
log.Error("GetDiff: %v", err)
206+
log.Error("GetDiffShortStat: %v", err)
218207
return nil
219208
}
220-
221-
apiPullRequest.Additions = diff.TotalAddition
222-
apiPullRequest.Deletions = diff.TotalDeletion
223-
apiPullRequest.ChangedFiles = diff.NumFiles
224209
}
225210

226211
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {

0 commit comments

Comments
 (0)