Keesun Baik 2015-03-05
NotificationEvent: bug fix
The pull-request's commit changed events occured even when it is not actually changed. like:
* new pull-request is created.
* other pull-requests are merged.

Fixed to send the event notification only when it is changed.
@80a80c5f08f1a951263dc69550e61aeb93ccd95e
app/actors/PullRequestActor.java
--- app/actors/PullRequestActor.java
+++ app/actors/PullRequestActor.java
@@ -38,8 +38,10 @@
 
             if (mergeResult.hasDiffCommits()) {
                 mergeResult.saveCommits();
-                NotificationEvent.afterPullRequestCommitChanged(message.getSender(), pullRequest);
                 if (!mergeResult.getNewCommits().isEmpty()) {
+                    if (!message.isNewPullRequest()) {
+                        NotificationEvent.afterPullRequestCommitChanged(message.getSender(), pullRequest);
+                    }
                     PullRequestEvent.addCommitEvents(message.getSender(), pullRequest,
                             mergeResult.getNewCommits(),
                             getCommitEventOldValue(oldMergeCommitId, pullRequest.mergedCommitIdTo));
app/controllers/PullRequestApp.java
--- app/controllers/PullRequestApp.java
+++ app/controllers/PullRequestApp.java
@@ -281,8 +281,7 @@
         NotificationEvent notiEvent = NotificationEvent.afterNewPullRequest(pullRequest);
         PullRequestEvent.addFromNotificationEvent(notiEvent, pullRequest);
 
-        PullRequestEventMessage message = new PullRequestEventMessage(
-                UserApp.currentUser(), request(), pullRequest);
+        PullRequestEventMessage message = new PullRequestEventMessage(UserApp.currentUser(), request(), pullRequest, notiEvent.eventType);
         Akka.system().actorOf(Props.create(PullRequestMergingActor.class)).tell(message, null);
 
         return redirect(pullRequestCall);
app/models/PullRequestEventMessage.java
--- app/models/PullRequestEventMessage.java
+++ app/models/PullRequestEventMessage.java
@@ -20,6 +20,7 @@
  */
 package models;
 
+import models.enumeration.EventType;
 import play.mvc.Http.Request;
 
 public class PullRequestEventMessage {
@@ -28,6 +29,7 @@
     private Project project;
     private String branch;
     private PullRequest pullRequest;
+    private EventType eventType;
 
     public PullRequestEventMessage(User sender, Request request, Project project, String branch) {
         this.sender = sender;
@@ -40,6 +42,11 @@
         this.sender = sender;
         this.request = request;
         this.pullRequest = pullRequest;
+    }
+
+    public PullRequestEventMessage(User sender, Request request, PullRequest pullRequest, EventType eventType) {
+        this(sender, request, pullRequest);
+        this.eventType = eventType;
     }
 
     public User getSender() {
@@ -61,4 +68,8 @@
     public PullRequest getPullRequest() {
         return pullRequest;
     }
+
+    public boolean isNewPullRequest() {
+        return eventType != null && eventType == EventType.NEW_PULL_REQUEST;
+    }
 }
Add a comment
List