@@ -4,6 +4,8 @@ import gitbucket.core.controller.Context
4
4
import gitbucket .core .model .{Account , Issue }
5
5
import gitbucket .core .service ._
6
6
import RepositoryService .RepositoryInfo
7
+ import gitbucket .core
8
+ import gitbucket .core .model
7
9
import gitbucket .core .util .{LDAPUtil , Mailer }
8
10
import gitbucket .core .view .Markdown
9
11
import gitbucket .notifications .model .Profile ._
@@ -12,7 +14,7 @@ import profile.blockingApi._
12
14
13
15
import scala .concurrent .Future
14
16
import scala .concurrent .ExecutionContext .Implicits .global
15
- import scala .util .{Success , Failure }
17
+ import scala .util .{Failure , Success }
16
18
17
19
18
20
class AccountHook extends gitbucket.core.plugin.AccountHook {
@@ -59,7 +61,8 @@ class IssueHook extends gitbucket.core.plugin.IssueHook
59
61
with IssuesService
60
62
with LabelsService
61
63
with PrioritiesService
62
- with MilestonesService {
64
+ with MilestonesService
65
+ with SystemSettingsService {
63
66
64
67
private val logger = LoggerFactory .getLogger(classOf [IssueHook ])
65
68
@@ -102,6 +105,24 @@ class IssueHook extends gitbucket.core.plugin.IssueHook
102
105
sendAsync(issue, r, subject(issue, r), markdown)
103
106
}
104
107
108
+ override def assigned (issue : Issue , r : RepositoryInfo , assigner : Option [String ], assigned : Option [String ], oldAssigned : Option [String ])(implicit session : model.Profile .profile.api.Session , context : Context ): Unit = {
109
+ val assignerMessage = assigner.flatMap(getAccountByUserName(_)).map(a => s " ${a.fullName}(@ ${a.userName}) " ).getOrElse(" unknown user" )
110
+ val assignedMessage = assigned.flatMap(getAccountByUserName(_)).map(a => s " ${a.fullName}(@ ${a.userName}) " ).getOrElse(" not assigned" )
111
+ val oldAssignedMessage = oldAssigned.flatMap(getAccountByUserName(_, true )).map(a => s " ${a.fullName}(@ ${a.userName}) " ).getOrElse(" not assigned" )
112
+ val markdown =
113
+ s """ assigned from ${oldAssignedMessage} to ${assignedMessage} by ${assignerMessage}
114
+ | """ .stripMargin
115
+ sendAsync(issue, r, subject(issue, r), markdown)
116
+ }
117
+
118
+ override def closedByCommitComment (issue : Issue , r : RepositoryInfo , commitMessage : String , pusher : Account )(implicit session : core.model.Profile .profile.api.Session ): Unit = {
119
+ val settings = loadSystemSettings()
120
+ val message = s """ |close #[ ${issue.issueId}]( ${s " ${settings.baseUrl}/ ${r.owner}/ ${r.name}/issues/ ${issue.issueId}" })
121
+ |
122
+ | ${commitMessage}""" .stripMargin
123
+ println(message)
124
+ sendAsyncTextOnly(issue, r, subject(issue, r), message, pusher, settings)
125
+ }
105
126
106
127
protected def subject (issue : Issue , r : RepositoryInfo ): String = {
107
128
s " [ ${r.owner}/ ${r.name}] ${issue.title} (# ${issue.issueId}) "
@@ -117,6 +138,21 @@ class IssueHook extends gitbucket.core.plugin.IssueHook
117
138
enableLineBreaks = false
118
139
)
119
140
141
+ protected def sendAsyncTextOnly (issue : Issue , repository : RepositoryInfo , subject : String , message : String , senderAccount : Account , settings : SystemSettingsService .SystemSettings )(implicit session: Session ): Unit = {
142
+ val recipients = getRecipients(issue, senderAccount)
143
+ val mailer = new Mailer (settings)
144
+ val f = Future {
145
+ recipients.foreach { address =>
146
+ mailer.send(address, subject, message, None , Some (senderAccount))
147
+ }
148
+ " Notifications Successful."
149
+ }
150
+ f.onComplete {
151
+ case Success (s) => logger.debug(s)
152
+ case Failure (t) => logger.error(" Notifications Failed." , t)
153
+ }
154
+ }
155
+
120
156
protected def sendAsync (issue : Issue , repository : RepositoryInfo , subject : String , markdown : String )
121
157
(implicit session : Session , context : Context ): Unit = {
122
158
val recipients = getRecipients(issue, context.loginAccount.get)
0 commit comments