diff --git a/gradle/changelog/plugin_logo.yaml b/gradle/changelog/plugin_logo.yaml index dc6c14caa9..3046c11ffd 100644 --- a/gradle/changelog/plugin_logo.yaml +++ b/gradle/changelog/plugin_logo.yaml @@ -1,2 +1,2 @@ - type: Added - description: Add bounding box for plugin avatar ([#1749](https://github.com/scm-manager/scm-manager/pull/1749)) + description: Bounding box for plugin avatar ([#1749](https://github.com/scm-manager/scm-manager/pull/1749)) diff --git a/gradle/changelog/post_receive_hook_event_after_import.yaml b/gradle/changelog/post_receive_hook_event_after_import.yaml new file mode 100644 index 0000000000..cf657f050f --- /dev/null +++ b/gradle/changelog/post_receive_hook_event_after_import.yaml @@ -0,0 +1,2 @@ +- type: Fixed + description: Post 'post receive repository hook event' after import ([#1754](https://github.com/scm-manager/scm-manager/pull/1754)) diff --git a/gradle/changelog/query_with_hypen.yaml b/gradle/changelog/query_with_hypen.yaml index d2a001fbab..fab8eb7ae7 100644 --- a/gradle/changelog/query_with_hypen.yaml +++ b/gradle/changelog/query_with_hypen.yaml @@ -1,2 +1,2 @@ - type: Fixed - description: Fixed search queries containing hypens ([#1743](https://github.com/scm-manager/scm-manager/issues/1743) and [#1753](https://github.com/scm-manager/scm-manager/pull/1753)) + description: Search queries containing hypens ([#1743](https://github.com/scm-manager/scm-manager/issues/1743) and [#1753](https://github.com/scm-manager/scm-manager/pull/1753)) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/PostReceiveRepositoryHookEventFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/PostReceiveRepositoryHookEventFactory.java index b9d7d982c5..33507df73e 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/PostReceiveRepositoryHookEventFactory.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/PostReceiveRepositoryHookEventFactory.java @@ -29,7 +29,6 @@ import sonia.scm.ContextEntry; import sonia.scm.event.ScmEventBus; import sonia.scm.repository.PostReceiveRepositoryHookEvent; -import sonia.scm.repository.RepositoryHookEvent; import sonia.scm.repository.Tag; import sonia.scm.repository.WrappedRepositoryHookEvent; import sonia.scm.repository.api.ImportFailedException; diff --git a/scm-webapp/src/main/java/sonia/scm/importexport/FromBundleImporter.java b/scm-webapp/src/main/java/sonia/scm/importexport/FromBundleImporter.java index cb4ad5a91b..68b8f7cb13 100644 --- a/scm-webapp/src/main/java/sonia/scm/importexport/FromBundleImporter.java +++ b/scm-webapp/src/main/java/sonia/scm/importexport/FromBundleImporter.java @@ -31,6 +31,7 @@ import sonia.scm.event.ScmEventBus; import sonia.scm.repository.ImportRepositoryHookEvent; import sonia.scm.repository.InternalRepositoryException; +import sonia.scm.repository.PostReceiveRepositoryHookEvent; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryHookEvent; import sonia.scm.repository.RepositoryImportEvent; @@ -132,6 +133,7 @@ private void runUnbundleCommand(boolean compressed, RepositoryService service, F .unbundle(file); RepositoryHookEvent repositoryHookEvent = eventSink.get(); if (repositoryHookEvent != null) { + eventBus.post(new PostReceiveRepositoryHookEvent(repositoryHookEvent)); eventBus.post(new ImportRepositoryHookEvent(repositoryHookEvent)); } } diff --git a/scm-webapp/src/test/java/sonia/scm/importexport/FromBundleImporterTest.java b/scm-webapp/src/test/java/sonia/scm/importexport/FromBundleImporterTest.java index 61114f118c..0fb09cc003 100644 --- a/scm-webapp/src/test/java/sonia/scm/importexport/FromBundleImporterTest.java +++ b/scm-webapp/src/test/java/sonia/scm/importexport/FromBundleImporterTest.java @@ -28,7 +28,6 @@ import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.ThreadContext; -import org.junit.Assert; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -40,8 +39,11 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import sonia.scm.event.ScmEventBus; +import sonia.scm.repository.ImportRepositoryHookEvent; +import sonia.scm.repository.PostReceiveRepositoryHookEvent; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryHandler; +import sonia.scm.repository.RepositoryHookEvent; import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryPermission; import sonia.scm.repository.RepositoryTestData; @@ -65,6 +67,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -136,8 +139,7 @@ void initMocks(@TempDir Path temp) throws IOException { @Test void shouldImportCompressedBundle() throws IOException { - URL dumpUrl = Resources.getResource("sonia/scm/api/v2/svn.dump.gz"); - InputStream in = new ByteArrayInputStream(Resources.toByteArray(dumpUrl)); + InputStream in = buildInput("sonia/scm/api/v2/svn.dump.gz"); importer.importFromBundle(true, in, REPOSITORY); @@ -147,8 +149,7 @@ void shouldImportCompressedBundle() throws IOException { @Test void shouldImportNonCompressedBundle() throws IOException { - URL dumpUrl = Resources.getResource("sonia/scm/api/v2/svn.dump"); - InputStream in = new ByteArrayInputStream(Resources.toByteArray(dumpUrl)); + InputStream in = buildInput("sonia/scm/api/v2/svn.dump"); importer.importFromBundle(false, in, REPOSITORY); @@ -158,8 +159,7 @@ void shouldImportNonCompressedBundle() throws IOException { @Test void shouldSetPermissionForCurrentUser() throws IOException { - URL dumpUrl = Resources.getResource("sonia/scm/api/v2/svn.dump"); - InputStream in = new ByteArrayInputStream(Resources.toByteArray(dumpUrl)); + InputStream in = buildInput("sonia/scm/api/v2/svn.dump"); Repository createdRepository = importer.importFromBundle(false, in, REPOSITORY); @@ -170,12 +170,28 @@ void shouldSetPermissionForCurrentUser() throws IOException { assertThat(permission.isGroupPermission()).isFalse(); assertThat(permission.getRole()).isEqualTo("OWNER"); } + + @Test + void shouldPostEvents() throws IOException { + InputStream in = buildInput("sonia/scm/api/v2/svn.dump"); + + RepositoryHookEvent event = mock(RepositoryHookEvent.class); + when(unbundleCommandBuilder.setPostEventSink(any())) + .thenAnswer(invocationOnMock -> { + invocationOnMock.getArgument(0, Consumer.class).accept(event); + return invocationOnMock.getMock(); + }); + + importer.importFromBundle(false, in, REPOSITORY); + + verify(eventBus).post(argThat(o -> o instanceof PostReceiveRepositoryHookEvent)); + verify(eventBus).post(argThat(o -> o instanceof ImportRepositoryHookEvent)); + } } @Test void shouldFailWithoutPermission() throws IOException { - URL dumpUrl = Resources.getResource("sonia/scm/api/v2/svn.dump"); - InputStream in = new ByteArrayInputStream(Resources.toByteArray(dumpUrl)); + InputStream in = buildInput("sonia/scm/api/v2/svn.dump"); doThrow(new AuthorizationException()).when(subject).checkPermission("repository:create"); @@ -183,4 +199,9 @@ void shouldFailWithoutPermission() throws IOException { verify(manager, never()).create(any(), any()); } + + private InputStream buildInput(String s) throws IOException { + URL dumpUrl = Resources.getResource(s); + return new ByteArrayInputStream(Resources.toByteArray(dumpUrl)); + } }