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 beaa226
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 3.5.3

* [#382](https://github.com/clojure-emacs/refactor-nrepl/issues/382): `refactor-nrepl.artifacts`: increase resiliency.

## 3.5.2

* [#378](https://github.com/clojure-emacs/refactor-nrepl/issues/378): Fix `:as-alias` handling for .cljc files.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Be aware that this isn't the case if you connect to an already running REPL proc
Add the following, either in your project's `project.clj`, or in the `:user` profile found at `~/.lein/profiles.clj`:

```clojure
:plugins [[refactor-nrepl "3.5.2"]
:plugins [[refactor-nrepl "3.5.3"]
[cider/cider-nrepl "0.28.3"]]
```

Expand Down Expand Up @@ -360,12 +360,12 @@ If you want to use `mranderson` while developing locally with the REPL, the sour

When you want to release locally to the following:

PROJECT_VERSION=3.5.2 make install
PROJECT_VERSION=3.5.3 make install

And here's how to deploy to Clojars:

```bash
git tag -a v3.5.2 -m "3.5.2"
git tag -a v3.5.3 -m "3.5.3"
git push --tags
```

Expand Down
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 "2022.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 beaa226

Please sign in to comment.