Last active
June 17, 2016 12:21
-
-
Save apod/c41a9df5a7345478176c8ce6120c1936 to your computer and use it in GitHub Desktop.
Parse project.clj dependencies from top clojure projects in Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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