Skip to content

Commit

Permalink
refactor-nrepl.artifacts: increase resiliency
Browse files Browse the repository at this point in the history
Fixes #382
  • Loading branch information
vemv committed Jul 5, 2022
1 parent c2f629d commit 3b9d45a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
:unresolved-symbol {:exclude [(refactor-nrepl.ns.ns-parser/with-libspecs-from [libspecs])
(refactor-nrepl.middleware/set-descriptor! [set-descriptor!])]}
:unresolved-namespace {:exclude [clojure.main]}
:unresolved-var {:exclude [org.httpkit.client/get]}
;; for integration tests:
:unused-namespace {:exclude [sample.unused.namespace
"more.unused.namespaces*"]}}}
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
with-debug-bindings [[:inner 0]]
merge-meta [[:inner 0]]
try-if-let [[:block 1]]}}}]
:eastwood {:plugins [[jonase/eastwood "1.2.2"]]
:eastwood {:plugins [[jonase/eastwood "1.2.3"]]
:eastwood {;; :implicit-dependencies would fail spuriously when the CI matrix runs for Clojure < 1.10,
;; because :implicit-dependencies can only work for a certain corner case starting from 1.10.
:exclude-linters [:implicit-dependencies]
:exclude-namespaces [refactor-nrepl.plugin]
:add-linters [:performance :boxed-math]
:config-files ["eastwood.clj"]}}
:clj-kondo [:test
{:dependencies [[clj-kondo "2021.12.19"]]}]
{:dependencies [[clj-kondo "2021.06.22"]]}]

:deploy {:source-paths [".circleci/deploy"]}}

Expand Down
60 changes: 34 additions & 26 deletions src/refactor_nrepl/artifacts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,50 @@
(let [search-prefix "https://search.maven.org/solrsearch/select?q=g:%22"
search-suffix "%22+AND+p:%22jar%22&rows=2000&wt=json"
search-url (str search-prefix group-id search-suffix)
{:keys [_ _ body _]} @(http/get search-url (assoc (get-proxy-opts) :as :text))
search-result (json/read-str body :key-fn keyword)]
(->> search-result
:response
:docs
(keep :a))))
p (http/get search-url (assoc (get-proxy-opts) :as :text))
{:keys [_ _ body _]} (deref p 7000 {})]
(if (empty? body)
[]
(->> (json/read-str body :key-fn keyword)
:response
:docs
(keep :a)))))

(defn- get-mvn-versions!
"Fetches all the versions of particular artifact from maven repository."
[artifact]
(let [[group-id artifact] (str/split artifact #"/")
search-prefix "https://search.maven.org/solrsearch/select?q=g:%22"
{:keys [_ _ body _]} @(http/get (str search-prefix
group-id
"%22+AND+a:%22"
artifact
"%22&core=gav&rows=100&wt=json")
(assoc (get-proxy-opts) :as :text))]
(->> (json/read-str body :key-fn keyword)
:response
:docs
(keep :v))))

(defn- get-artifacts-from-mvn-central!
[]
(let [group-ids #{"com.cognitect" "org.clojure"}]
(mapcat (fn [group-id]
(->> (get-mvn-artifacts! group-id)
(map #(vector (str group-id "/" %) nil))))
group-ids)))
p (http/get (str search-prefix
group-id
"%22+AND+a:%22"
artifact
"%22&core=gav&rows=100&wt=json")
(assoc (get-proxy-opts) :as :text))
{:keys [_ _ body _]} (deref p 7000 {})]
(if (empty? body)
[]
(->> (json/read-str body :key-fn keyword)
:response
:docs
(keep :v)))))

(defn- get-artifacts-from-mvn-central! []
(->> ["org.clojure" "com.cognitect"]
(pmap (fn [group-id]
(->> group-id
get-mvn-artifacts!
(mapv (fn [artifact]
[(str group-id "/" artifact),
nil])))))
(reduce into [])))

(defn get-clojars-versions!
"Fetches all the versions of particular artifact from Clojars."
[artifact]
(let [{:keys [body status]} @(http/get (str "https://clojars.org/api/artifacts/"
artifact))]
(let [p (http/get (str "https://clojars.org/api/artifacts/"
artifact))
{:keys [body status]} (deref p 7000 {})]
(when (= 200 status)
(->> (json/read-str body :key-fn keyword)
:recent_versions
Expand Down
3 changes: 2 additions & 1 deletion src/refactor_nrepl/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,9 @@
(catch Exception _e
(throw (IllegalArgumentException. "Malformed ns form!")))))))

(defn ^String fully-qualify
(defn fully-qualify
"Create a fully qualified name from name and ns."
^String
[ns name]
(let [prefix (str ns)
suffix (suffix name)]
Expand Down

0 comments on commit 3b9d45a

Please sign in to comment.