-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.clj
More file actions
47 lines (39 loc) · 1.69 KB
/
Copy pathcore.clj
File metadata and controls
47 lines (39 loc) · 1.69 KB
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
(ns github-issues-dump.core
(:require [clojure.java.io :as io]
[clojure.tools.cli :refer [cli]]
[github-issues-dump.api :as api]))
(defn spit* [filename body]
(println "Writing file: " filename)
(io/make-parents filename)
(spit filename body))
(defn dump-issues [token organization]
(let [issues (api/issues token organization)]
(doseq [[page body] issues
:let [filename (if organization
(format "dump/%s/issues/%s.json" organization page)
(format "dump/issues/%s.json" page))]]
(spit* filename body))))
(defn dump-comments* [filename-pattern comments]
(doseq [[[owner repo] pages] comments]
(doseq [[page body] pages
:let [filename (format filename-pattern owner repo page)]]
(spit* filename body))))
(defn dump-comments [token organization]
(let [repos (api/repositories token organization)
issue-comments (api/issue-comments token repos)
review-comments (api/review-comments token repos)]
(dump-comments* "dump/%s/%s/issues/comments/%s.json" issue-comments)
(dump-comments* "dump/%s/%s/pulls/comments/%s.json" review-comments)))
(def cli-args
[["-h" "--help" "Show help" :flag true :default false]
["-t" "--token"
"GitHub authorization token - create one at https://github.com/settings/tokens"]
["-o" "--organization" "Optional organization limits the scope of issues captured"]])
(defn -main [& args]
(let [[options _ banner] (apply cli args cli-args)
{:keys [help organization token]} options]
(when help
(println banner)
(System/exit 0))
(dump-issues token organization)
(dump-comments token organization)))