<commit_before>(ns exploud.tyranitar
  (:require [cheshire.core :as json]
            [environ.core :refer [env]]
            [exploud.http :as http]))

(def tyranitar-url
  (env :service-tyranitar-url))

(defn- file-url [environment application-name commit-hash file-name]
  (str tyranitar-url "/1.x/applications/" environment "/" application-name "/" commit-hash "/" file-name))

(defn- commits-url [environment application-name]
  (str tyranitar-url "/1.x/applications/" environment "/" application-name))

(defn- get-file-content [environment application-name commit-hash file-name]
  (let [{:keys [body status]} (http/simple-get (file-url environment application-name commit-hash file-name))]
    (if (= status 200)
      (json/parse-string body))))

(defn application-properties [environment application-name commit-hash]
  (if-let [content (get-file-content environment application-name commit-hash "application-properties")]
    content
    {:status 500 :body "Application properties not found. Deployment cannot continue."}))

(defn deployment-params [environment application-name commit-hash]
  (if-let [content (get-file-content environment application-name commit-hash "deployment-params")]
    content
    {:status 500 :body "Deployment params not found. Deployment cannot continue."}))

(defn launch-data [environment application-name commit-hash]
  (if-let [content (get-file-content environment application-name commit-hash "launch-data")]
    content
    {:status 500 :body "Launch data not found. Deployment cannot continue."}))

(defn commits [environment application-name]
  (let [{:keys [body status]} (http/simple-get (commits-url environment application-name))]
    (if (= status 200)
      (json/parse-string body true))))

(defn last-commit-hash [environment application-name]
  (:hash (first (:commits (commits environment application-name)))))

;(application-properties "dev" "skeleton" "HEAD")
;(deployment-params "dev" "skeleton" "HEAD")
;(launch-data "dev" "skeleton" "HEAD")
;(last-commit-hash "dev" "skeleton")

(get (application-properties "dev" "skeleton" "HEAD") "data")<commit_msg>Bit of random code left over<commit_after>(ns exploud.tyranitar
  (:require [cheshire.core :as json]
            [environ.core :refer [env]]
            [exploud.http :as http]))

(def tyranitar-url
  (env :service-tyranitar-url))

(defn- file-url [environment application-name commit-hash file-name]
  (str tyranitar-url "/1.x/applications/" environment "/" application-name "/" commit-hash "/" file-name))

(defn- commits-url [environment application-name]
  (str tyranitar-url "/1.x/applications/" environment "/" application-name))

(defn- get-file-content [environment application-name commit-hash file-name]
  (let [{:keys [body status]} (http/simple-get (file-url environment application-name commit-hash file-name))]
    (if (= status 200)
      (json/parse-string body))))

(defn application-properties [environment application-name commit-hash]
  (if-let [content (get-file-content environment application-name commit-hash "application-properties")]
    content
    {:status 500 :body "Application properties not found. Deployment cannot continue."}))

(defn deployment-params [environment application-name commit-hash]
  (if-let [content (get-file-content environment application-name commit-hash "deployment-params")]
    content
    {:status 500 :body "Deployment params not found. Deployment cannot continue."}))

(defn launch-data [environment application-name commit-hash]
  (if-let [content (get-file-content environment application-name commit-hash "launch-data")]
    content
    {:status 500 :body "Launch data not found. Deployment cannot continue."}))

(defn commits [environment application-name]
  (let [{:keys [body status]} (http/simple-get (commits-url environment application-name))]
    (if (= status 200)
      (json/parse-string body true))))

(defn last-commit-hash [environment application-name]
  (:hash (first (:commits (commits environment application-name)))))

;(application-properties "dev" "skeleton" "HEAD")
;(deployment-params "dev" "skeleton" "HEAD")
;(launch-data "dev" "skeleton" "HEAD")
;(last-commit-hash "dev" "skeleton")
;(get (application-properties "dev" "skeleton" "HEAD") "data")
{'fraction_non_alphanumeric': 0.14473993880913155, 'fraction_numerical': 0.008001882795951988, 'mean_word_length': 4.5847568988173455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5493107', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1247, 'n_words': 364}