Skip to content

Commit

Permalink
Merge pull request #815 from clojars/tobias/show-dependents
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias authored Oct 27, 2021
2 parents 5144fc8 + b405513 commit 30c97e4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
8 changes: 8 additions & 0 deletions dev-resources/test-0.0.2/test.pom
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>fake</groupId>
<artifactId>fake</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>
</project>
11 changes: 11 additions & 0 deletions resources/queries/queryfile.sql
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ WHERE (
version = :version
);

--name: find-dependents
SELECT *
FROM deps
WHERE (
dep_group_name = :groupname
AND
dep_jar_name = :jarname
AND
dep_version = :version
);

--name: all-projects
SELECT DISTINCT group_name, jar_name
FROM jars
Expand Down
7 changes: 7 additions & 0 deletions src/clojars/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@
:version version}
{:connection db}))

(defn find-dependents
[db groupname jarname version]
(sql/find-dependents {:groupname groupname
:jarname jarname
:version version}
{:connection db}))

(defn all-projects [db offset-num limit-num]
(sql/all-projects {:num limit-num
:offset offset-num}
Expand Down
28 changes: 19 additions & 9 deletions src/clojars/web/jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,23 @@
[:li (dependency-link db dep)])])))

(defn dependencies [db {:keys [group_name jar_name version]}]
(dependency-section db "Dependencies" "dependencies"
(remove #(not= (:scope %) "compile")
(map
#(set/rename-keys % {:dep_group_name :group_name
:dep_jar_name :jar_name
:dep_version :version
:dep_scope :scope})
(db/find-dependencies db
group_name jar_name version)))))
(dependency-section
db "Dependencies" "dependencies"
(into []
(comp
(filter #(= (:dep_scope %) "compile"))
(map
#(set/rename-keys % {:dep_group_name :group_name
:dep_jar_name :jar_name
:dep_version :version})))
(db/find-dependencies db group_name jar_name version))))

(defn dependents [db {:keys [group_name jar_name version]}]
(dependency-section
db "Dependents (on Clojars)" "dependents"
(filter
#(= (:dep_scope %) "compile")
(db/find-dependents db group_name jar_name version))))

(defn homepage [{:keys [homepage]}]
(when homepage
Expand Down Expand Up @@ -295,6 +303,8 @@
[:li (versions jar recent-versions count)]
(when-let [dependencies (dependencies db jar)]
[:li dependencies])
(when-let [dependents (dependents db jar)]
[:li dependents])
(when-let [homepage (homepage jar)]
[:li.homepage homepage])
(when-let [licenses (licenses jar)]
Expand Down
8 changes: 8 additions & 0 deletions test/clojars/integration/jars_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
(within [:ul#dependencies]
(has (text? "org.clojure/clojure 1.3.0-beta1")))))

(deftest canonical-jars-can-view-dependents
(inject-artifacts-into-repo! help/*db* "someuser" "fake.jar" "fake-0.0.2/fake.pom")
(inject-artifacts-into-repo! help/*db* "someuser" "test.jar" "test-0.0.2/test.pom")
(-> (session (help/app))
(visit "/fake")
(within [:ul#dependents]
(has (text? "org.clojars.dantheman/test 0.0.2")))))

(deftest shadow-jars-have-a-message
(inject-artifacts-into-repo! help/*db* "someuser" "fake.jar"
(help/rewrite-pom (io/file (io/resource "fake-0.0.1/fake.pom"))
Expand Down
1 change: 0 additions & 1 deletion test/clojars/test_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,4 @@
[params m]
`(let [db# (:db (config/config))
audit# (first (db/find-audit db# ~params))]
(prn (db/find-audit db# ~params))
(is (~'match? ~m audit#))))

0 comments on commit 30c97e4

Please sign in to comment.