Skip to content

Commit 06a8504

Browse files
jolheiserguillep2k
authored andcommitted
Update dashboard context for PR reviews (#8995)
* Update dashboard context for PR reviews Signed-off-by: jolheiser <[email protected]> * Update options/locale/locale_en-US.ini Co-Authored-By: guillep2k <[email protected]> * Only append head action if it has content or is approval/rejection Signed-off-by: jolheiser <[email protected]> * Update options/locale/locale_en-US.ini Co-Authored-By: guillep2k <[email protected]>
1 parent dd1beee commit 06a8504

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

models/action.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,28 @@ type ActionType int
3030

3131
// Possible action types.
3232
const (
33-
ActionCreateRepo ActionType = iota + 1 // 1
34-
ActionRenameRepo // 2
35-
ActionStarRepo // 3
36-
ActionWatchRepo // 4
37-
ActionCommitRepo // 5
38-
ActionCreateIssue // 6
39-
ActionCreatePullRequest // 7
40-
ActionTransferRepo // 8
41-
ActionPushTag // 9
42-
ActionCommentIssue // 10
43-
ActionMergePullRequest // 11
44-
ActionCloseIssue // 12
45-
ActionReopenIssue // 13
46-
ActionClosePullRequest // 14
47-
ActionReopenPullRequest // 15
48-
ActionDeleteTag // 16
49-
ActionDeleteBranch // 17
50-
ActionMirrorSyncPush // 18
51-
ActionMirrorSyncCreate // 19
52-
ActionMirrorSyncDelete // 20
33+
ActionCreateRepo ActionType = iota + 1 // 1
34+
ActionRenameRepo // 2
35+
ActionStarRepo // 3
36+
ActionWatchRepo // 4
37+
ActionCommitRepo // 5
38+
ActionCreateIssue // 6
39+
ActionCreatePullRequest // 7
40+
ActionTransferRepo // 8
41+
ActionPushTag // 9
42+
ActionCommentIssue // 10
43+
ActionMergePullRequest // 11
44+
ActionCloseIssue // 12
45+
ActionReopenIssue // 13
46+
ActionClosePullRequest // 14
47+
ActionReopenPullRequest // 15
48+
ActionDeleteTag // 16
49+
ActionDeleteBranch // 17
50+
ActionMirrorSyncPush // 18
51+
ActionMirrorSyncCreate // 19
52+
ActionMirrorSyncDelete // 20
53+
ActionApprovePullRequest // 21
54+
ActionRejectPullRequest // 22
5355
)
5456

5557
// Action represents user operation type and other information to

modules/notification/action/action.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,28 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
148148
}
149149
}
150150

151-
if strings.TrimSpace(comment.Content) != "" {
152-
actions = append(actions, &models.Action{
151+
if review.Type != models.ReviewTypeComment || strings.TrimSpace(comment.Content) != "" {
152+
action := &models.Action{
153153
ActUserID: review.Reviewer.ID,
154154
ActUser: review.Reviewer,
155155
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
156-
OpType: models.ActionCommentIssue,
157156
RepoID: review.Issue.RepoID,
158157
Repo: review.Issue.Repo,
159158
IsPrivate: review.Issue.Repo.IsPrivate,
160159
Comment: comment,
161160
CommentID: comment.ID,
162-
})
161+
}
162+
163+
switch review.Type {
164+
case models.ReviewTypeApprove:
165+
action.OpType = models.ActionApprovePullRequest
166+
case models.ReviewTypeReject:
167+
action.OpType = models.ActionRejectPullRequest
168+
default:
169+
action.OpType = models.ActionCommentIssue
170+
}
171+
172+
actions = append(actions, action)
163173
}
164174

165175
if err := models.NotifyWatchersActions(actions); err != nil {

modules/templates/helper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ func ActionIcon(opType models.ActionType) string {
555555
return "issue-reopened"
556556
case models.ActionMirrorSyncPush, models.ActionMirrorSyncCreate, models.ActionMirrorSyncDelete:
557557
return "repo-clone"
558+
case models.ActionApprovePullRequest:
559+
return "eye"
560+
case models.ActionRejectPullRequest:
561+
return "x"
558562
default:
559563
return "invalid type"
560564
}

options/locale/locale_en-US.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ email_notifications.submit = Set Email Preference
582582
owner = Owner
583583
repo_name = Repository Name
584584
repo_name_helper = Good repository names use short, memorable and unique keywords.
585-
repo_size = Repository Size
585+
repo_size = Repository Size
586586
template = Template
587587
template_select = Select a template.
588588
template_helper = Make repository a template
@@ -2000,6 +2000,8 @@ compare_commits_general = Compare commits
20002000
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
20012001
mirror_sync_create = synced new reference <a href="%s/src/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a> from mirror
20022002
mirror_sync_delete = synced and deleted reference <code>%[2]s</code> at <a href="%[1]s">%[3]s</a> from mirror
2003+
approve_pull_request = `approved <a href="%s/pulls/%s">%s#%[2]s</a>`
2004+
reject_pull_request = `suggested changes for <a href="%s/pulls/%s">%s#%[2]s</a>`
20032005

20042006
[tool]
20052007
ago = %s ago

templates/user/dashboard/feeds.tmpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
{{$.i18n.Tr "action.mirror_sync_create" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}}
6262
{{else if eq .GetOpType 20}}
6363
{{$.i18n.Tr "action.mirror_sync_delete" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}}
64+
{{else if eq .GetOpType 21}}
65+
{{ $index := index .GetIssueInfos 0}}
66+
{{$.i18n.Tr "action.approve_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}}
67+
{{else if eq .GetOpType 22}}
68+
{{ $index := index .GetIssueInfos 0}}
69+
{{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}}
6470
{{end}}
6571
</p>
6672
{{if or (eq .GetOpType 5) (eq .GetOpType 18)}}
@@ -80,7 +86,7 @@
8086
<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
8187
{{else if eq .GetOpType 7}}
8288
<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
83-
{{else if eq .GetOpType 10}}
89+
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22)}}
8490
<a href="{{.GetCommentLink}}" class="text truncate issue title has-emoji">{{.GetIssueTitle}}</a>
8591
<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
8692
{{else if eq .GetOpType 11}}

0 commit comments

Comments
 (0)