diff --git a/src/main/scala/gitbucket/core/controller/IssuesController.scala b/src/main/scala/gitbucket/core/controller/IssuesController.scala index 4f9c810..80c450b 100644 --- a/src/main/scala/gitbucket/core/controller/IssuesController.scala +++ b/src/main/scala/gitbucket/core/controller/IssuesController.scala @@ -132,11 +132,11 @@ // call web hooks callIssuesWebHook("opened", repository, issue, context.baseUrl, context.loginAccount.get) - } - // notifications - Notifier().toNotify(repository, issueId, form.content.getOrElse("")){ - Notifier.msgIssue(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}") + // notifications + Notifier().toNotify(repository, issue, form.content.getOrElse("")){ + Notifier.msgIssue(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}") + } } redirect(s"/${owner}/${name}/issues/${issueId}") @@ -418,13 +418,13 @@ Notifier() match { case f => content foreach { - f.toNotify(repository, issueId, _){ + f.toNotify(repository, issue, _){ Notifier.msgComment(s"${context.baseUrl}/${owner}/${name}/${ if(issue.isPullRequest) "pull" else "issues"}/${issueId}#comment-${commentId.get}") } } action foreach { - f.toNotify(repository, issueId, _){ + f.toNotify(repository, issue, _){ Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}") } } diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala index 885f931..5c6d6dd 100644 --- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala +++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala @@ -236,7 +236,7 @@ callPullRequestWebHook("closed", repository, issueId, context.baseUrl, context.loginAccount.get) // notifications - Notifier().toNotify(repository, issueId, "merge"){ + Notifier().toNotify(repository, issue, "merge"){ Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}") } @@ -395,8 +395,10 @@ callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get) // notifications - Notifier().toNotify(repository, issueId, form.content.getOrElse("")){ - Notifier.msgPullRequest(s"${context.baseUrl}/${repository.owner}/${repository.name}/pull/${issueId}") + getIssue(repository.owner, repository.name, issueId.toString) foreach { issue => + Notifier().toNotify(repository, issue, form.content.getOrElse("")){ + Notifier.msgPullRequest(s"${context.baseUrl}/${repository.owner}/${repository.name}/pull/${issueId}") + } } redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}") diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 9e80917..b7dbbe8 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -15,7 +15,7 @@ import ControlUtil.defining trait Notifier extends RepositoryService with AccountService with IssuesService { - def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String) + def toNotify(r: RepositoryService.RepositoryInfo, issue: Issue, content: String) (msg: String => String)(implicit context: Context): Unit protected def recipients(issue: Issue)(notify: String => Unit)(implicit session: Session, context: Context) = @@ -67,16 +67,15 @@ class Mailer(private val smtp: Smtp) extends Notifier { private val logger = LoggerFactory.getLogger(classOf[Mailer]) - def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String) + def toNotify(r: RepositoryService.RepositoryInfo, issue: Issue, content: String) (msg: String => String)(implicit context: Context) = { val database = Database() val f = Future { database withSession { implicit session => - getIssue(r.owner, r.name, issueId.toString) foreach { issue => - defining( - s"[${r.name}] ${issue.title} (#${issueId})" -> - msg(Markdown.toHtml(content, r, false, true))) { case (subject, msg) => + defining( + s"[${r.name}] ${issue.title} (#${issue.issueId})" -> + msg(Markdown.toHtml(content, r, false, true))) { case (subject, msg) => recipients(issue) { to => val email = new HtmlEmail email.setHostName(smtp.host) @@ -92,14 +91,13 @@ .orElse (Some("notifications@gitbucket.com" -> context.loginAccount.get.userName)) .foreach { case (address, name) => email.setFrom(address, name) - } + } email.setCharset("UTF-8") email.setSubject(subject) email.setHtmlMsg(msg) email.addTo(to).send } - } } } "Notifications Successful." @@ -113,6 +111,6 @@ } } class MockMailer extends Notifier { - def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String) + def toNotify(r: RepositoryService.RepositoryInfo, issue: Issue, content: String) (msg: String => String)(implicit context: Context): Unit = {} }