Skip to content

Commit 243b824

Browse files
committed
Fix bug disallowing seeing changed files in PRs from forks
1 parent 2ee241f commit 243b824

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ func ViewPullFiles(ctx *context.Context) {
702702
methodWithError = "GetDiff"
703703
} else {
704704
diff, err = gitdiff.SyncAndGetUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diffOptions, files...)
705-
methodWithError = "GetUserSpecificDiff"
705+
methodWithError = "SyncAndGetUserSpecificDiff"
706706
}
707707
if err != nil {
708708
ctx.ServerError(methodWithError, err)

services/gitdiff/gitdiff.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,12 @@ func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *models.
15261526
return diff, err
15271527
}
15281528

1529-
// Prepation to check for each file whether it was changed since the last review
1530-
changedFiles, err := gitRepo.GetFilesChangedBetween(review.CommitSHA, pull.HeadBranch)
1529+
latestCommit := opts.AfterCommitID
1530+
if latestCommit == "" {
1531+
latestCommit = pull.HeadBranch // opts.AfterCommitID is preferred because it handles PRs from forks correctly and the branch name doesn't
1532+
}
1533+
1534+
changedFiles, err := gitRepo.GetFilesChangedBetween(review.CommitSHA, latestCommit)
15311535
if err != nil {
15321536
return diff, err
15331537
}
@@ -1563,14 +1567,12 @@ outer:
15631567
// Explicitly store files that have changed in the database, if any is present at all.
15641568
// This has the benefit that the "Has Changed" attribute will be present as long as the user does not explicitly mark this file as viewed, so it will even survive a page reload after marking another file as viewed.
15651569
// On the other hand, this means that even if a commit reverting an unseen change is committed, the file will still be seen as changed.
1566-
// The update is performed in the background because it only affects future calls to this function and not the present one, and because it is quite an expensive operation
15671570
if len(filesChangedSinceLastDiff) > 0 {
1568-
go func() {
1569-
err := pulls.UpdateReviewState(ctx, review.UserID, review.PullID, review.CommitSHA, filesChangedSinceLastDiff)
1570-
if err != nil {
1571-
log.Warn("Could not update review for user %d, pull %d, commit %s and the changed files %v: %v", review.UserID, review.PullID, review.CommitSHA, filesChangedSinceLastDiff, err)
1572-
}
1573-
}()
1571+
err := pulls.UpdateReviewState(ctx, review.UserID, review.PullID, review.CommitSHA, filesChangedSinceLastDiff)
1572+
if err != nil {
1573+
log.Warn("Could not update review for user %d, pull %d, commit %s and the changed files %v: %v", review.UserID, review.PullID, review.CommitSHA, filesChangedSinceLastDiff, err)
1574+
return nil, err
1575+
}
15741576
}
15751577

15761578
return diff, err

0 commit comments

Comments
 (0)