Browse Source

Trigger repository mirroring on more events

pull/68/head
Mat Mannion 6 years ago
parent
commit
2a50e35587
  1. 16
      src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java
  2. 2
      src/test/java/com/englishtown/bitbucket/hook/MirrorRepositoryHookTest.java

16
src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java

@ -1,9 +1,6 @@
package com.englishtown.bitbucket.hook; package com.englishtown.bitbucket.hook;
import com.atlassian.bitbucket.hook.repository.PostRepositoryHook; import com.atlassian.bitbucket.hook.repository.*;
import com.atlassian.bitbucket.hook.repository.PostRepositoryHookContext;
import com.atlassian.bitbucket.hook.repository.RepositoryHookRequest;
import com.atlassian.bitbucket.hook.repository.StandardRepositoryHookTrigger;
import com.atlassian.bitbucket.i18n.I18nService; import com.atlassian.bitbucket.i18n.I18nService;
import com.atlassian.bitbucket.repository.Repository; import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.repository.RepositoryService; import com.atlassian.bitbucket.repository.RepositoryService;
@ -21,6 +18,7 @@ import com.atlassian.bitbucket.setting.SettingsValidator;
import com.atlassian.sal.api.pluginsettings.PluginSettings; import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -59,6 +57,14 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
static final int MAX_ATTEMPTS = 5; static final int MAX_ATTEMPTS = 5;
static final String DEFAULT_REFSPEC = "+refs/heads/*:refs/heads/*"; static final String DEFAULT_REFSPEC = "+refs/heads/*:refs/heads/*";
/**
* Trigger types that don't cause a mirror to happen
*/
private static ImmutableSet<RepositoryHookTrigger> TRIGGERS_TO_IGNORE =
ImmutableSet.of(
StandardRepositoryHookTrigger.UNKNOWN
);
private final ScmService scmService; private final ScmService scmService;
private final I18nService i18nService; private final I18nService i18nService;
private final ScheduledExecutorService executor; private final ScheduledExecutorService executor;
@ -107,7 +113,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
*/ */
@Override @Override
public void postUpdate(@Nonnull PostRepositoryHookContext context, @Nonnull RepositoryHookRequest request) { public void postUpdate(@Nonnull PostRepositoryHookContext context, @Nonnull RepositoryHookRequest request) {
if (request.getTrigger() == StandardRepositoryHookTrigger.REPO_PUSH) { if (!TRIGGERS_TO_IGNORE.contains(request.getTrigger())) {
logger.debug("MirrorRepositoryHook: postReceive started."); logger.debug("MirrorRepositoryHook: postReceive started.");
List<MirrorSettings> mirrorSettings = getMirrorSettings(context.getSettings()); List<MirrorSettings> mirrorSettings = getMirrorSettings(context.getSettings());

2
src/test/java/com/englishtown/bitbucket/hook/MirrorRepositoryHookTest.java

@ -107,7 +107,7 @@ public class MirrorRepositoryHookTest {
public void testUnwantedEventsIgnored() { public void testUnwantedEventsIgnored() {
Repository repo = mock(Repository.class); Repository repo = mock(Repository.class);
hook.postUpdate(buildContext(), buildRequest(StandardRepositoryHookTrigger.BRANCH_CREATE, repo)); hook.postUpdate(buildContext(), buildRequest(StandardRepositoryHookTrigger.UNKNOWN, repo));
verify(executor, never()).submit(ArgumentMatchers.<Runnable>any()); verify(executor, never()).submit(ArgumentMatchers.<Runnable>any());
} }

Loading…
Cancel
Save