Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Processing events on Bitbucket Server's event threads #78
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Oct 16, 2015
1 parent 36aa1ce commit b1d305f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Changelog of Pull Request Notifier for Stash.

## 1.35
* Processing events on Bitbucket Server's event threads

## 1.34
* Url encoding evaluated values when they are used in URL invocations.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static se.bjurr.prnfs.settings.SettingsStorage.getPrnfsSettings;

import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.logging.Logger;

import se.bjurr.prnfs.listener.PrnfsRenderer.PrnfsVariable;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class PrnfsPullRequestEventListener {
private final RepositoryService repositoryService;
private final ApplicationPropertiesService propertiesService;
private final PullRequestService pullRequestService;
private final ExecutorService executorService;
private static final Logger logger = getLogger(PrnfsPullRequestEventListener.class.getName());

private static Invoker invoker = new Invoker() {
Expand All @@ -69,64 +71,75 @@ public static void setInvoker(Invoker invoker) {
}

public PrnfsPullRequestEventListener(PluginSettingsFactory pluginSettingsFactory, RepositoryService repositoryService,
ApplicationPropertiesService propertiesService, PullRequestService pullRequestService) {
ApplicationPropertiesService propertiesService, PullRequestService pullRequestService,
ExecutorService executorService) {
this.pluginSettingsFactory = pluginSettingsFactory;
this.repositoryService = repositoryService;
this.propertiesService = propertiesService;
this.pullRequestService = pullRequestService;
this.executorService = executorService;
}

@EventListener
public void onEvent(PullRequestApprovedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestCommentAddedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestCommentRepliedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestDeclinedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestMergedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestOpenedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestReopenedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(final PullRequestRescopedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestUnapprovedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@EventListener
public void onEvent(PullRequestUpdatedEvent e) {
handleEvent(e);
handleEventAsync(e);
}

@VisibleForTesting
public void handleEventAsync(final PullRequestEvent pullRequestEvent) {
executorService.execute(new Runnable() {
@Override
public void run() {
handleEvent(pullRequestEvent);
}
});
}

public void handleEvent(final PullRequestEvent pullRequestEvent) {
try {
if (pullRequestEvent.getPullRequest().isClosed() && pullRequestEvent instanceof PullRequestCommentEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public <T> T execute(TransactionCallback<T> action) {
configResource = new ConfigResource(userManager, pluginSettingsFactory, transactionTemplate, securityService);
pullRequestService = mock(PullRequestService.class);
listener = new PrnfsPullRequestEventListener(pluginSettingsFactory, repositoryService, propertiesService,
pullRequestService);
pullRequestService, new SyncExecutorService());
UserService userService = mock(UserService.class);
withPullRequest(pullRequestEventBuilder().build().getPullRequest());
manualResouce = new ManualResource(userManager, userService, pluginSettingsFactory, pullRequestService, listener,
Expand Down

0 comments on commit b1d305f

Please sign in to comment.