aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2022-05-08 05:07:39 +0200
committerTeddy Wing2022-05-08 05:07:39 +0200
commit22461379250147870550d4d9cd43dc67f65892a9 (patch)
tree8c9a66ff3c071868b86c81528c896c1e196f2130
parent8d98dd58afdbf659b6c246f158451cd8c850acb8 (diff)
downloadwajir-22461379250147870550d4d9cd43dc67f65892a9.tar.bz2
Start of email building
Take a recipient email address. Build an email containing the issue details. Change the `run` loop to only operate on a single issue for testing purposes.
-rw-r--r--src/config.lisp6
-rw-r--r--src/email.lisp20
-rw-r--r--src/main.lisp17
-rw-r--r--wajir.asd2
4 files changed, 40 insertions, 5 deletions
diff --git a/src/config.lisp b/src/config.lisp
index 82d3865..0bc6fee 100644
--- a/src/config.lisp
+++ b/src/config.lisp
@@ -13,6 +13,12 @@
:initarg :endpoint
:reader endpoint
:documentation "Jira site URL (e.g. example.atlassian.net)")
+
+ (email-to
+ :initarg :email-to
+ :reader email-to
+ :documentation "Email recipient")
+
(jql
:initarg :jql
:reader jql
diff --git a/src/email.lisp b/src/email.lisp
new file mode 100644
index 0000000..c877eda
--- /dev/null
+++ b/src/email.lisp
@@ -0,0 +1,20 @@
+(in-package :wajir)
+
+(defun deliver-email (recipient issue)
+ (cl-smtp:write-rfc8822-message
+ *standard-output*
+ (format nil "wajir@~A" (uiop:hostname))
+ `(,recipient)
+ (format-subject issue)
+ (format-description issue)))
+
+(defun format-subject (issue)
+ (format nil
+ "[JIRA] (~A) ~A"
+ (gethash "key" issue)
+ (gethash "summary"
+ (gethash "fields" issue))))
+
+(defun format-description (issue)
+ (gethash "description"
+ (gethash "fields" issue)))
diff --git a/src/main.lisp b/src/main.lisp
index d15ab6e..e48cf34 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -11,6 +11,7 @@
:login "name@example.com"
:token "atlassian-token"
:endpoint "example.atlassian.net"
+ :email-to "name@example.com"
:jql "project = \"FAKE\" AND watcher != currentUser() AND key > \"FAKE-100\" ORDER BY created DESC")))
(run config)))
@@ -41,9 +42,13 @@
total)
;; Watch each issue.
- (loop for issue
- across (gethash "issues" response)
- do (watch-issue issue))
+ ; (loop for issue
+ ; across (gethash "issues" response)
+ ; do (watch-issue config issue))
+ (let ((issue (aref (gethash "issues" response) 0)))
+ (watch-issue config issue)
+
+ (return))
;; Stop looping if we're on the last page of results.
(when (> start-at
@@ -73,7 +78,9 @@
(:authorization
. ,(format nil "Basic ~A" basic-auth-token))))))
-(defun watch-issue (issue)
+(defun watch-issue (config issue)
;; 1. Watch issue in Jira
;; 2. Send email
- (format t "Watching issue ~A~%" (gethash "key" issue)))
+ (format t "Watching issue ~A~%" (gethash "key" issue))
+
+ (deliver-email (email-to config) issue))
diff --git a/wajir.asd b/wajir.asd
index bcb8eb8..5d5c32d 100644
--- a/wajir.asd
+++ b/wajir.asd
@@ -13,12 +13,14 @@
(defsystem wajir
:version "0.0.1"
:depends-on (:cl-base64
+ :cl-smtp
:com.inuoe.jzon
:dexador)
:components ((:module "src"
:serial t
:components ((:file "package")
(:file "config")
+ (:file "email")
(:file "main"))))
:build-operation "program-op"