<commit_before>(ns cider-ci.utils.self
  (:require
    [cider-ci.utils.system :as system]

    [clojure.java.io :as io]
    [clj-yaml.core :as yaml]
    [clj-time.core :as time]


    [logbug.debug :as debug]
    [logbug.catcher :refer [snatch]]
    [clj-commons-exec :as commons-exec]
    [clj-logging-config.log4j :as logging-config]
    [clojure.tools.logging :as logging]
    ))

(defn group-name []
  (-> "project-info.clj"
      io/resource
      slurp
      read-string
      :project-group))

(defn project-name []
  (-> "project-info.clj"
      io/resource
      slurp
      read-string
      :project-name))

(defn release []
  (snatch
    {:return-fn (fn [e]
                  {:version_major 4
                   :version_minor 0
                   :version_patch 0
                   :version_pre "TEST"
                   :version_build nil
                   :edition nil})}
    (-> "releases.yml"
        clojure.java.io/resource
        slurp
        yaml/parse-string
        :releases
        first )))

(defn version []
  (let [release (release)]
    (str (:version_major release)
         "." (:version_minor release)
         "." (:version_patch release)
         (when-let [pre (:version_pre release)]
           (str "-" pre))
         (when-let [build (:version_build release)]
           (str "+" build)))))

(defn current-time []
  (str (time/now)))

(defn deploy-info []
  (snatch
    {:return-fn (fn [e]
                  {:tree_id "TEST"
                   :commit_id "TEST"
                   :time (current-time) })}
    (-> "deploy-info.yml"
        clojure.java.io/resource
        slurp
        yaml/parse-string)))

(defn group-edition-str []
  (str (group-name)
       (when-let  [edition (-> release :edition)]
         (str "_" edition))
       ))

(defn application-str []
  (-> (str (group-edition-str)
           "/" (project-name)
           " " (version)
           "+" (-> (deploy-info) :tree_id))
      (clojure.string/replace #"\s+" " ")
      clojure.string/trim))

(defn cider-ci-str []
  (-> (str (group-edition-str)
           " "
           " " (version)
           "+" (-> (deploy-info) :tree_id))
      (clojure.string/replace #"\s+" " ")
      clojure.string/trim))


;### Debug #####################################################################
;(debug/debug-ns *ns*)
;(logging-config/set-logger! :level :debug)
;(logging-config/set-logger! :level :info)<commit_msg>Add group and project name fallback in dev mode<commit_after>(ns cider-ci.utils.self
  (:require
    [cider-ci.utils.system :as system]

    [clojure.java.io :as io]
    [clj-yaml.core :as yaml]
    [clj-time.core :as time]


    [logbug.debug :as debug]
    [logbug.catcher :refer [snatch]]
    [clj-commons-exec :as commons-exec]
    [clj-logging-config.log4j :as logging-config]
    [clojure.tools.logging :as logging]
    ))

(defn group-name []
  (snatch
    {:return-fn (fn [_]
                  (-> "project.clj" slurp read-string
                      second  str (clojure.string/split #"\/") first))}
    (-> "project-info.clj" io/resource
        slurp read-string :project-group)))

(defn project-name []
  (snatch
    {:return-fn (fn [_]
                  (-> "project.clj" slurp read-string
                      second  str (clojure.string/split #"\/") second))}
    (-> "project-info.clj" io/resource
        slurp read-string :project-name)))

(defn release []
  (snatch
    {:return-fn (fn [e]
                  {:version_major 4
                   :version_minor 0
                   :version_patch 0
                   :version_pre "TEST"
                   :version_build nil
                   :edition nil})}
    (-> "releases.yml"
        clojure.java.io/resource
        slurp
        yaml/parse-string
        :releases
        first )))

(defn version []
  (let [release (release)]
    (str (:version_major release)
         "." (:version_minor release)
         "." (:version_patch release)
         (when-let [pre (:version_pre release)]
           (str "-" pre))
         (when-let [build (:version_build release)]
           (str "+" build)))))

(defn current-time []
  (str (time/now)))

(defn deploy-info []
  (snatch
    {:return-fn (fn [e]
                  {:tree_id "TEST"
                   :commit_id "TEST"
                   :time (current-time) })}
    (-> "deploy-info.yml"
        clojure.java.io/resource
        slurp
        yaml/parse-string)))

(defn group-edition-str []
  (str (group-name)
       (when-let  [edition (-> release :edition)]
         (str "_" edition))
       ))

(defn application-str []
  (-> (str (group-edition-str)
           "/" (project-name)
           " " (version)
           "+" (-> (deploy-info) :tree_id))
      (clojure.string/replace #"\s+" " ")
      clojure.string/trim))

(defn cider-ci-str []
  (-> (str (group-edition-str)
           " "
           " " (version)
           "+" (-> (deploy-info) :tree_id))
      (clojure.string/replace #"\s+" " ")
      clojure.string/trim))


;### Debug #####################################################################
;(debug/debug-ns *ns*)
{'fraction_non_alphanumeric': 0.18460329929300864, 'fraction_numerical': 0.0015710919088766694, 'mean_word_length': 1.8500279798545047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6172360', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1684, 'n_words': 325}