blob: 0705fe4a328fe3cb806ad76496d7cca5cec324bd (
plain)
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
48
|
#lang racket/base
(require irc/bot irc/command irc/storage
racket/runtime-path
racket/string racket/file net/url json)
(provide (all-defined-out))
(define-runtime-path here ".")
(define api (string->url "https://api.github.com/graphql"))
(define (gh-graphql query [variables (hasheq)])
(let* ([data (hasheq 'query query 'variables variables)]
[token (hash-ref (network-storage "github") 'token)]
[headers (list (format "Authorization: bearer ~a" token))]
[port (post-pure-port api (jsexpr->bytes data) headers)]
[result (read-json port)])
(close-input-port port)
result))
(define open-items (file->string (build-path here "open-items.gql")))
(define (gh-open-report gh-user irc-user)
(define (repo-action repo)
(for ([item (in-sequences (ref repo 'pullRequests 'nodes)
(ref repo 'issues 'nodes))])
(sleep 2)
(privmsg irc-user (format "~a - ~a" (ref item 'title) (ref item 'url)))))
(let* ([r (gh-graphql open-items (hasheq 'user gh-user))]
[user (ref r 'data 'user)])
(for* ([user-repo (ref user 'repositories 'nodes)])
(repo-action user-repo))
(for* ([org (ref user 'organizations 'nodes)]
[org-repo (ref org 'repositories 'nodes)])
(repo-action org-repo))))
(define-command (gh-set-name nick)
#:help "Set GitHub handle to be associated with your IRC user"
(ref-set! (user-storage (source))
nick
'github 'name)
(persist-user (source)))
(define-command (gh-open)
#:help "Request open issues and PRs for your GitHub handle, sent in private"
(define irc-name (source))
(define gh-name
(ref (user-storage irc-name) 'github 'name))
(gh-open-report gh-name irc-name))
|