Skip to content

Commit 9f5b252

Browse files
committed
refactor-nrepl.artifacts: increase resiliency
Fixes #382
1 parent c2f629d commit 9f5b252

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

src/refactor_nrepl/artifacts.clj

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,50 @@
7272
(let [search-prefix "https://search.maven.org/solrsearch/select?q=g:%22"
7373
search-suffix "%22+AND+p:%22jar%22&rows=2000&wt=json"
7474
search-url (str search-prefix group-id search-suffix)
75-
{:keys [_ _ body _]} @(http/get search-url (assoc (get-proxy-opts) :as :text))
76-
search-result (json/read-str body :key-fn keyword)]
77-
(->> search-result
78-
:response
79-
:docs
80-
(keep :a))))
75+
p (http/get search-url (assoc (get-proxy-opts) :as :text))
76+
{:keys [_ _ body _]} (deref p 7 {})]
77+
(if (empty? body)
78+
[]
79+
(->> (json/read-str body :key-fn keyword)
80+
:response
81+
:docs
82+
(keep :a)))))
8183

8284
(defn- get-mvn-versions!
8385
"Fetches all the versions of particular artifact from maven repository."
8486
[artifact]
8587
(let [[group-id artifact] (str/split artifact #"/")
8688
search-prefix "https://search.maven.org/solrsearch/select?q=g:%22"
87-
{:keys [_ _ body _]} @(http/get (str search-prefix
88-
group-id
89-
"%22+AND+a:%22"
90-
artifact
91-
"%22&core=gav&rows=100&wt=json")
92-
(assoc (get-proxy-opts) :as :text))]
93-
(->> (json/read-str body :key-fn keyword)
94-
:response
95-
:docs
96-
(keep :v))))
97-
98-
(defn- get-artifacts-from-mvn-central!
99-
[]
100-
(let [group-ids #{"com.cognitect" "org.clojure"}]
101-
(mapcat (fn [group-id]
102-
(->> (get-mvn-artifacts! group-id)
103-
(map #(vector (str group-id "/" %) nil))))
104-
group-ids)))
89+
p (http/get (str search-prefix
90+
group-id
91+
"%22+AND+a:%22"
92+
artifact
93+
"%22&core=gav&rows=100&wt=json")
94+
(assoc (get-proxy-opts) :as :text))
95+
{:keys [_ _ body _]} (deref p 7 {})]
96+
(if (empty? body)
97+
[]
98+
(->> (json/read-str body :key-fn keyword)
99+
:response
100+
:docs
101+
(keep :v)))))
102+
103+
(defn- get-artifacts-from-mvn-central! []
104+
(->> ["org.clojure" "com.cognitect"]
105+
(pmap (fn [group-id]
106+
(->> group-id
107+
get-mvn-artifacts!
108+
(mapv (fn [artifact]
109+
[(str group-id "/" artifact),
110+
nil])))))
111+
(reduce into [])))
105112

106113
(defn get-clojars-versions!
107114
"Fetches all the versions of particular artifact from Clojars."
108115
[artifact]
109-
(let [{:keys [body status]} @(http/get (str "https://clojars.org/api/artifacts/"
110-
artifact))]
116+
(let [p (http/get (str "https://clojars.org/api/artifacts/"
117+
artifact))
118+
{:keys [body status]} (deref p 7 {})]
111119
(when (= 200 status)
112120
(->> (json/read-str body :key-fn keyword)
113121
:recent_versions

0 commit comments

Comments
 (0)