Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Added notification event after the pulll-request's commits are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Keesun Baik committed Feb 26, 2015
1 parent f798de7 commit aca8b34
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/actors/PullRequestActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -36,6 +38,7 @@ protected void processPullRequestMerging(PullRequestEventMessage message, PullRe

if (mergeResult.hasDiffCommits()) {
mergeResult.saveCommits();
NotificationEvent.afterPullRequestCommitChanged(message.getSender(), pullRequest);
if (!mergeResult.getNewCommits().isEmpty()) {
PullRequestEvent.addCommitEvents(message.getSender(), pullRequest,
mergeResult.getNewCommits(),
Expand Down
27 changes: 26 additions & 1 deletion app/models/NotificationEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,32 @@ public static NotificationEvent afterPullRequestUpdated(User sender, PullRequest
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)}
*/
Expand Down Expand Up @@ -1071,5 +1097,4 @@ public static int getNotificationsCount(User user) {

return find.setRawSql(RawSqlBuilder.parse(sql).create()).findList().size();
}

}
19 changes: 19 additions & 0 deletions app/models/PullRequestCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import java.util.Date;
import java.util.List;

import javax.annotation.Nonnull;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
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;
Expand Down Expand Up @@ -69,6 +71,23 @@ public String getCommitMessage() {
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;
}
Expand Down
1 change: 1 addition & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ notification.organization.member.request.title = [{0}] {1} wants to join your gr
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.
Expand Down
1 change: 1 addition & 0 deletions conf/messages.ko
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ notification.organization.member.request.title = [{0}] {1} 님이 멤버 요청
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} 님이 리뷰를 완료했습니다.
Expand Down

0 comments on commit aca8b34

Please sign in to comment.