feat(panettone): Send emails when issues are closed

Send notification emails to the same group of users who receive
notifications on issue comments when issues are marked as closed. This
also takes the opportunity to generalize issue notification emails a
bit, and lay the groundwork for (but not implement) explicit issue
subscriber lists.

Change-Id: Ie2572ed3ad0207d415b4c362438f772925e7a2c5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2807
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Griffin Smith 2021-04-03 14:40:33 -04:00 committed by glittershark
parent 3ec15ec9f9
commit 606d2af2da
3 changed files with 42 additions and 18 deletions

View file

@ -409,6 +409,20 @@
;;; HTTP handlers
;;;
(defun send-email-for-issue
(issue-id &key subject (message ""))
"Send an email notification to all subscribers to the given issue with the
given subject an body (in a thread, to avoid blocking)"
(let ((current-user *user*))
(model:make-thread
(lambda ()
(dolist (user-dn (model:issue-subscribers issue-id))
(when (not (equal (dn current-user) user-dn))
(email:notify-user
user-dn
:subject subject
:message message)))))))
(defun @auth-optional (next)
(let ((*user* (hunchentoot:session-value 'user)))
(funcall next)))
@ -550,22 +564,13 @@
:body body
:author-dn (dn *user*))
;; Send email notifications (in a thread, since smtp is slow)
(let ((current-user *user*))
(model:make-thread
(lambda ()
(let ((issue (model:get-issue id)))
(dolist (user-dn (remove-duplicates
(cons (author-dn issue)
(model:issue-commenter-dns id))
:test #'equal))
(when (not (equal (dn current-user) user-dn))
(email:notify-user
user-dn
:subject (format nil "~A commented on \"~A\""
(displayname current-user)
(subject issue))
:message body)))))))
(let ((issue (model:get-issue id)))
(send-email-for-issue
id
:subject (format nil "~A commented on \"~A\""
(displayname *user*)
(subject issue))
:message body))
(redirect-to-issue)))))
(defroute close-issue
@ -582,7 +587,12 @@
(irc:noping (cn *user*))
id)
:channel (or (uiop:getenvp "ISSUECHANNEL")
"##tvl-dev")))
"##tvl-dev"))
(send-email-for-issue
id
:subject (format nil "~A closed \"~A\""
(dn *user*)
(subject issue))))
(hunchentoot:redirect (format nil "/issues/~A" id)))
(defroute open-issue