(ns ci.coverage-badge (:require [hickory.core :as h] [clojure.string :as string])) (def readme-path "README.md") (def regex #"(?s)(?<=).*?(?=)") (def cloverage-output "target/coverage/index.html") (def coverage (let [rows (-> cloverage-output slurp h/parse h/as-hickory :content first ;; get :content (nth 3) ;; get :content second ;; get :content last ;; get :content) total-row (->> rows (map :content) (filter sequential?) (filter #(= "Totals:" (get-in % [0 :content 0]))) first (filter map?))] (-> total-row (nth 2) :content first (string/replace " " "")))) ;; "25" will make "%25" which decoded to "%", removing it will result in a Bad Request (def badge-url (str "https://img.shields.io/badge/coverage-" coverage "25-green")) (def badge-html (str "\"test")) (defn -main [& _] (let [readme-old (slurp readme-path) readme-new (string/replace readme-old regex badge-html)] (spit readme-path readme-new)))