git.fiddlerwoaroof.com
Browse code

Updating to use the new sheeple-based architecture

fiddlerwoaroof authored on 10/05/2016 16:01:48
Showing 4 changed files
... ...
@@ -1,7 +1,12 @@
1 1
 (in-package #:jira-api) 
2 2
 
3 3
 ; curl -u user:password https://atomampd.atlassian.net/rest/api/2/issue/ATOMOS-212 | jq .
4
-(defparameter *endpoint* "https://atomampd.atlassian.net/rest/api/2/")
4
+(defparameter *hostname* "https://atomampd.atlassian.net")
5
+(defparameter *endpoint* (princ-to-string (puri:merge-uris *hostname* "/rest/api/2/")))
6
+
7
+(defun update-hostname (new-subdomain)
8
+  (setf *hostname* (format nil "https://~a.atlassian.net" new-subdomain))
9
+  (setf *endpoint* (princ-to-string (puri:merge-uris "/rest/api/2/" *hostname*))))
5 10
 
6 11
 (defun api-get-call (auth method &rest parameters)
7 12
   "Connect to a GET REST endpoint specified by method and return a stream from
... ...
@@ -1,6 +1,4 @@
1 1
 ;;;; jira-api.lisp
2
-(declaim (optimize (debug 3)))
3
-
4 2
 (in-package #:jira-api)
5 3
 
6 4
 (defun get-issues (auth)
... ...
@@ -62,38 +60,11 @@
62 60
 (defun show-labels (labels)
63 61
   (format t "~&~4tLabels: ~{~a~}~%" (coerce labels 'list)))
64 62
 
65
-(defun show-description (description)
66
-  (pprint-logical-block (*standard-output* (mapcar (compose 'tokens 'trim-whitespace)
67
-                                                 (lines description)))
68
-    (pprint-indent :block 4 *standard-output*)
69
-    (pprint-newline :mandatory *standard-output*)
70
-    (loop
71
-      (pprint-exit-if-list-exhausted)
72
-      (let ((line (pprint-pop)))
73
-        (pprint-logical-block (*standard-output* line)
74
-          (loop
75
-            (princ (pprint-pop) *standard-output*)
76
-            (pprint-exit-if-list-exhausted)
77
-            (princ #\space *standard-output*)
78
-            (pprint-indent :block 3)
79
-            (pprint-newline :fill *standard-output*)))
80
-        (pprint-newline :mandatory *standard-output*)))))
81
-
82
-(defun show-summary (summary)
83
-  (pprint-logical-block (*standard-output* (funcall (compose 'tokens 'trim-whitespace) summary))
84
-    (pprint-indent :block 8 *standard-output*)
85
-    (pprint-exit-if-list-exhausted)
86
-    (format *standard-output* "~4tSummary: ")
87
-    (loop
88
-      (princ (pprint-pop))
89
-      (pprint-exit-if-list-exhausted)
90
-      (pprint-newline :fill *standard-output*)
91
-      (princ #\space))))
92
-
93 63
 (defun classify-issues (sheeple-issues &optional (classify-by '(status name)))
94 64
   (sheeple:with-properties (issues) sheeple-issues
95 65
     (loop with classes = (make-hash-table :test 'equalp)
96 66
           for issue across issues
67
+          do (ensure-parent issue =issue=)
97 68
           do (loop for classification in classify-by
98 69
                    for thing = (sheeple:property-value (fields issue) classification)
99 70
                        then (sheeple:property-value thing classification)
... ...
@@ -105,7 +76,13 @@
105 76
     (let* ((fields (fields issue))
106 77
            (status (name (status fields)))
107 78
            (summary (summary fields)))
108
-      (format t "~&~a ~a (~a)~%" self key status)
79
+
80
+      (format t "~&~a (~a) <~a>~%"
81
+              key
82
+              status 
83
+              (puri:merge-uris (format nil "/browse/~a" (key issue))
84
+                               *hostname*))
85
+
109 86
       (show-summary summary)
110 87
       (fresh-line))))
111 88
 
... ...
@@ -19,6 +19,12 @@
19 19
   (sheeple:with-properties (labels) fields
20 20
     labels))
21 21
 
22
+(sheeple:defproto =comment= () (self id author body))
23
+
24
+(sheeple:defreply sheeple:shared-init :after ((comment =comment=) &key)
25
+  (with-accessors ((author author)) issue
26
+      (ensure-parent author =person= :err-if-nil nil)))
27
+
22 28
 (sheeple:defreply sheeple:shared-init :after ((issue =issue=) &key)
23 29
   (with-accessors ((fields fields)) issue
24 30
     (when fields
... ...
@@ -26,7 +32,12 @@
26 32
       (ensure-parent (status fields) =status=)
27 33
       (ensure-parent (reporter fields) =person=)
28 34
       (ensure-parent (creator fields) =person=)
29
-      (ensure-parent (assignee fields) =person= :err-if-nil nil))))
35
+      (ensure-parent (assignee fields) =person= :err-if-nil nil)
36
+      (when (sheeple:direct-property-p issue 'comment) 
37
+        (sheeple:with-properties (comment) issue
38
+          (sheeple:with-properties (comments) comment
39
+            (map 'nil (lambda (comment) (ensure-parent comment =comment=))
40
+                 comments)))))))
30 41
 
31 42
 (sheeple:defreply show ((person =person=) &rest args)
32 43
   (declare (ignore args))
... ...
@@ -75,7 +86,8 @@
75 86
         (format t "~a (~a) <~a>~%"
76 87
                 (key issue)
77 88
                 (show status)
78
-                (self issue))
89
+                (princ-to-string (puri:merge-uris (format nil "/browse/~a" (key issue))
90
+                                                  *hostname*)))
79 91
 
80 92
         (show-summary summary)
81 93
 
... ...
@@ -63,40 +63,40 @@
63 63
   (setf *auth* (ubiquitous:value :jira :creds))
64 64
   (make-context)
65 65
 
66
-  (let ((jira-api::*endpoint* (format nil *endpoint-template* (getopt :long-name "jira-account"))))
67
-    (cond
68
-      ((getopt :long-name "help") (help))
69
-      ((getopt :long-name "version") (format t "~&~a~%" *version*))
70
-      ((getopt :long-name "dump-configuration") (dump-configuration))
71
-      ((getopt :long-name "configure") (let ((creds (prompt :creds))
72
-                                             (account (prompt :jira-account)))
73
-                                         (setf (ubiquitous:value :jira :creds) creds)
74
-                                         (setf (ubiquitous:value :jira :account) account)
75
-                                         (dump-configuration)))
76
-      ((getopt :long-name "get-issue") (let ((options (remainder)))
77
-                                         (format t "~&~a~&"
78
-                                                 (jira-api::show
79
-                                                   (jira-api::json2sheeple
80
-                                                     (jira-api::get-issue *auth*
81
-                                                                          (format nil "~a-~a"
82
-                                                                                  (car options)
83
-                                                                                  (cadr options)))
84
-                                                     jira-api::=issue=)))))
85
-      ((getopt :long-name "get-issues")
86
-       (let ((options (remainder)))
87
-         (let ((issues (jira-api::json2sheeple (jira-api::get-issues *auth*))))
88
-           (alexandria:if-let ((status (getopt :long-name "status")))
89
-             (setf issues
90
-                   (sheeple:defobject ()
91
-                                      ((jira-api::issues
92
-                                         (apply 'vector
93
-                                                (gethash status
94
-                                                         (jira-api::classify-issues issues))))))))
95
-           (jira-api::show-issues issues))))
96
-      ((getopt :long-name "list-projects") (jira-api::show-projects
97
-                                             (jira-api::json2sheeple
98
-                                               (jira-api::get-projects *auth*))))
99
-      ((getopt :long-name "post-issue") (yason:encode (jira-api::read-issue)))
100
-      (t  (help) (exit)))))
66
+  (jira-api::update-hostname (getopt :long-name "jira-account"))
67
+  (cond
68
+    ((getopt :long-name "help") (help))
69
+    ((getopt :long-name "version") (format t "~&~a~%" *version*))
70
+    ((getopt :long-name "dump-configuration") (dump-configuration))
71
+    ((getopt :long-name "configure") (let ((creds (prompt :creds))
72
+                                           (account (prompt :jira-account)))
73
+                                       (setf (ubiquitous:value :jira :creds) creds)
74
+                                       (setf (ubiquitous:value :jira :account) account)
75
+                                       (dump-configuration)))
76
+    ((getopt :long-name "get-issue") (let ((options (remainder)))
77
+                                       (format t "~&~a~&"
78
+                                               (jira-api::show
79
+                                                 (jira-api::json2sheeple
80
+                                                   (jira-api::get-issue *auth*
81
+                                                                        (format nil "~a-~a"
82
+                                                                                (car options)
83
+                                                                                (cadr options)))
84
+                                                   jira-api::=issue=)))))
85
+    ((getopt :long-name "get-issues")
86
+     (let ((options (remainder)))
87
+       (let ((issues (jira-api::json2sheeple (jira-api::get-issues *auth*))))
88
+         (alexandria:if-let ((status (getopt :long-name "status")))
89
+           (setf issues
90
+                 (sheeple:defobject ()
91
+                                    ((jira-api::issues
92
+                                       (apply 'vector
93
+                                              (gethash status
94
+                                                       (jira-api::classify-issues issues))))))))
95
+         (jira-api::show-issues issues))))
96
+    ((getopt :long-name "list-projects") (jira-api::show-projects
97
+                                           (jira-api::json2sheeple
98
+                                             (jira-api::get-projects *auth*))))
99
+    ((getopt :long-name "post-issue") (yason:encode (jira-api::read-issue)))
100
+    (t  (help) (exit))))
101 101
 
102 102
 (dump "jira-client" main)