From 0100d2125a26467e062ffaf648f107b1423805ad Mon Sep 17 00:00:00 2001
From: jolheiser <john.olheiser@gmail.com>
Date: Thu, 14 Nov 2019 12:00:07 -0600
Subject: [PATCH 1/4] Update dashboard context for PR reviews

Signed-off-by: jolheiser <john.olheiser@gmail.com>
---
 models/action.go                      | 42 ++++++++++++++-------------
 modules/notification/action/action.go | 32 ++++++++++++--------
 modules/templates/helper.go           |  4 +++
 options/locale/locale_en-US.ini       |  4 ++-
 templates/user/dashboard/feeds.tmpl   |  8 ++++-
 5 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/models/action.go b/models/action.go
index ddb82e0f4c86b..3cd97eff09c14 100644
--- a/models/action.go
+++ b/models/action.go
@@ -30,26 +30,28 @@ type ActionType int
 
 // Possible action types.
 const (
-	ActionCreateRepo        ActionType = iota + 1 // 1
-	ActionRenameRepo                              // 2
-	ActionStarRepo                                // 3
-	ActionWatchRepo                               // 4
-	ActionCommitRepo                              // 5
-	ActionCreateIssue                             // 6
-	ActionCreatePullRequest                       // 7
-	ActionTransferRepo                            // 8
-	ActionPushTag                                 // 9
-	ActionCommentIssue                            // 10
-	ActionMergePullRequest                        // 11
-	ActionCloseIssue                              // 12
-	ActionReopenIssue                             // 13
-	ActionClosePullRequest                        // 14
-	ActionReopenPullRequest                       // 15
-	ActionDeleteTag                               // 16
-	ActionDeleteBranch                            // 17
-	ActionMirrorSyncPush                          // 18
-	ActionMirrorSyncCreate                        // 19
-	ActionMirrorSyncDelete                        // 20
+	ActionCreateRepo         ActionType = iota + 1 // 1
+	ActionRenameRepo                               // 2
+	ActionStarRepo                                 // 3
+	ActionWatchRepo                                // 4
+	ActionCommitRepo                               // 5
+	ActionCreateIssue                              // 6
+	ActionCreatePullRequest                        // 7
+	ActionTransferRepo                             // 8
+	ActionPushTag                                  // 9
+	ActionCommentIssue                             // 10
+	ActionMergePullRequest                         // 11
+	ActionCloseIssue                               // 12
+	ActionReopenIssue                              // 13
+	ActionClosePullRequest                         // 14
+	ActionReopenPullRequest                        // 15
+	ActionDeleteTag                                // 16
+	ActionDeleteBranch                             // 17
+	ActionMirrorSyncPush                           // 18
+	ActionMirrorSyncCreate                         // 19
+	ActionMirrorSyncDelete                         // 20
+	ActionApprovePullRequest                       // 21
+	ActionRejectPullRequest                        // 22
 )
 
 // Action represents user operation type and other information to
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go
index 36035b864fecf..cef21750063de 100644
--- a/modules/notification/action/action.go
+++ b/modules/notification/action/action.go
@@ -148,20 +148,28 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
 		}
 	}
 
-	if strings.TrimSpace(comment.Content) != "" {
-		actions = append(actions, &models.Action{
-			ActUserID: review.Reviewer.ID,
-			ActUser:   review.Reviewer,
-			Content:   fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
-			OpType:    models.ActionCommentIssue,
-			RepoID:    review.Issue.RepoID,
-			Repo:      review.Issue.Repo,
-			IsPrivate: review.Issue.Repo.IsPrivate,
-			Comment:   comment,
-			CommentID: comment.ID,
-		})
+	action := &models.Action{
+		ActUserID: review.Reviewer.ID,
+		ActUser:   review.Reviewer,
+		Content:   fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
+		RepoID:    review.Issue.RepoID,
+		Repo:      review.Issue.Repo,
+		IsPrivate: review.Issue.Repo.IsPrivate,
+		Comment:   comment,
+		CommentID: comment.ID,
 	}
 
+	switch review.Type {
+	case models.ReviewTypeApprove:
+		action.OpType = models.ActionApprovePullRequest
+	case models.ReviewTypeReject:
+		action.OpType = models.ActionRejectPullRequest
+	default:
+		action.OpType = models.ActionCommentIssue
+	}
+
+	actions = append(actions, action)
+
 	if err := models.NotifyWatchersActions(actions); err != nil {
 		log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)
 	}
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 1347835b808ac..6aa429ee142c4 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -555,6 +555,10 @@ func ActionIcon(opType models.ActionType) string {
 		return "issue-reopened"
 	case models.ActionMirrorSyncPush, models.ActionMirrorSyncCreate, models.ActionMirrorSyncDelete:
 		return "repo-clone"
+	case models.ActionApprovePullRequest:
+		return "eye"
+	case models.ActionRejectPullRequest:
+		return "x"
 	default:
 		return "invalid type"
 	}
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index e3e0dba9fecda..8f3ff99263bad 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -582,7 +582,7 @@ email_notifications.submit = Set Email Preference
 owner = Owner
 repo_name = Repository Name
 repo_name_helper = Good repository names use short, memorable and unique keywords.
-repo_size = Repository Size 
+repo_size = Repository Size
 template = Template
 template_select = Select a template.
 template_helper = Make repository a template
@@ -2000,6 +2000,8 @@ compare_commits_general = Compare commits
 mirror_sync_push = synced commits to <a href="%[1]s/src/%[2]s">%[3]s</a> at <a href="%[1]s">%[4]s</a> from mirror
 mirror_sync_create = synced new reference <a href="%s/src/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a> from mirror
 mirror_sync_delete = synced and deleted reference <code>%[2]s</code> at <a href="%[1]s">%[3]s</a> from mirror
+approve_pull_request = `approved <a href="%s/issues/%s">%s#%[2]s</a>`
+reject_pull_request = `suggested changes for <a href="%s/issues/%s">%s#%[2]s</a>`
 
 [tool]
 ago = %s ago
diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl
index 9c404c9fde26e..48cdb49c15de3 100644
--- a/templates/user/dashboard/feeds.tmpl
+++ b/templates/user/dashboard/feeds.tmpl
@@ -61,6 +61,12 @@
 							{{$.i18n.Tr "action.mirror_sync_create" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}}
 						{{else if eq .GetOpType 20}}
 							{{$.i18n.Tr "action.mirror_sync_delete" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}}
+						{{else if eq .GetOpType 21}}
+							{{ $index := index .GetIssueInfos 0}}
+							{{$.i18n.Tr "action.approve_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}}
+						{{else if eq .GetOpType 22}}
+							{{ $index := index .GetIssueInfos 0}}
+							{{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}}
 						{{end}}
 					</p>
 					{{if or (eq .GetOpType 5) (eq .GetOpType 18)}}
@@ -80,7 +86,7 @@
 						<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
 					{{else if eq .GetOpType 7}}
 						<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
-					{{else if eq .GetOpType 10}}
+					{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22)}}
 						<a href="{{.GetCommentLink}}" class="text truncate issue title has-emoji">{{.GetIssueTitle}}</a>
 						<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
 					{{else if eq .GetOpType 11}}

From 34236ea7822cd5ffc05e68a0255eeb82855515d9 Mon Sep 17 00:00:00 2001
From: John Olheiser <42128690+jolheiser@users.noreply.github.com>
Date: Thu, 14 Nov 2019 14:01:55 -0600
Subject: [PATCH 2/4] Update options/locale/locale_en-US.ini

Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
---
 options/locale/locale_en-US.ini | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 8f3ff99263bad..b8943f3c14c95 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -2000,7 +2000,7 @@ compare_commits_general = Compare commits
 mirror_sync_push = synced commits to <a href="%[1]s/src/%[2]s">%[3]s</a> at <a href="%[1]s">%[4]s</a> from mirror
 mirror_sync_create = synced new reference <a href="%s/src/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a> from mirror
 mirror_sync_delete = synced and deleted reference <code>%[2]s</code> at <a href="%[1]s">%[3]s</a> from mirror
-approve_pull_request = `approved <a href="%s/issues/%s">%s#%[2]s</a>`
+approve_pull_request = `approved <a href="%s/pulls/%s">%s#%[2]s</a>`
 reject_pull_request = `suggested changes for <a href="%s/issues/%s">%s#%[2]s</a>`
 
 [tool]

From 8c8a0a6e4bc195a9b1158d097b3cc895dd7753d7 Mon Sep 17 00:00:00 2001
From: jolheiser <john.olheiser@gmail.com>
Date: Thu, 14 Nov 2019 14:22:47 -0600
Subject: [PATCH 3/4] Only append head action if it has content or is
 approval/rejection

Signed-off-by: jolheiser <john.olheiser@gmail.com>
---
 modules/notification/action/action.go | 40 ++++++++++++++-------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go
index cef21750063de..d4be1e43041b1 100644
--- a/modules/notification/action/action.go
+++ b/modules/notification/action/action.go
@@ -148,27 +148,29 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
 		}
 	}
 
-	action := &models.Action{
-		ActUserID: review.Reviewer.ID,
-		ActUser:   review.Reviewer,
-		Content:   fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
-		RepoID:    review.Issue.RepoID,
-		Repo:      review.Issue.Repo,
-		IsPrivate: review.Issue.Repo.IsPrivate,
-		Comment:   comment,
-		CommentID: comment.ID,
-	}
+	if review.Type != models.ReviewTypeComment || strings.TrimSpace(comment.Content) != "" {
+		action := &models.Action{
+			ActUserID: review.Reviewer.ID,
+			ActUser:   review.Reviewer,
+			Content:   fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
+			RepoID:    review.Issue.RepoID,
+			Repo:      review.Issue.Repo,
+			IsPrivate: review.Issue.Repo.IsPrivate,
+			Comment:   comment,
+			CommentID: comment.ID,
+		}
 
-	switch review.Type {
-	case models.ReviewTypeApprove:
-		action.OpType = models.ActionApprovePullRequest
-	case models.ReviewTypeReject:
-		action.OpType = models.ActionRejectPullRequest
-	default:
-		action.OpType = models.ActionCommentIssue
-	}
+		switch review.Type {
+		case models.ReviewTypeApprove:
+			action.OpType = models.ActionApprovePullRequest
+		case models.ReviewTypeReject:
+			action.OpType = models.ActionRejectPullRequest
+		default:
+			action.OpType = models.ActionCommentIssue
+		}
 
-	actions = append(actions, action)
+		actions = append(actions, action)
+	}
 
 	if err := models.NotifyWatchersActions(actions); err != nil {
 		log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)

From 574ae4ff4b760427105d637b35f37beebd19b60d Mon Sep 17 00:00:00 2001
From: John Olheiser <42128690+jolheiser@users.noreply.github.com>
Date: Thu, 14 Nov 2019 14:26:37 -0600
Subject: [PATCH 4/4] Update options/locale/locale_en-US.ini

Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
---
 options/locale/locale_en-US.ini | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index b8943f3c14c95..883b9222f5385 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -2001,7 +2001,7 @@ mirror_sync_push = synced commits to <a href="%[1]s/src/%[2]s">%[3]s</a> at <a h
 mirror_sync_create = synced new reference <a href="%s/src/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a> from mirror
 mirror_sync_delete = synced and deleted reference <code>%[2]s</code> at <a href="%[1]s">%[3]s</a> from mirror
 approve_pull_request = `approved <a href="%s/pulls/%s">%s#%[2]s</a>`
-reject_pull_request = `suggested changes for <a href="%s/issues/%s">%s#%[2]s</a>`
+reject_pull_request = `suggested changes for <a href="%s/pulls/%s">%s#%[2]s</a>`
 
 [tool]
 ago = %s ago