Skip to content

Commit 7386d4e

Browse files
committed
fix
1 parent 92f2d90 commit 7386d4e

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

modules/structs/pull.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ type PullRequest struct {
2727
Comments int `json:"comments"`
2828
// number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)
2929
ReviewComments int `json:"review_comments"`
30-
Additions int `json:"additions"`
31-
Deletions int `json:"deletions"`
32-
ChangedFiles int `json:"changed_files"`
30+
31+
Additions *int `json:"additions,omitempty"`
32+
Deletions *int `json:"deletions,omitempty"`
33+
ChangedFiles *int `json:"changed_files,omitempty"`
3334

3435
HTMLURL string `json:"html_url"`
3536
DiffURL string `json:"diff_url"`

services/convert/pull.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
239239
// Calculate diff
240240
startCommitID = pr.MergeBase
241241

242-
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
242+
diffChangedFiles, diffAdditions, diffDeletions, err := gitRepo.GetDiffShortStat(startCommitID, endCommitID)
243243
if err != nil {
244244
log.Error("GetDiffShortStat: %v", err)
245+
} else {
246+
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions = &diffChangedFiles, &diffAdditions, &diffDeletions
245247
}
246248
}
247249

@@ -459,12 +461,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
459461
return nil, err
460462
}
461463

462-
// Outer scope variables to be used in diff calculation
463-
var (
464-
startCommitID string
465-
endCommitID string
466-
)
467-
468464
if git.IsErrBranchNotExist(err) {
469465
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
470466
if err != nil && !git.IsErrNotExist(err) {
@@ -473,7 +469,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
473469
}
474470
if err == nil {
475471
apiPullRequest.Head.Sha = headCommitID
476-
endCommitID = headCommitID
477472
}
478473
} else {
479474
commit, err := headBranch.GetCommit()
@@ -484,17 +479,8 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
484479
if err == nil {
485480
apiPullRequest.Head.Ref = pr.HeadBranch
486481
apiPullRequest.Head.Sha = commit.ID.String()
487-
endCommitID = commit.ID.String()
488482
}
489483
}
490-
491-
// Calculate diff
492-
startCommitID = pr.MergeBase
493-
494-
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
495-
if err != nil {
496-
log.Error("GetDiffShortStat: %v", err)
497-
}
498484
}
499485

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

0 commit comments

Comments
 (0)