mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 09:55:49 +01:00
fix issue notifications
This commit is contained in:
@@ -132,11 +132,11 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
// call web hooks
|
// call web hooks
|
||||||
callIssuesWebHook("opened", repository, issue, context.baseUrl, context.loginAccount.get)
|
callIssuesWebHook("opened", repository, issue, context.baseUrl, context.loginAccount.get)
|
||||||
}
|
|
||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
|
Notifier().toNotify(repository, issue, form.content.getOrElse("")){
|
||||||
Notifier.msgIssue(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
Notifier.msgIssue(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${owner}/${name}/issues/${issueId}")
|
redirect(s"/${owner}/${name}/issues/${issueId}")
|
||||||
@@ -418,13 +418,13 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
Notifier() match {
|
Notifier() match {
|
||||||
case f =>
|
case f =>
|
||||||
content foreach {
|
content foreach {
|
||||||
f.toNotify(repository, issueId, _){
|
f.toNotify(repository, issue, _){
|
||||||
Notifier.msgComment(s"${context.baseUrl}/${owner}/${name}/${
|
Notifier.msgComment(s"${context.baseUrl}/${owner}/${name}/${
|
||||||
if(issue.isPullRequest) "pull" else "issues"}/${issueId}#comment-${commentId.get}")
|
if(issue.isPullRequest) "pull" else "issues"}/${issueId}#comment-${commentId.get}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action foreach {
|
action foreach {
|
||||||
f.toNotify(repository, issueId, _){
|
f.toNotify(repository, issue, _){
|
||||||
Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/issues/${issueId}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
callPullRequestWebHook("closed", repository, issueId, context.baseUrl, context.loginAccount.get)
|
callPullRequestWebHook("closed", repository, issueId, context.baseUrl, context.loginAccount.get)
|
||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
Notifier().toNotify(repository, issueId, "merge"){
|
Notifier().toNotify(repository, issue, "merge"){
|
||||||
Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}")
|
Notifier.msgStatus(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,8 +395,10 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get)
|
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get)
|
||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
|
getIssue(repository.owner, repository.name, issueId.toString) foreach { issue =>
|
||||||
Notifier.msgPullRequest(s"${context.baseUrl}/${repository.owner}/${repository.name}/pull/${issueId}")
|
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}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import SystemSettingsService.Smtp
|
|||||||
import ControlUtil.defining
|
import ControlUtil.defining
|
||||||
|
|
||||||
trait Notifier extends RepositoryService with AccountService with IssuesService {
|
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
|
(msg: String => String)(implicit context: Context): Unit
|
||||||
|
|
||||||
protected def recipients(issue: Issue)(notify: String => Unit)(implicit session: Session, context: Context) =
|
protected def recipients(issue: Issue)(notify: String => Unit)(implicit session: Session, context: Context) =
|
||||||
@@ -67,16 +67,15 @@ object Notifier {
|
|||||||
class Mailer(private val smtp: Smtp) extends Notifier {
|
class Mailer(private val smtp: Smtp) extends Notifier {
|
||||||
private val logger = LoggerFactory.getLogger(classOf[Mailer])
|
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) = {
|
(msg: String => String)(implicit context: Context) = {
|
||||||
val database = Database()
|
val database = Database()
|
||||||
|
|
||||||
val f = Future {
|
val f = Future {
|
||||||
database withSession { implicit session =>
|
database withSession { implicit session =>
|
||||||
getIssue(r.owner, r.name, issueId.toString) foreach { issue =>
|
defining(
|
||||||
defining(
|
s"[${r.name}] ${issue.title} (#${issue.issueId})" ->
|
||||||
s"[${r.name}] ${issue.title} (#${issueId})" ->
|
msg(Markdown.toHtml(content, r, false, true))) { case (subject, msg) =>
|
||||||
msg(Markdown.toHtml(content, r, false, true))) { case (subject, msg) =>
|
|
||||||
recipients(issue) { to =>
|
recipients(issue) { to =>
|
||||||
val email = new HtmlEmail
|
val email = new HtmlEmail
|
||||||
email.setHostName(smtp.host)
|
email.setHostName(smtp.host)
|
||||||
@@ -92,14 +91,13 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
.orElse (Some("notifications@gitbucket.com" -> context.loginAccount.get.userName))
|
.orElse (Some("notifications@gitbucket.com" -> context.loginAccount.get.userName))
|
||||||
.foreach { case (address, name) =>
|
.foreach { case (address, name) =>
|
||||||
email.setFrom(address, name)
|
email.setFrom(address, name)
|
||||||
}
|
}
|
||||||
email.setCharset("UTF-8")
|
email.setCharset("UTF-8")
|
||||||
email.setSubject(subject)
|
email.setSubject(subject)
|
||||||
email.setHtmlMsg(msg)
|
email.setHtmlMsg(msg)
|
||||||
|
|
||||||
email.addTo(to).send
|
email.addTo(to).send
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"Notifications Successful."
|
"Notifications Successful."
|
||||||
@@ -113,6 +111,6 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class MockMailer extends Notifier {
|
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 = {}
|
(msg: String => String)(implicit context: Context): Unit = {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user