Skip to content

Instantly share code, notes, and snippets.

@apod
Last active June 17, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apod/c41a9df5a7345478176c8ce6120c1936 to your computer and use it in GitHub Desktop.
Save apod/c41a9df5a7345478176c8ce6120c1936 to your computer and use it in GitHub Desktop.
Parse project.clj dependencies from top clojure projects in Github
(ns github-dependencies.core
(:require [clojure.string :as str]
[clj-http.client :as http]))
(def github-search-url "https://api.github.com/search/repositories")
(def github-projects-data
(:body
(http/get github-search-url
{:query-params {:q "language:clojure"
:sort "stars"
:order "desc"}
:as :json})))
(defn get-project-urls [github-response]
(map (fn [item]
(let [html-url (:html_url item)
replace-github (str/replace-first html-url
"github.com"
"raw.githubusercontent.com")]
(str replace-github "/master/project.clj"))) (:items github-response)))
(defn get-dependencies [project-clj]
(get
(apply hash-map (drop 3 (read-string project-clj)))
:dependencies))
(def all-dependencies
(->> (get-project-urls github-projects-data)
(map (fn [url]
(try
(slurp url)
(catch Exception _ :no-project-clj))))
(filter (fn [content]
(not= content :no-project-clj)))
(mapcat get-dependencies)))
(take 10 (sort-by val > (frequencies (map first all-dependencies))))
;;=> ([org.clojure/clojure 16] [org.clojure/clojurescript 6] [org.clojure/tools.logging 3] [cheshire 3] [clj-http 3] [org.clojure/data.json 2] [com.draines/postal 2] [clj-time 2] [stencil 2] [cljsjs/react-dom 2])
(defproject github-dependencies "0.1.0-SNAPSHOT"
:description "Parse project.clj dependencies from top clojure projects in GH"
:url "https://github.com/athens/clojure"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[clj-http "2.2.0"]
[cheshire "5.6.1"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment