From 356562cfe5a1e4c57b9be65b9ef587c3060dbdd1 Mon Sep 17 00:00:00 2001 From: Miloslav Nenadal Date: Mon, 4 Nov 2024 10:54:13 +0100 Subject: [PATCH] Fix pr remarks --- .circleci/config.yml | 5 ---- src/antq/core.clj | 1 + src/antq/dep/circle_ci.clj | 10 +++----- src/antq/ver/circle_ci_orb.clj | 37 +++++++++++++++++----------- test/antq/dep/circle_ci_test.clj | 13 +++------- test/antq/ver/circle_ci_orb_test.clj | 24 ++++++++++++++++++ 6 files changed, 55 insertions(+), 35 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 test/antq/ver/circle_ci_orb_test.clj diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index e868b2b5..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: 2.1 - -orbs: - node: circleci/node@6.3.0 - docker: circleci/docker@2.8.0 diff --git a/src/antq/core.clj b/src/antq/core.clj index 8ec42548..5eb08a0b 100644 --- a/src/antq/core.clj +++ b/src/antq/core.clj @@ -68,6 +68,7 @@ (def ^:private skippable #{"boot" + "circle-ci" "clojure-cli" "github-action" "gradle" diff --git a/src/antq/dep/circle_ci.clj b/src/antq/dep/circle_ci.clj index 8b7f4436..a4433135 100644 --- a/src/antq/dep/circle_ci.clj +++ b/src/antq/dep/circle_ci.clj @@ -11,15 +11,13 @@ (->> parsed :orbs vals - (into - [] - (map (fn [orb-s] - (let [[name version] (str/split orb-s #"@")] - (r/map->Dependency {:name name + (mapv (fn [orb-s] + (let [[orb-name version] (str/split orb-s #"@" 2)] + (r/map->Dependency {:name orb-name :version version :type :circle-ci-orb :project :circle-ci - :file file-path})))))))) + :file file-path}))))))) (defn load-deps {:malli/schema [:function diff --git a/src/antq/ver/circle_ci_orb.clj b/src/antq/ver/circle_ci_orb.clj index 63d61e05..fc96f77c 100644 --- a/src/antq/ver/circle_ci_orb.clj +++ b/src/antq/ver/circle_ci_orb.clj @@ -3,24 +3,33 @@ [clojure.java.io :as io] [clojure.string :as str] [clojure.data.json :as json] + [antq.log :as log] [antq.ver :as ver])) -(defn orb-id [ns name] - (-> (io/as-url (str "https://internal.circleci.com/api/v2/orbs?ns=" ns "&name=" name)) - slurp - (json/read-str :key-fn keyword) - :items - first - :id)) +(defn- orb-id [orb-ns orb-name] + (try + (-> (io/as-url (str "https://internal.circleci.com/api/v2/orbs?ns=" orb-ns "&name=" orb-name)) + slurp + (json/read-str :key-fn keyword) + :items + first + :id) + (catch Exception ex + (log/error (str "Failed to fetch orb id from circleci: " + (.getMessage ex)))))) -(defn orb-versions [id] - (-> (io/as-url (str "https://internal.circleci.com/api/v2/orbs/" id)) - slurp - (json/read-str :key-fn keyword) - :versions)) +(defn- orb-versions [id] + (try + (-> (io/as-url (str "https://internal.circleci.com/api/v2/orbs/" id)) + slurp + (json/read-str :key-fn keyword) + :versions) + (catch Exception ex + (log/error (str "Failed to fetch orb versions from circleci: " + (.getMessage ex)))))) (defmethod ver/get-sorted-versions :circle-ci-orb [dep _options] - (let [[ns name] (str/split (:name dep) #"/") - id (orb-id ns name)] + (let [[orb-ns orb-name] (str/split (:name dep) #"/" 2) + id (orb-id orb-ns orb-name)] (orb-versions id))) diff --git a/test/antq/dep/circle_ci_test.clj b/test/antq/dep/circle_ci_test.clj index 4524d872..fcde50aa 100644 --- a/test/antq/dep/circle_ci_test.clj +++ b/test/antq/dep/circle_ci_test.clj @@ -5,7 +5,7 @@ [clojure.test :as t] [clojure.java.io :as io])) -(defn- git-tag-dependency +(defn- circle-ci-orb-dependency [m] (r/map->Dependency (merge {:project :circle-ci :type :circle-ci-orb @@ -16,13 +16,6 @@ (slurp (io/resource "dep/test_circle_ci.yml")))] (t/is (sequential? deps)) (t/is (every? #(instance? antq.record.Dependency %) deps)) - (t/is (= #{(git-tag-dependency {:name "circleci/node" :version "6.3.0"}) - (git-tag-dependency {:name "circleci/docker" :version "2.8.0"})} + (t/is (= #{(circle-ci-orb-dependency {:name "circleci/node" :version "6.3.0"}) + (circle-ci-orb-dependency {:name "circleci/docker" :version "2.8.0"})} (set deps))))) - -(t/deftest load-deps-test - (let [deps (sut/load-deps)] - (t/is (= #{".circleci/config.yml"} - (set (map :file deps))))) - - (t/is (nil? (sut/load-deps "non_existing_directory")))) diff --git a/test/antq/ver/circle_ci_orb_test.clj b/test/antq/ver/circle_ci_orb_test.clj new file mode 100644 index 00000000..33bc7779 --- /dev/null +++ b/test/antq/ver/circle_ci_orb_test.clj @@ -0,0 +1,24 @@ +(ns antq.ver.circle-ci-orb-test + (:require + [clojure.test :as t] + [antq.record :as r] + [antq.ver :as ver] + [antq.ver.circle-ci-orb :as sut])) + +(defn- dep + [m] + (r/map->Dependency (merge {:type :circle-ci-orb} m))) + +(defn- orb-id [orb-ns orb-name] + (get-in {"circleci" {"node" "circleci-node-id"}} [orb-ns orb-name])) + +(defn- orb-versions [id] + (get {"circleci-node-id" ["3.0.0" "2.0.0" "1.0.0"]} id)) + +(t/deftest get-sorted-versions-test + (with-redefs [sut/orb-id orb-id + sut/orb-versions orb-versions] + (t/is (= ["3.0.0" "2.0.0" "1.0.0"] + (ver/get-sorted-versions (dep {:name "circleci/node" + :version "1.0.0"}) + {})))))