Created
July 16, 2011 14:53
-
-
Save iartarisi/1086417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use http-client intarweb uri-common getopt-long json) | |
(define authorization-method | |
'#(basic ((username . "user") (password . "pass")))) | |
(define (github-get-auth path) | |
(with-input-from-request | |
(make-request method: 'GET | |
uri: (uri-reference (string-append | |
"https://api.github.com/" path)) | |
headers: (headers `((host ("http://api.github.com" . 80)) | |
(authorization ,authorization-method)))) | |
#f | |
json-read) | |
) | |
(define (gh-list-pulls user repo) | |
(github-get-auth (string-join `("repos" ,user ,repo "pulls") "/"))) | |
(define (list-pulls user repo) | |
(map (lambda (x) | |
;; only list open pull requests | |
(if (equal? "open" (assocv "state" x)) | |
(list (assocv "number" x) | |
(substring (assocv "created_at" x) 2 7) | |
(assocv "title" x)) | |
'() | |
)) | |
(gh-list-pulls user repo))) | |
(define (assocv key vector) | |
;; Acts like assoc for vectors instead of associative lists | |
(cdr (assoc key (vector->list vector)))) | |
;; Command line parsing | |
(case (string->symbol (car (command-line-arguments))) | |
;; Show a list of all the pull requests for this user and repository | |
((list) (begin | |
(print "Id Created Title") | |
(print "-- ------- -----") | |
(for-each | |
(lambda (x) | |
(apply format #t "~A ~A ~A\n" x)) | |
(apply list-pulls (cdr (command-line-arguments))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment