채수원 2015-03-02
Merge branch 'issue-2130' of dlab/hive
from pull-request 1482

* refs/heads/issue-2130:
  Added notification event after the pulll-request's commits are changed

Reviewed-by: 채수원 
@91b3cba2ede0b8dd96e72b22f85d3aa1143f3c33
app/actors/PullRequestActor.java
--- app/actors/PullRequestActor.java
+++ app/actors/PullRequestActor.java
@@ -25,6 +25,8 @@
 import models.enumeration.EventType;
 import models.enumeration.State;
 
+import java.util.List;
+
 public abstract class PullRequestActor extends UntypedActor {
 
     protected void processPullRequestMerging(PullRequestEventMessage message, PullRequest pullRequest) {
@@ -36,6 +38,7 @@
 
             if (mergeResult.hasDiffCommits()) {
                 mergeResult.saveCommits();
+                NotificationEvent.afterPullRequestCommitChanged(message.getSender(), pullRequest);
                 if (!mergeResult.getNewCommits().isEmpty()) {
                     PullRequestEvent.addCommitEvents(message.getSender(), pullRequest,
                             mergeResult.getNewCommits(),
app/models/NotificationEvent.java
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
@@ -463,6 +463,32 @@
         return notiEvent;
     }
 
+    public static NotificationEvent afterPullRequestCommitChanged(User sender, PullRequest pullRequest) {
+        NotificationEvent notiEvent = createFrom(sender, pullRequest);
+        notiEvent.title = formatReplyTitle(pullRequest);
+        notiEvent.receivers = getReceivers(sender, pullRequest);
+        notiEvent.eventType = PULL_REQUEST_COMMIT_CHANGED;
+        notiEvent.oldValue = null;
+        notiEvent.newValue = newPullRequestCommitChangedMessage(pullRequest);
+        NotificationEvent.add(notiEvent);
+        return notiEvent;
+    }
+
+    private static String newPullRequestCommitChangedMessage(PullRequest pullRequest) {
+        List<PullRequestCommit> commits = PullRequestCommit.find.where().eq("pullRequest", pullRequest).orderBy().desc("authorDate").findList();
+        StringBuilder builder = new StringBuilder();
+        builder.append("### ");
+        builder.append(Messages.get("notification.pullrequest.current.commits"));
+        builder.append("\n");
+        for (PullRequestCommit commit : commits) {
+            builder.append(commit.getCommitShortId());
+            builder.append(" ");
+            builder.append(commit.getCommitShortMessage());
+            builder.append("\n");
+        }
+        return builder.toString();
+    }
+
     /**
      * @see {@link actors.PullRequestActor#processPullRequestMerging(models.PullRequestEventMessage, models.PullRequest)}
      */
@@ -1071,5 +1097,4 @@
 
         return find.setRawSql(RawSqlBuilder.parse(sql).create()).findList().size();
     }
-
 }
app/models/PullRequestCommit.java
--- app/models/PullRequestCommit.java
+++ app/models/PullRequestCommit.java
@@ -23,6 +23,7 @@
 import java.util.Date;
 import java.util.List;
 
+import javax.annotation.Nonnull;
 import javax.persistence.Entity;
 import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
@@ -30,6 +31,7 @@
 import javax.persistence.ManyToOne;
 import javax.persistence.Transient;
 
+import org.apache.commons.lang3.StringUtils;
 import play.db.ebean.Model;
 import playRepository.GitCommit;
 import utils.JodaDateUtil;
@@ -69,6 +71,23 @@
         return commitMessage;
     }
 
+    public @Nonnull String getCommitShortMessage() {
+        if (StringUtils.isEmpty(commitMessage)) {
+            return "";
+        }
+
+        if (!commitMessage.contains("\n")) {
+            return commitMessage;
+        }
+
+        String[] segments = commitMessage.split("\n");
+        if (segments.length > 0) {
+            return segments[0];
+        }
+
+        return "";
+    }
+
     public String getCommitId() {
         return commitId;
     }
conf/messages
--- conf/messages
+++ conf/messages
@@ -370,6 +370,7 @@
 notification.organization.type.member.enroll = Requests for joining group
 notification.pullrequest.closed = Pull Request closed
 notification.pullrequest.conflicts = Pull Request conflicts
+notification.pullrequest.current.commits = Current Pull Request Commits
 notification.pullrequest.merged = Pull Request merged
 notification.pullrequest.reopened = Pull Request has been reopened
 notification.pullrequest.reviewed = {0} completed a review on pull request.
conf/messages.ko
--- conf/messages.ko
+++ conf/messages.ko
@@ -370,6 +370,7 @@
 notification.organization.type.member.enroll = 멤버 등록 요청
 notification.pullrequest.closed = 코드 주고받기 닫힘(closed)
 notification.pullrequest.conflicts = 충돌이 발생
+notification.pullrequest.current.commits = 현재 커밋 목록
 notification.pullrequest.merged = 보낸 코드가 반영됨(merged)
 notification.pullrequest.reopened = 코드 주고받기 다시 열림
 notification.pullrequest.reviewed = {0} 님이 리뷰를 완료했습니다.
Add a comment
List