Show More
Commit Description:
Update documentation and TODO.
Commit Description:
Update documentation and TODO.
File last commit:
Show/Diff file:
Action:
src/project_checkup/core.clj
157 lines | 5.9 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]
Small tweaks to tests.
r30 [clojure.set :as set]
Small style fixes.
r14 [clojure.string :as string]))
Initial working version.
r0
Small style fixes.
r14 (defn get-extension [path]
Add property-based testing (and fix a bug).
r8 "Extracts the extension of a path.
Expand the changelog check and do a little refactoring.
r32 Returns the extension with the period, e.g., '.txt' because that's the
format people are used to seeing extensions in."
Add property-based testing (and fix a bug).
r8 (re-find #"\.[a-zA-Z0-9]+$" path))
Initial working version.
r0
Small style fixes.
r14 (defn gather-untracked
Add git support.
r10 [vcs-systems]
"Gather untracked files in Git or Mercurial."
Expand the changelog check and do a little refactoring.
r32 (filter (comp not empty?) (reduce into [
Add git support.
r10 (if (contains? vcs-systems ".hg")
(string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n"))
(if (contains? vcs-systems ".git")
Small style fixes.
r14 (string/split (:out (shell/sh "git" "ls-files" "--others"
Expand the changelog check and do a little refactoring.
r32 "--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 []
Small style fixes.
r14 (let [all-files (map str (file-seq (clojure.java.io/file ".")))
Add git support.
r10 files (map #(clojure.string/replace % #"./(.*)" "$1") all-files )
Small tweaks to tests.
r30 vcs-systems (set/intersection #{".git" ".hg"} (set files))]
Small style fixes.
r14 {:files files
Initial working version.
r0 :extensions (frequencies (map get-extension files ))
Cleanup.
r6 :path (System/getProperty "user.dir")
Small style fixes.
r14 :untracked-files (gather-untracked vcs-systems)
Refactor and cleanup.
r29 :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") }) )
Initial working version.
r0
Expand the changelog check and do a little refactoring.
r32
(def doc-extensions ["" ".txt" ".mkd" ".md" ".rst"])
(defn create-valid-names [exts names]
"Creates valid file names based on a sequence of exts and names."
(set (for [ext exts name names]
(str name ext))))
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"
Refactor and cleanup.
r29 :magenta "\u001B[35m")
reset "\u001B[m"]
(str color-sequence string reset)))
Initial working version.
r0
(defn check-vcs [project]
(let [{files :files } project]
Refactor and cleanup.
r29 (boolean (some #{".git" ".hg"} files))))
Initial working version.
r0
(defn check-readme [project]
(let [{files :files } project]
Refactor and cleanup.
r29 (boolean (some #{"README.md" "README.txt" "README.mkd" "README"} files))))
Initial working version.
r0
Add CHANGELOG check and ensure .taskpaper files are actually counted.
r27 (defn check-changelog [project]
Expand the changelog check and do a little refactoring.
r32 (let [{files :files } project
changelog-names #{"CHANGELOG" "HISTORY" "NEWS" "RELEASES"}]
(boolean (some (create-valid-names doc-extensions changelog-names) files))))
Add CHANGELOG check and ensure .taskpaper files are actually counted.
r27
Initial working version.
r0 (defn check-untracked [project]
(let [{untracked :untracked-files } project]
Refactor and cleanup.
r29 (= (count untracked) 0)))
Initial working version.
r0
(defn check-taskpaper [project]
Various improvements and refactorings.
r4 (let [{extensions :extensions files :files } project]
Add CHANGELOG check and ensure .taskpaper files are actually counted.
r27 (or (>= (get extensions ".taskpaper" 0) 1)
Small style fixes.
r14 (some #{"TODO" "TODO.txt" } files))))
Various improvements and refactorings.
r4
(defn check-readme-placeholders [project]
Refactor and cleanup.
r29 (= (count (re-find #"(FIXME|TODO)" (:readme project))) 0))
Various improvements and refactorings.
r4
Initial working version.
r0
Add license check.
r15 (defn check-license [project]
(let [{files :files } project]
Update version.
r16 (boolean (some #{"LICENSE" "LICENSE.txt" "LICENSE.md" "LICENSE.mkd"} files))))
Add license check.
r15
Tidy output.
r13 (def checks [{:name "Project is checked into revision control"
Initial working version.
r0 :description ""
:function check-vcs
Small style fixes.
r14 :level :error
Refactor and cleanup.
r29 :follow-up "Initialize a repository."}
Initial working version.
r0 {:name "Always True"
:function #(or true %)
:level :error
Refactor and cleanup.
r29 :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
Refactor and cleanup.
r29 :follow-up "Add a todo file using Taskpaper."}
Add license check.
r15 {:name "Project has a README"
Initial working version.
r0 :function check-readme
:description "Readme exists"
Tweak warning levels and remove .java-version, which was misleading.
r28 :level :warning
Refactor and cleanup.
r29 :follow-up "Add a README."}
Add CHANGELOG check and ensure .taskpaper files are actually counted.
r27 {:name "Project has a CHANGELOG"
:function check-changelog
:description "Changelog exists"
Tweak warning levels and remove .java-version, which was misleading.
r28 :level :warning
:follow-up "Add a CHANGELOG. Consider refering to keepachangelog.com for guidance." }
Various improvements and refactorings.
r4 {:name "README has no placeholders"
:function check-readme-placeholders
:description "No placeholders in README"
:level :error
Small tweaks to tests.
r30 :follow-up "Address placeholders or convert them to tasks."}
Add license check.
r15 { :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.
Tweak warning levels and remove .java-version, which was misleading.
r28 :follow-up "Add a license to LICENSE. Consider using https://choosealicense.com/ for guidance." }])
Initial working version.
r0
Refactor.
r31 (def false-colors {:suggestion :blue
:warning :yellow
:error :red})
(def level-prefixes {:suggestion "Suggested "
:warning "Recommended "
:error "Required "})
Initial working version.
r0 (defn perform-check [check project]
Refactor and cleanup.
r29 (let [{check-name :name :keys [function follow-up level]} check
Initial working version.
r0 result (function project)
Refactor.
r31 false-color (level false-colors :red)
prefix (level level-prefixes "Follow-up")]
Initial working version.
r0 {:name check-name
:result result
Small style fixes.
r14 :output (if result
(color :green (str "✔" check-name "…passed!"))
Refactor and cleanup.
r29 (str (color false-color (str "❌" check-name "…failed!"))
"\n\t" prefix " Follow up: " follow-up))}))
Initial working version.
r0
(defn -main
Various improvements and refactorings.
r4 "Run checks."
Initial working version.
r0 [& args]
Small style fixes.
r14 (try
(let [project-info (gather-project-info)]
(doseq [check checks]
(println (:output (perform-check check project-info )))))
Small tweaks to tests.
r30 (catch Exception ex ; Not expecting there to be a lot of exceptions, hence the catch-all.
Small style fixes.
r14 (.printStackTrace ex)
(str "caught exception: " (.getMessage ex)))
Add license check.
r15 (finally (shutdown-agents))))