Skip to content

Commit 1df701f

Browse files
mrsdizzielunny
authored andcommitted
Add ActionCommentPull action (#9456)
* Add ActionCommentPull action Adds ActionCommentPull action to distinguish between a comment on an issue and on a pull request * Update modules/notification/action/action.go Co-authored-by: Lunny Xiao <[email protected]>
1 parent 875d6b2 commit 1df701f

File tree

9 files changed

+18
-9
lines changed

9 files changed

+18
-9
lines changed

models/action.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const (
5050
ActionMirrorSyncDelete // 20
5151
ActionApprovePullRequest // 21
5252
ActionRejectPullRequest // 22
53+
ActionCommentPull // 23
5354
)
5455

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

models/repo_watch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func notifyWatchers(e Engine, act *Action) error {
210210
if !act.Repo.checkUnitUser(e, act.UserID, false, UnitTypeIssues) {
211211
continue
212212
}
213-
case ActionCreatePullRequest, ActionMergePullRequest, ActionClosePullRequest, ActionReopenPullRequest:
213+
case ActionCreatePullRequest, ActionCommentPull, ActionMergePullRequest, ActionClosePullRequest, ActionReopenPullRequest:
214214
if !act.Repo.checkUnitUser(e, act.UserID, false, UnitTypePullRequests) {
215215
continue
216216
}

modules/notification/action/action.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *models.User, issue *model
9090
func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
9191
issue *models.Issue, comment *models.Comment) {
9292
act := &models.Action{
93-
OpType: models.ActionCommentIssue,
9493
ActUserID: doer.ID,
9594
ActUser: doer,
9695
Content: fmt.Sprintf("%d|%s", issue.Index, comment.Content),
@@ -100,6 +99,11 @@ func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *model
10099
CommentID: comment.ID,
101100
IsPrivate: issue.Repo.IsPrivate,
102101
}
102+
if issue.IsPull {
103+
act.OpType = models.ActionCommentPull
104+
} else {
105+
act.OpType = models.ActionCommentIssue
106+
}
103107

104108
// Notify watchers for whatever action comes in, ignore if no action type.
105109
if err := models.NotifyWatchers(act); err != nil {
@@ -208,7 +212,7 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
208212
ActUserID: review.Reviewer.ID,
209213
ActUser: review.Reviewer,
210214
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comm.Content, "\n")[0]),
211-
OpType: models.ActionCommentIssue,
215+
OpType: models.ActionCommentPull,
212216
RepoID: review.Issue.RepoID,
213217
Repo: review.Issue.Repo,
214218
IsPrivate: review.Issue.Repo.IsPrivate,
@@ -237,7 +241,7 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
237241
case models.ReviewTypeReject:
238242
action.OpType = models.ActionRejectPullRequest
239243
default:
240-
action.OpType = models.ActionCommentIssue
244+
action.OpType = models.ActionCommentPull
241245
}
242246

243247
actions = append(actions, action)

modules/notification/mail/mail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models
8585
} else if comment.Type == models.CommentTypeReopen {
8686
act = models.ActionReopenIssue
8787
} else if comment.Type == models.CommentTypeComment {
88-
act = models.ActionCommentIssue
88+
act = models.ActionCommentPull
8989
}
9090
if err := mailer.MailParticipantsComment(comment, act, pr.Issue); err != nil {
9191
log.Error("MailParticipantsComment: %v", err)

modules/templates/helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ func ActionIcon(opType models.ActionType) string {
548548
return "issue-opened"
549549
case models.ActionCreatePullRequest:
550550
return "git-pull-request"
551-
case models.ActionCommentIssue:
551+
case models.ActionCommentIssue, models.ActionCommentPull:
552552
return "comment-discussion"
553553
case models.ActionMergePullRequest:
554554
return "git-merge"

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ create_pull_request = `created pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
20472047
close_pull_request = `closed pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
20482048
reopen_pull_request = `reopened pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
20492049
comment_issue = `commented on issue <a href="%s/issues/%s">%s#%[2]s</a>`
2050+
comment_pull = `commented on pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
20502051
merge_pull_request = `merged pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
20512052
transfer_repo = transferred repository <code>%s</code> to <a href="%s">%s</a>
20522053
push_tag = pushed tag <a href="%s/src/tag/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a>

services/mailer/mail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func actionToTemplate(issue *models.Issue, actionType models.ActionType,
291291
switch actionType {
292292
case models.ActionCreateIssue, models.ActionCreatePullRequest:
293293
name = "new"
294-
case models.ActionCommentIssue:
294+
case models.ActionCommentIssue, models.ActionCommentPull:
295295
name = "comment"
296296
case models.ActionCloseIssue, models.ActionClosePullRequest:
297297
name = "close"

services/mailer/mail_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestTemplateSelection(t *testing.T) {
153153

154154
pull := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
155155
comment = models.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
156-
msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: pull, Doer: doer, ActionType: models.ActionCommentIssue,
156+
msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
157157
Content: "test body", Comment: comment}, tos, false, "TestTemplateSelection")
158158
expect(t, msg, "pull/comment/subject", "pull/comment/body")
159159

templates/user/dashboard/feeds.tmpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
{{else if eq .GetOpType 22}}
6868
{{ $index := index .GetIssueInfos 0}}
6969
{{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}}
70+
{{else if eq .GetOpType 23}}
71+
{{ $index := index .GetIssueInfos 0}}
72+
{{$.i18n.Tr "action.comment_pull" .GetRepoLink $index .ShortRepoPath | Str2html}}
7073
{{end}}
7174
</p>
7275
{{if or (eq .GetOpType 5) (eq .GetOpType 18)}}
@@ -86,7 +89,7 @@
8689
<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
8790
{{else if eq .GetOpType 7}}
8891
<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
89-
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22)}}
92+
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}}
9093
<a href="{{.GetCommentLink}}" class="text truncate issue title has-emoji">{{.GetIssueTitle}}</a>
9194
<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
9295
{{else if eq .GetOpType 11}}

0 commit comments

Comments
 (0)