Skip to content

Commit

Permalink
Fix pr remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Nov 4, 2024
1 parent 79f42b5 commit 356562c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
5 changes: 0 additions & 5 deletions .circleci/config.yml

This file was deleted.

1 change: 1 addition & 0 deletions src/antq/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

(def ^:private skippable
#{"boot"
"circle-ci"
"clojure-cli"
"github-action"
"gradle"
Expand Down
10 changes: 4 additions & 6 deletions src/antq/dep/circle_ci.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 23 additions & 14 deletions src/antq/ver/circle_ci_orb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
13 changes: 3 additions & 10 deletions test/antq/dep/circle_ci_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))))
24 changes: 24 additions & 0 deletions test/antq/ver/circle_ci_orb_test.clj
Original file line number Diff line number Diff line change
@@ -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"})
{})))))

0 comments on commit 356562c

Please sign in to comment.