Merge "Return code-owners~skip-validation option only if OWNERS files are touched"
diff --git a/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java b/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java index 8411568..1a08131 100644 --- a/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java +++ b/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java
@@ -306,15 +306,15 @@ } else { try (InMemoryInserter ins = new InMemoryInserter(repository); ObjectReader reader = ins.newReader(); - RevWalk rw = new RevWalk(reader)) { + RevWalk rw = new RevWalk(reader); + RepoView repoView = new RepoView(repository, rw, ins)) { ChangeNotes changeNotes = changeNotesFactory.create(projectState.getNameKey(), commit.change().getId()); PatchSet patchSet = patchSetUtil.get(changeNotes, patchSetId); IdentifiedUser patchSetUploader = userFactory.create(patchSet.uploader()); validationResult = validateCodeOwnerConfig( - diffOperationsForCommitValidationFactory.create( - new RepoView(repository, rw, ins), ins), + diffOperationsForCommitValidationFactory.create(repoView, ins), branchNameKey, commit, patchSetUploader,
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java index c3dece0..479ad1d 100644 --- a/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java +++ b/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java
@@ -66,7 +66,8 @@ new TestRepository<>(repoManager.openRepository(project)); ObjectInserter ins = testRepo.getRepository().newObjectInserter(); ObjectReader reader = ins.newReader(); - RevWalk revWalk = new RevWalk(reader)) { + RevWalk revWalk = new RevWalk(reader); + RepoView repoView = new RepoView(testRepo.getRepository(), revWalk, ins)) { RevCommit commit = testRepo .commit() @@ -74,20 +75,21 @@ .add("project.config", "INVALID") .create(); - CommitReceivedEvent receiveEvent = new CommitReceivedEvent(); - receiveEvent.project = - projectCache.get(project).orElseThrow(illegalState(project)).getProject(); - receiveEvent.refName = RefNames.REFS_CONFIG; - receiveEvent.commit = commit; - receiveEvent.revWalk = testRepo.getRevWalk(); - receiveEvent.repoConfig = new Config(); - receiveEvent.diffOperations = - diffOperationsForCommitValidationFactory.create( - new RepoView(testRepo.getRepository(), revWalk, ins), ins); - CommitValidationException exception = - assertThrows( - CommitValidationException.class, - () -> codeOwnersPluginConfigValidator.onCommitReceived(receiveEvent)); + CommitValidationException exception; + try (CommitReceivedEvent receiveEvent = new CommitReceivedEvent()) { + receiveEvent.project = + projectCache.get(project).orElseThrow(illegalState(project)).getProject(); + receiveEvent.refName = RefNames.REFS_CONFIG; + receiveEvent.commit = commit; + receiveEvent.revWalk = testRepo.getRevWalk(); + receiveEvent.repoConfig = new Config(); + receiveEvent.diffOperations = + diffOperationsForCommitValidationFactory.create(repoView, ins); + exception = + assertThrows( + CommitValidationException.class, + () -> codeOwnersPluginConfigValidator.onCommitReceived(receiveEvent)); + } assertThat(exception) .hasMessageThat() .isEqualTo(