Get file changes in RepositoryMergeCheck

I’m trying to get list of changed files in RepositoryMergeCheck, but Collection of RefChange always empty.

My code:

public RepositoryHookResult preUpdate(
    @Nonnull PreRepositoryHookContext context,
    @Nonnull PullRequestMergeHookRequest request) {
    Collection<RefChange> refChanges = request.getRefChanges();
    // ............

With debugger I can see my variables, and refChanges is empty (size = 0).

I suppose RepositoryMergeCheck haven’t any information about changes. I want to add some specific reviewers based on changing some specific files in PR. Is it possible (one way or another)?

1 Like

You can obtain the changeset from the pull request object with the help of PullRequestService API:

PullRequest pullRequest = request.getPullRequest();

PullRequestChangesRequest changesRequest = new PullRequestChangesRequest.Builder(pullRequest).build();
pullRequestService.streamChanges(changesRequest, new ChangeCallback() {
            public boolean onChange(@Nonnull Change change) throws IOException {
                // >>> Process your file change here
                return false;

Let me know if that works for you
Kind regards, Ulrich
++Remove boring from work++

1 Like

Thanks for the answer, Ulrich!

I already tried this way - unfortunately, it return only the first change.
In my case, I have 2 commits (add file one and add file two). In the onChange(@Nonnull Change change) method I can see only change for “add file one” commit.

I found solutions throw DiffContentCallback - looks terrible, but works :smiley::

CompareRef compareRefFrom = new CompareRef(request.getFromRef());
CompareRef compareRefTo = new CompareRef(request.getToRef());
CompareDiffRequest compareDiffRequest = new CompareDiffRequest.Builder()

DiffContentCallback diffContentCallback = new DiffContentCallback() {
    public void onDiffStart(@Nullable Path path, @Nullable Path path1) {
        // ... do something ...

    * Not necessary
    * but can't use DiffContentCallback without overriding
    public void offerThreads(@Nonnull Stream<CommentThread> stream) {}
    public void onBinary(@Nullable Path path, @Nullable Path path1) {}
    public void onDiffEnd(boolean b) {}
    public void onEnd(@Nonnull DiffSummary diffSummary) {}
    public void onHunkEnd(boolean b) {}
    public void onHunkStart(int i, int i1, int i2, int i3, @Nullable String s) {}
    public void onSegmentEnd(boolean b) {}
    public void onSegmentLine(@Nonnull String s, @Nullable ConflictMarker conflictMarker, boolean b) {}
    public void onSegmentStart(@Nonnull DiffSegmentType diffSegmentType) {}
    public void onStart(@Nonnull DiffContext diffContext) {}
compareService.streamDiff(compareDiffRequest, diffContentCallback);

And now I can catch all changes. I hope we can find a better way.