diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj old mode 100755 new mode 100644 --- a/src/project_checkup/core.clj +++ b/src/project_checkup/core.clj @@ -2,31 +2,30 @@ (ns project-checkup.core (:gen-class) (:require [clojure.java.shell :as shell] - [clojure.string :as string])) + [clojure.string :as string])) -(defn get-extension [path] +(defn get-extension [path] "Extracts the extension of a path. - Returns the extension with the period, e.g., '.txt' because that's the format + Returns the extension with the period, e.g., '.txt' because that's the format people are used to seeing extensions in." (re-find #"\.[a-zA-Z0-9]+$" path)) -(defn gather-untracked +(defn gather-untracked [vcs-systems] "Gather untracked files in Git or Mercurial." (reduce into [ (if (contains? vcs-systems ".hg") (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) (if (contains? vcs-systems ".git") - (string/split (:out (shell/sh "git" "ls-files" "--others" + (string/split (:out (shell/sh "git" "ls-files" "--others" "--exclude-standard")) #"\n"))] - ) ) (defn gather-project-info "Creates a dictionary of project information." [] - (let [all-files (map str (file-seq (clojure.java.io/file "."))) + (let [all-files (map str (file-seq (clojure.java.io/file "."))) ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) @@ -34,11 +33,11 @@ ;note that using some here means that if both are present, hg is ;ignored: vcs-systems (set (vector (some #{".git" ".hg"} files))) ] - {:files files + {:files files :extensions (frequencies (map get-extension files )) :path (System/getProperty "user.dir") - :untracked-files (gather-untracked vcs-systems) - :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") + :untracked-files (gather-untracked vcs-systems) + :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") }) ) (defn color [color string] @@ -69,7 +68,7 @@ (defn check-taskpaper [project] (let [{extensions :extensions files :files } project] (or (>= (get ".taskpaper" extensions 0) 1) - (some #{"TODO" "TODO.txt" } files)))) + (some #{"TODO" "TODO.txt" } files)))) (defn check-readme-placeholders [project] (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0)) @@ -78,7 +77,7 @@ (def checks [{:name "Project is checked into revision control" :description "" :function check-vcs - :level :error + :level :error :follow-up "Initialize a repository." } {:name "Always True" :function #(or true %) @@ -93,7 +92,7 @@ :function check-taskpaper :description "" :level :suggestion - :follow-up "Add a todo file using Taskpaper." } + :follow-up "Add a todo file using Taskpaper." } {:name "Has README" :function check-readme :description "Readme exists" @@ -114,33 +113,27 @@ :suggestion :blue :warning :yellow :error :red - :red) + :red) prefix (case level :suggestion "Suggested follow-up" :warning "Recommended follow-up" :error "Required follow-up" - "Follow-up" - - ) - ] + "Follow-up" )] {:name check-name :result result - :output (if result - (color :green (str "✔" check-name "…passed!")) - (str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up) - ; (str check-name (color false-color " failed! ") "\n\tFollow up: " follow-up) - - )})) + :output (if result + (color :green (str "✔" check-name "…passed!")) + (str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up))})) (defn -main "Run checks." [& args] -(try - (let [project-info (gather-project-info)] - (doseq [check checks] - (println (:output (perform-check check project-info ))))) - (catch Exception ex - (.printStackTrace ex) - (str "caught exception: " (.getMessage ex))) - (finally (shutdown-agents) )) ) + (try + (let [project-info (gather-project-info)] + (doseq [check checks] + (println (:output (perform-check check project-info ))))) + (catch Exception ex + (.printStackTrace ex) + (str "caught exception: " (.getMessage ex))) + (finally (shutdown-agents) )) )