Show More
Commit Description:
Tidy output.
Commit Description:
Tidy output.
File last commit:
Show/Diff file:
Action:
src/project_checkup/core.clj
146 lines | 5.2 KiB | text/x-clojure | ClojureLexer
Initial working version.
r0 #!/usr/bin/env lumo
(ns project-checkup.core
(:gen-class)
(:require [clojure.java.shell :as shell]
[clojure.string :as string]))
Add property-based testing (and fix a bug).
r8 (defn get-extension [path]
"Extracts the extension of a path.
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))
Initial working version.
r0
Add git support.
r10 (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"
"--exclude-standard")) #"\n"))]
)
)
Initial working version.
r0 (defn gather-project-info
Add git support.
r10 "Creates a dictionary of project information."
Initial working version.
r0 []
Cleanup.
r6 (let [all-files (map str (file-seq (clojure.java.io/file ".")))
Various improvements and refactorings.
r4 ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n")
Add git support.
r10
files (map #(clojure.string/replace % #"./(.*)" "$1") all-files )
Tidy output.
r13 ; file-set (set files)
Add git support.
r10 ;note that using some here means that if both are present, hg is
;ignored:
vcs-systems (set (vector (some #{".git" ".hg"} files))) ]
Initial working version.
r0 {:files files
:extensions (frequencies (map get-extension files ))
Cleanup.
r6 :path (System/getProperty "user.dir")
Add git support.
r10 :untracked-files (gather-untracked vcs-systems)
Various improvements and refactorings.
r4 :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "")
Cleanup.
r6 }) )
Initial working version.
r0
(defn color [color string]
(let [color-sequence (case color
:green "\u001B[32m"
:yellow "\u001B[33m"
:blue "\u001B[34m"
Various improvements and refactorings.
r4 :red "\u001B[31m"
:cyan "\u001B[36m"
:magenta "\u001B[35m"
Initial working version.
r0 )
reset "\u001B[m" ]
(str color-sequence string reset)) )
(defn check-vcs [project]
(let [{files :files } project]
Various improvements and refactorings.
r4 (boolean (some #{".git" ".hg"} files)) ))
Initial working version.
r0
(defn check-readme [project]
(let [{files :files } project]
Add tests (and bug fix as a result of a test).
r7 (boolean (some #{"README.md" "README.txt" "README.mkd" "README"} files)) ))
Initial working version.
r0
(defn check-untracked [project]
(let [{untracked :untracked-files } project]
(= (count untracked) 0)) )
(defn check-taskpaper [project]
Various improvements and refactorings.
r4 (let [{extensions :extensions files :files } project]
(or (>= (get ".taskpaper" extensions 0) 1)
(some #{"TODO" "TODO.txt" } files))))
(defn check-readme-placeholders [project]
Add tests (and bug fix as a result of a test).
r7 (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0))
Various improvements and refactorings.
r4
Initial working version.
r0
Tidy output.
r13 (def checks [{:name "Project is checked into revision control"
Initial working version.
r0 :description ""
:function check-vcs
:level :error
:follow-up "Initialize a repository." }
{:name "Always True"
:function #(or true %)
:level :error
:follow-up "This is a bug." }
Tidy output.
r13 {:name "All files are tracked or ignored"
Initial working version.
r0 :description ""
:function check-untracked
:level :warning
Add git support.
r10 :follow-up "Commit or ignore files from 'hg st -u' or 'git ls-files --others --exclude-standard'." }
Tidy output.
r13 {:name "Project has a todo file"
Initial working version.
r0 :function check-taskpaper
:description ""
:level :suggestion
:follow-up "Add a todo file using Taskpaper." }
Tidy output.
r13 {:name "Has README"
Initial working version.
r0 :function check-readme
:description "Readme exists"
:level :suggestion
Various improvements and refactorings.
r4 :follow-up "Add a README." }
{:name "README has no placeholders"
:function check-readme-placeholders
:description "No placeholders in README"
:level :error
:follow-up "Address placeholders or convert them to tasks."
} ])
Initial working version.
r0
(defn perform-check [check project]
(let [{check-name :name function :function follow-up :follow-up
level :level } check
result (function project)
false-color (case level
:suggestion :blue
:warning :yellow
:error :red
Tidy output.
r13 :red)
prefix (case level
:suggestion "Suggested follow-up"
:warning "Recommended follow-up"
:error "Required follow-up"
"Follow-up"
)
]
Initial working version.
r0 {:name check-name
:result result
:output (if result
Tidy output.
r13 (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)
)}))
Initial working version.
r0
(defn -main
Various improvements and refactorings.
r4 "Run checks."
Initial working version.
r0 [& args]
Various improvements and refactorings.
r4 (try
Add git support.
r10 (let [project-info (gather-project-info)]
(doseq [check checks]
(println (:output (perform-check check project-info )))))
Various improvements and refactorings.
r4 (catch Exception ex
(.printStackTrace ex)
(str "caught exception: " (.getMessage ex)))
Cleanup.
r6 (finally (shutdown-agents) )) )