Description:
Small style fixes.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -2,31 +2,30 | |||
|
2 | 2 | (ns project-checkup.core |
|
3 | 3 | (:gen-class) |
|
4 | 4 | (:require [clojure.java.shell :as shell] |
|
5 |
[clojure.string :as string])) |
|
|
5 | [clojure.string :as string])) | |
|
6 | 6 | |
|
7 |
(defn get-extension [path] |
|
|
7 | (defn get-extension [path] | |
|
8 | 8 | "Extracts the extension of a path. |
|
9 |
Returns the extension with the period, e.g., '.txt' because that's the format |
|
|
9 | Returns the extension with the period, e.g., '.txt' because that's the format | |
|
10 | 10 | people are used to seeing extensions in." |
|
11 | 11 | (re-find #"\.[a-zA-Z0-9]+$" path)) |
|
12 | 12 | |
|
13 |
(defn gather-untracked |
|
|
13 | (defn gather-untracked | |
|
14 | 14 | [vcs-systems] |
|
15 | 15 | "Gather untracked files in Git or Mercurial." |
|
16 | 16 | (reduce into [ |
|
17 | 17 | (if (contains? vcs-systems ".hg") |
|
18 | 18 | (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) |
|
19 | 19 | (if (contains? vcs-systems ".git") |
|
20 |
(string/split (:out (shell/sh "git" "ls-files" "--others" |
|
|
20 | (string/split (:out (shell/sh "git" "ls-files" "--others" | |
|
21 | 21 | "--exclude-standard")) #"\n"))] |
|
22 | ||
|
23 | 22 | ) |
|
24 | 23 | ) |
|
25 | 24 | |
|
26 | 25 | (defn gather-project-info |
|
27 | 26 | "Creates a dictionary of project information." |
|
28 | 27 | [] |
|
29 |
(let [all-files (map str (file-seq (clojure.java.io/file "."))) |
|
|
28 | (let [all-files (map str (file-seq (clojure.java.io/file "."))) | |
|
30 | 29 | ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") |
|
31 | 30 | |
|
32 | 31 | files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) |
@@ -34,11 +33,11 | |||
|
34 | 33 | ;note that using some here means that if both are present, hg is |
|
35 | 34 | ;ignored: |
|
36 | 35 | vcs-systems (set (vector (some #{".git" ".hg"} files))) ] |
|
37 |
{:files files |
|
|
36 | {:files files | |
|
38 | 37 | :extensions (frequencies (map get-extension files )) |
|
39 | 38 | :path (System/getProperty "user.dir") |
|
40 |
:untracked-files (gather-untracked vcs-systems) |
|
|
41 |
:readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") |
|
|
39 | :untracked-files (gather-untracked vcs-systems) | |
|
40 | :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") | |
|
42 | 41 | }) ) |
|
43 | 42 | |
|
44 | 43 | (defn color [color string] |
@@ -69,7 +68,7 | |||
|
69 | 68 | (defn check-taskpaper [project] |
|
70 | 69 | (let [{extensions :extensions files :files } project] |
|
71 | 70 | (or (>= (get ".taskpaper" extensions 0) 1) |
|
72 |
(some #{"TODO" "TODO.txt" } files)))) |
|
|
71 | (some #{"TODO" "TODO.txt" } files)))) | |
|
73 | 72 | |
|
74 | 73 | (defn check-readme-placeholders [project] |
|
75 | 74 | (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0)) |
@@ -78,7 +77,7 | |||
|
78 | 77 | (def checks [{:name "Project is checked into revision control" |
|
79 | 78 | :description "" |
|
80 | 79 | :function check-vcs |
|
81 |
:level :error |
|
|
80 | :level :error | |
|
82 | 81 | :follow-up "Initialize a repository." } |
|
83 | 82 | {:name "Always True" |
|
84 | 83 | :function #(or true %) |
@@ -93,7 +92,7 | |||
|
93 | 92 | :function check-taskpaper |
|
94 | 93 | :description "" |
|
95 | 94 | :level :suggestion |
|
96 |
:follow-up "Add a todo file using Taskpaper." } |
|
|
95 | :follow-up "Add a todo file using Taskpaper." } | |
|
97 | 96 | {:name "Has README" |
|
98 | 97 | :function check-readme |
|
99 | 98 | :description "Readme exists" |
@@ -114,33 +113,27 | |||
|
114 | 113 | :suggestion :blue |
|
115 | 114 | :warning :yellow |
|
116 | 115 | :error :red |
|
117 |
:red) |
|
|
116 | :red) | |
|
118 | 117 | prefix (case level |
|
119 | 118 | :suggestion "Suggested follow-up" |
|
120 | 119 | :warning "Recommended follow-up" |
|
121 | 120 | :error "Required follow-up" |
|
122 | "Follow-up" | |
|
123 | ||
|
124 | ) | |
|
125 | ] | |
|
121 | "Follow-up" )] | |
|
126 | 122 | {:name check-name |
|
127 | 123 | :result result |
|
128 |
:output (if result |
|
|
129 |
(color :green (str "✔" check-name "…passed!")) |
|
|
130 | (str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up) | |
|
131 | ; (str check-name (color false-color " failed! ") "\n\tFollow up: " follow-up) | |
|
132 | ||
|
133 | )})) | |
|
124 | :output (if result | |
|
125 | (color :green (str "✔" check-name "…passed!")) | |
|
126 | (str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up))})) | |
|
134 | 127 | |
|
135 | 128 | |
|
136 | 129 | (defn -main |
|
137 | 130 | "Run checks." |
|
138 | 131 | [& args] |
|
139 |
(try |
|
|
140 |
(let [project-info (gather-project-info)] |
|
|
141 | (doseq [check checks] | |
|
142 | (println (:output (perform-check check project-info ))))) | |
|
143 |
(catch Exception ex |
|
|
144 | (.printStackTrace ex) | |
|
145 | (str "caught exception: " (.getMessage ex))) | |
|
146 |
(finally (shutdown-agents) )) ) |
|
|
132 | (try | |
|
133 | (let [project-info (gather-project-info)] | |
|
134 | (doseq [check checks] | |
|
135 | (println (:output (perform-check check project-info ))))) | |
|
136 | (catch Exception ex | |
|
137 | (.printStackTrace ex) | |
|
138 | (str "caught exception: " (.getMessage ex))) | |
|
139 | (finally (shutdown-agents) )) ) |
You need to be logged in to leave comments.
Login now