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

Commit

Permalink
Removing RESCOPED event to trigger _FROM and _TO instead #37
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jun 20, 2015
1 parent 76a9217 commit d948d6b
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 145 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.15
* Removing RESCOPED event, its confusing when to use it with _FROM, _TO.

## 1.14
* New variables with information about the user who issued the event
* ${PULL_REQUEST_USER_DISPLAY_NAME} Example: Some User
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The Pull Request Notifier for Stash can:
* Send custom HTTP headers
* Can optionally use proxy to connect

If you only want to trigger on RESCOPED_FROM, or RESCOPED_TO, you will also need to trigger on RESCOPED. Stash will fire an event, RESCOPED, if target and/or source branch is changed. The plugin has its own implementation to create the RESCOPED_FROM and RESCOPED_TO events. RESCOPED is transformed to RESCOPED_FROM if only source branch changed, RESCOPED_TO if only target branch changed and kept as RESCOPED if both changed.
The plugin has its own implementation to create the RESCOPED_FROM and RESCOPED_TO events. RESCOPED is transformed to RESCOPED_FROM if source branch changed, RESCOPED_TO if target branch changed.

The filter text as well as the URL support variables. These are:

Expand Down
22 changes: 19 additions & 3 deletions src/main/java/se/bjurr/prnfs/listener/PrnfsPullRequestAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import static com.atlassian.stash.pull.PullRequestAction.UNAPPROVED;
import static com.atlassian.stash.pull.PullRequestAction.UPDATED;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.Boolean.FALSE;

import java.util.List;
import java.util.Map;

import se.bjurr.prnfs.settings.PrnfsNotification;

import com.atlassian.stash.event.pull.PullRequestEvent;
import com.atlassian.stash.event.pull.PullRequestRescopedEvent;
import com.google.common.collect.ImmutableMap;
Expand All @@ -30,7 +33,7 @@ public class PrnfsPullRequestAction {
.put(MERGED.name(), new PrnfsPullRequestAction(MERGED.name())) //
.put(OPENED.name(), new PrnfsPullRequestAction(OPENED.name())) //
.put(REOPENED.name(), new PrnfsPullRequestAction(REOPENED.name())) //
.put(RESCOPED.name(), new PrnfsPullRequestAction(RESCOPED.name())) //
.put(RESCOPED.name(), new PrnfsPullRequestAction(RESCOPED_FROM)) //
.put(RESCOPED_FROM, new PrnfsPullRequestAction(RESCOPED_FROM)) //
.put(RESCOPED_TO, new PrnfsPullRequestAction(RESCOPED_TO)) //
.put(UNAPPROVED.name(), new PrnfsPullRequestAction(UNAPPROVED.name())) //
Expand Down Expand Up @@ -62,8 +65,7 @@ public static List<PrnfsPullRequestAction> values() {
return newArrayList(values.values());
}

@SuppressWarnings("deprecation")
public static PrnfsPullRequestAction fromPullRequestEvent(PullRequestEvent event) {
public static PrnfsPullRequestAction fromPullRequestEvent(PullRequestEvent event, PrnfsNotification notification) {
if (event instanceof PullRequestRescopedEvent) {
PullRequestRescopedEvent rescopedEvent = (PullRequestRescopedEvent) event;
boolean toChanged = !rescopedEvent.getPreviousToHash().equals(
Expand All @@ -74,8 +76,22 @@ public static PrnfsPullRequestAction fromPullRequestEvent(PullRequestEvent event
return PrnfsPullRequestAction.valueOf(RESCOPED_FROM);
} else if (toChanged && !fromChanged) {
return PrnfsPullRequestAction.valueOf(RESCOPED_TO);
} else {
if (notification.getTriggers().contains(values.get(RESCOPED_FROM))) {
return PrnfsPullRequestAction.valueOf(RESCOPED_FROM);
} else if (notification.getTriggers().contains(values.get(RESCOPED_TO))) {
return PrnfsPullRequestAction.valueOf(RESCOPED_TO);
}
}
}
return PrnfsPullRequestAction.valueOf(event.getAction().name());
}

@Override
public boolean equals(Object obj) {
if (obj instanceof PrnfsPullRequestAction) {
return getName().equals(((PrnfsPullRequestAction) obj).getName());
}
return FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,55 +62,56 @@ public PrnfsPullRequestEventListener(PluginSettingsFactory pluginSettingsFactory

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

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

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

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

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

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

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

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

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

@VisibleForTesting
public void handleEvent(PullRequestEvent pullRequestEvent, PrnfsPullRequestAction action) {
final PrnfsRenderer renderer = new PrnfsRenderer(pullRequestEvent, repositoryService);
public void handleEvent(PullRequestEvent pullRequestEvent) {
try {
final PrnfsSettings settings = getPrnfsSettings(pluginSettingsFactory.createGlobalSettings());
for (final PrnfsNotification notification : settings.getNotifications()) {
final PrnfsRenderer renderer = new PrnfsRenderer(pullRequestEvent, repositoryService, notification);
PrnfsPullRequestAction action = fromPullRequestEvent(pullRequestEvent, notification);
if (notification.getFilterRegexp().isPresent()
&& notification.getFilterString().isPresent()
&& !compile(notification.getFilterRegexp().get()).matcher(renderer.render(notification.getFilterString().get()))
Expand Down
Loading

0 comments on commit d948d6b

Please sign in to comment.