# HG changeset patch # User alys # Date 2019-01-01 02:45:14 # Node ID a194dde394431d725e944965b7958cfc3cedc0b3 # Parent 5d3a3c250c8c31915e18187d811630224f44dc83 Add license check. diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj --- a/src/project_checkup/core.clj +++ b/src/project_checkup/core.clj @@ -74,6 +74,12 @@ (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0)) +(defn check-license [project] +(let [{files :files } project] + (boolean (some #{"LICENSE" "LICENSE.txt" "LICENSE.md" "LICENSE.mkd"} files)) ) + ) + + (def checks [{:name "Project is checked into revision control" :description "" :function check-vcs @@ -93,7 +99,7 @@ :description "" :level :suggestion :follow-up "Add a todo file using Taskpaper." } - {:name "Has README" + {:name "Project has a README" :function check-readme :description "Readme exists" :level :suggestion @@ -103,7 +109,12 @@ :description "No placeholders in README" :level :error :follow-up "Address placeholders or convert them to tasks." - } ]) + } + { :name "Project has a license" + :function check-license + :description "Project has a LICENSE file." + :level :warning ;going with warning because a project might not have a license before release. + :follow-up "Add a license to LICENSE. Consider using https://choosealicense.com/ if you need guidance. " }]) (defn perform-check [check project] (let [{check-name :name function :function follow-up :follow-up @@ -115,9 +126,9 @@ :error :red :red) prefix (case level - :suggestion "Suggested follow-up" - :warning "Recommended follow-up" - :error "Required follow-up" + :suggestion "Suggested " + :warning "Recommended " + :error "Required " "Follow-up" )] {:name check-name :result result @@ -136,4 +147,4 @@ (catch Exception ex (.printStackTrace ex) (str "caught exception: " (.getMessage ex))) - (finally (shutdown-agents) )) ) + (finally (shutdown-agents)))) diff --git a/test/project_checkup/core_test.clj b/test/project_checkup/core_test.clj --- a/test/project_checkup/core_test.clj +++ b/test/project_checkup/core_test.clj @@ -34,6 +34,18 @@ (is (not (check-untracked {:untracked-files [".hg"]}))))) +(deftest test-check-license + (testing "Ensure license is counted" + (is (check-license {:files ["LICENSE.mkd"]})) + (is (check-license {:files ["LICENSE"]}))) + (testing "Ensure non-plain text licenses don't count." + (is (not (check-license {:files ["LICENSE.docx"]}))) + (is (not (check-license {:files ["LICENSE.pdf"]})))) + (testing "Ensure blank is false." + (is (not (check-license {:files []}))) + (is (not (check-license {}))) + (is (not (check-license {:files ["licens" "README"]}))))) + (deftest test-get-extension (testing "test various paths with extensions" (is (= (get-extension "test.txt") ".txt"))