mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Fire RepositoryImportHookEvent instead of PostReceiveRepositoryHookEvent (#1561)
We will fire an RepositoryImportHookEvent instead of PostReceiveRepositoryHookEvent for repository imports with metadata. The event is only fired if all parts of the repository could be successfully imported. The extra event is required to avoid heavy recalculations which can be triggered by the PostReceiveRepositoryHookEvent for example the scm-statistic-plugin uses the PostReceiveRepositoryHookEvent to calculate its statistics. Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
This commit is contained in:
@@ -80,7 +80,7 @@ public class AbstractRemoteCommandTestBase {
|
||||
outgoing = Git.init().setDirectory(outgoingDirectory).setBare(false).call();
|
||||
|
||||
eventBus = mock(ScmEventBus.class);
|
||||
eventFactory = mock(GitPostReceiveRepositoryHookEventFactory.class);
|
||||
eventFactory = mock(GitRepositoryHookEventFactory.class);
|
||||
|
||||
handler = mock(GitRepositoryHandler.class);
|
||||
when(handler.getDirectory(incomingRepository.getId())).thenReturn(
|
||||
@@ -212,5 +212,5 @@ public class AbstractRemoteCommandTestBase {
|
||||
private ScmTransportProtocol proto;
|
||||
|
||||
protected ScmEventBus eventBus;
|
||||
protected GitPostReceiveRepositoryHookEventFactory eventFactory;
|
||||
protected GitRepositoryHookEventFactory eventFactory;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.GitChangesetConverterFactory;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
import sonia.scm.repository.Tag;
|
||||
import sonia.scm.repository.api.HookContext;
|
||||
import sonia.scm.repository.api.HookContextFactory;
|
||||
@@ -48,7 +48,7 @@ public class GitPostReceiveRepositoryHookEventFactoryTest extends AbstractGitCom
|
||||
|
||||
private HookContext hookContext;
|
||||
|
||||
private GitPostReceiveRepositoryHookEventFactory eventFactory;
|
||||
private GitRepositoryHookEventFactory eventFactory;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
@@ -56,7 +56,7 @@ public class GitPostReceiveRepositoryHookEventFactoryTest extends AbstractGitCom
|
||||
hookContext = mock(HookContext.class, RETURNS_DEEP_STUBS);
|
||||
when(hookContextFactory.createContext(any(), eq(repository))).thenReturn(hookContext);
|
||||
GitChangesetConverterFactory converterFactory = mock(GitChangesetConverterFactory.class);
|
||||
eventFactory = new GitPostReceiveRepositoryHookEventFactory(hookContextFactory, converterFactory);
|
||||
eventFactory = new GitRepositoryHookEventFactory(hookContextFactory, converterFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public class GitPostReceiveRepositoryHookEventFactoryTest extends AbstractGitCom
|
||||
when(hookContext.getBranchProvider().getCreatedOrModified()).thenReturn(branches);
|
||||
when(hookContext.getTagProvider().getCreatedTags()).thenReturn(tags);
|
||||
|
||||
PostReceiveRepositoryHookEvent event = eventFactory.createEvent(
|
||||
RepositoryHookEvent event = eventFactory.createEvent(
|
||||
createContext(),
|
||||
branches,
|
||||
tags,
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryHookType;
|
||||
import sonia.scm.util.Archives;
|
||||
@@ -37,40 +35,41 @@ import sonia.scm.util.Archives;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class GitUnbundleCommandTest extends AbstractGitCommandTestBase {
|
||||
private ScmEventBus eventBus;
|
||||
private GitUnbundleCommand unbundleCommand;
|
||||
private GitPostReceiveRepositoryHookEventFactory eventFactory;
|
||||
private GitRepositoryHookEventFactory eventFactory;
|
||||
|
||||
@Before
|
||||
public void initUnbundleCommand() {
|
||||
eventBus = mock(ScmEventBus.class);
|
||||
eventFactory = mock(GitPostReceiveRepositoryHookEventFactory.class);
|
||||
unbundleCommand = new GitUnbundleCommand(createContext(), eventBus, eventFactory);
|
||||
eventFactory = mock(GitRepositoryHookEventFactory.class);
|
||||
unbundleCommand = new GitUnbundleCommand(createContext(), eventFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUnbundleRepositoryFiles() throws IOException {
|
||||
when(eventFactory.createEvent(eq(createContext()), any(), any(), any()))
|
||||
.thenReturn(new PostReceiveRepositoryHookEvent(new RepositoryHookEvent(null, repository, RepositoryHookType.POST_RECEIVE)));
|
||||
RepositoryHookEvent event = new RepositoryHookEvent(null, repository, RepositoryHookType.POST_RECEIVE);
|
||||
when(eventFactory.createEvent(eq(createContext()), any(), any(), any())).thenReturn(event);
|
||||
|
||||
AtomicReference<RepositoryHookEvent> receivedEvent = new AtomicReference<>();
|
||||
|
||||
String filePath = "test-input";
|
||||
String fileContent = "HeartOfGold";
|
||||
UnbundleCommandRequest unbundleCommandRequest = createUnbundleCommandRequestForFile(filePath, fileContent);
|
||||
unbundleCommandRequest.setPostEventSink(receivedEvent::set);
|
||||
|
||||
unbundleCommand.unbundle(unbundleCommandRequest);
|
||||
|
||||
assertFileWithContentWasCreated(createContext().getDirectory(), filePath, fileContent);
|
||||
|
||||
verify(eventBus).post(any(PostReceiveRepositoryHookEvent.class));
|
||||
assertThat(receivedEvent.get()).isSameAs(event);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user