From 27a205d81647c9df3c6c04f36062b87987d5ae99 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 8 May 2022 06:19:10 +0200 Subject: Format 'issue created' email Include a selection of metadata values in the email. I needed to pass `config` to `deliver-email` in order to be able to build a URL to the ticket based on the `endpoint` field. Also needed to make the field list a vector instead of a list, otherwise 'jzon' interpreted it as being a plist and serialized it to a JSON object. --- src/email.lisp | 29 +++++++++++++++++++++++------ src/main.lisp | 17 +++++++++-------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/email.lisp b/src/email.lisp index c877eda..9e5929c 100644 --- a/src/email.lisp +++ b/src/email.lisp @@ -1,12 +1,12 @@ (in-package :wajir) -(defun deliver-email (recipient issue) +(defun deliver-email (config issue) (cl-smtp:write-rfc8822-message *standard-output* (format nil "wajir@~A" (uiop:hostname)) - `(,recipient) + `(,(email-to config)) (format-subject issue) - (format-description issue))) + (format-body issue (endpoint config)))) (defun format-subject (issue) (format nil @@ -15,6 +15,23 @@ (gethash "summary" (gethash "fields" issue)))) -(defun format-description (issue) - (gethash "description" - (gethash "fields" issue))) +(defun format-body (issue endpoint) + (let ((fields (gethash "fields" issue))) + (format nil + "~A created ~A:~%~%Summary: ~A~%Key: ~A~%URL: ~A~%Project: ~A~%Issue Type: ~A~%Reporter: ~A~%~%~%~A" + (gethash "displayName" + (gethash "creator" fields)) + (gethash "key" issue) + (gethash "summary" fields) + (gethash "key" issue) + (format nil + "https://~A/browse/~A" + endpoint + (gethash "key" issue)) + (gethash "name" + (gethash "project" fields)) + (gethash "name" + (gethash "issuetype" fields)) + (gethash "displayName" + (gethash "reporter" fields)) + (gethash "description" fields)))) diff --git a/src/main.lisp b/src/main.lisp index e48cf34..7c0f368 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -66,13 +66,14 @@ :content (jzon:stringify `((:jql . ,jql) - (:fields . ("id" - "key" - "project" - "summary" - "description" - "issuetype" - "reporter")) + (:fields . #("id" + "key" + "project" + "summary" + "description" + "issuetype" + "creator" + "reporter")) (:|startAt| . ,start-at))) :headers `((:content-type . "application/json") (:authorization @@ -83,4 +84,4 @@ ;; 2. Send email (format t "Watching issue ~A~%" (gethash "key" issue)) - (deliver-email (email-to config) issue)) + (deliver-email config issue)) -- cgit v1.2.3