Skip to content

Commit c835ef9

Browse files
committed
Add quick github stats import
1 parent 6e8c71e commit c835ef9

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
repos.edn
2+
.nrepl-port

deps.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:deps {metosin/jsonista {:mvn/version "0.3.5"}}}

src/metosin/repos.clj

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(ns site.technology
2+
(:require [jsonista.core :as json]
3+
[clojure.java.io :as io]
4+
[clojure.edn :as edn]
5+
[clojure.pprint :refer [pprint]]
6+
[clojure.string :as str]))
7+
8+
(defn repos
9+
([]
10+
(repos "https://api.github.com/orgs/Metosin/repos?type=public"))
11+
([url]
12+
(let [u (java.net.URL. url)
13+
c (.openConnection u)
14+
links (-> (.getHeaderField c "Link")
15+
(str/split #",")
16+
(->> (map (fn [x]
17+
(let [[_ url rel] (re-matches #"<(.*)>; rel=\"(.*)\"" (str/trim x))]
18+
[rel url])))
19+
(into {})))
20+
data (with-open [is (.getInputStream c)]
21+
(json/read-value is json/keyword-keys-object-mapper))]
22+
(if-let [x (get links "next")]
23+
(into data (repos x))
24+
data))))
25+
26+
(defn update-github-data []
27+
(let [data (repos)]
28+
(spit (io/file "repos.edn") (with-out-str (pprint data)))))
29+
30+
(comment
31+
(update-github-data))
32+
33+
(def all-repos (edn/read-string (slurp (io/file "repos.edn"))))
34+
35+
(def topic->stage
36+
{"metosin-experimental" :experimental
37+
"metosin-active-development" :active-development
38+
"metosin-stable" :stable
39+
"metosin-deprecated" :deprecated})
40+
41+
(first all-repos)
42+
43+
(defn csv-export []
44+
(doseq [{:keys [topics archived open_issues_count] :as repo} all-repos]
45+
(let [stages (keep topic->stage topics)]
46+
(println (str (:name repo) ","
47+
archived ","
48+
(if (seq stages)
49+
(str/join " " (map name stages))
50+
"unknown") ","
51+
open_issues_count)))))
52+
53+
(defn -main [& _]
54+
(doseq [{:keys [topics archived] :as repo} all-repos]
55+
))

0 commit comments

Comments
 (0)