summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authortilpner2018-04-22 23:40:12 +0200
committertilpner2018-04-22 23:41:40 +0200
commitfbff17c34e0e87ffd3c678d29242e2563a4eb2d2 (patch)
tree190121a31a313eda3418a77b31bada36ca2b2e37 /modules
parent24efd4634c560ddcfaea6908efeaf74930b0b30d (diff)
downloadmeep-fbff17c34e0e87ffd3c678d29242e2563a4eb2d2.tar.gz
meep-fbff17c34e0e87ffd3c678d29242e2563a4eb2d2.tar.xz
meep-fbff17c34e0e87ffd3c678d29242e2563a4eb2d2.zip
Add github module
Diffstat (limited to 'modules')
-rw-r--r--modules/3-gh/default.rkt48
-rw-r--r--modules/3-gh/open-items.gql25
2 files changed, 73 insertions, 0 deletions
diff --git a/modules/3-gh/default.rkt b/modules/3-gh/default.rkt
new file mode 100644
index 0000000..0705fe4
--- /dev/null
+++ b/modules/3-gh/default.rkt
@@ -0,0 +1,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))
diff --git a/modules/3-gh/open-items.gql b/modules/3-gh/open-items.gql
new file mode 100644
index 0000000..e7fa240
--- /dev/null
+++ b/modules/3-gh/open-items.gql
@@ -0,0 +1,25 @@
+fragment repoView on Repository {
+ name
+ pullRequests(first: 100, states: OPEN) {
+ nodes { title url }
+ }
+ issues(first: 100, states: OPEN) {
+ nodes { title url }
+ }
+}
+
+query OpenItems($user: String!) {
+ user(login: $user) {
+ repositories(first: 100) {
+ nodes { ...repoView }
+ }
+
+ organizations(first: 10) {
+ nodes {
+ repositories(first: 100) {
+ nodes { ...repoView }
+ }
+ }
+ }
+ }
+}