-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgithub-issues.lisp
52 lines (40 loc) · 1.51 KB
/
github-issues.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(defpackage #:qlc-github-issues
(:use #:cl)
(:export #:get-issues-plist
#:matching-issue)
(:import-from #:function-cache
#:defcached)
(:import-from #:drakma
#:http-request))
(in-package #:qlc-github-issues)
(defvar *issues-json-url*
"https://api.github.com/repos/quicklisp/quicklisp-projects/issues")
(defcached (get-issues-json :timeout 300) ()
(multiple-value-bind (document status headers)
(http-request *issues-json-url*)
(declare (ignore headers))
(unless (eql status 200)
(error "Unexpected status from ~A: ~A" *issues-json-url* status))
(trivial-utf-8:utf-8-bytes-to-string document)))
(defun clear-cache ()
(function-cache:clear-cache *get-issues-json-cache*))
(defun get-raw-issues-data ()
(yason:parse (get-issues-json)))
(defun get-issues-plist ()
(let ((issues (get-raw-issues-data)))
(loop for table in issues
collect (list :title (gethash "title" table)
:number (gethash "number" table)
:body (gethash "body" table)))))
(defun matching-issue (substring)
"Return the FIRST issue that matches SUBSTRING. Matches in titles
are preferred."
(block found
(dolist (issue (get-issues-plist))
(when (search substring (getf issue :title)
:test 'equalp)
(return-from found issue)))
(dolist (issue (get-issues-plist))
(when (search substring (getf issue :body)
:test 'equalp)
(return-from found issue)))))