Skip to content

Instantly share code, notes, and snippets.

@iartarisi
Created July 16, 2011 14:53
Show Gist options
  • Save iartarisi/1086417 to your computer and use it in GitHub Desktop.
Save iartarisi/1086417 to your computer and use it in GitHub Desktop.
(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