<commit_before>;
;  (C) Copyright 2017  <NAME>
;
;  All rights reserved. This program and the accompanying materials
;  are made available under the terms of the Eclipse Public License v1.0
;  which accompanies this distribution, and is available at
;  http://www.eclipse.org/legal/epl-v10.html
;
;  Contributors:
;      <NAME>
;

(ns emender-jenkins.waive
    "Test waiving functionality")

(require '[clojure.data.json            :as json])
(require '[clj-fileutils.fileutils      :as file-utils])

(require '[emender-jenkins.results      :as results])
(require '[emender-jenkins.utils        :refer :all])
(require '[emender-jenkins.db-interface :as db-interface])

(defn read-waive-input-data
    [request]
    (try
        (-> request
            :body
            file-utils/slurp-
            (json/read-str :key-fn clojure.core/keyword))
        (catch Exception e
            (throw-exception "Can not read POST data: " e))))

(defn parse-job-name
    [input-data]
    (let [job-name (:job_name input-data)]
        (-> input-data
            (assoc :product (results/job-name->product-name job-name))
            (assoc :version (results/job-name->version job-name))
            (assoc :guide   (results/job-name->book-name job-name))
            (dissoc :job_name))))

(defn assert-not-empty
    [waive-data key-name message]
    (if (empty? (get waive-data key-name))
        (throw-exception message)))

(defn check-waive-data
    [waive-data]
    (assert-not-empty waive-data :product    "Product name not specified")
    (assert-not-empty waive-data :version    "Version not specified")
    (assert-not-empty waive-data :guide      "Guide (book) name not specified")
    (assert-not-empty waive-data :test_suite "Test suite not specified")
    (assert-not-empty waive-data :test_name  "Test name not specified")
    (assert-not-empty waive-data :cause      "Cause not specified"))

(defn parse-waive-data
    [input-data]
    (let [parsed-data (if (:job_name input-data)
                          (parse-job-name input-data)
                          input-data)]
         (check-waive-data parsed-data)
         parsed-data))

(defn waive-test
    [request]
        (let [waive-input-data  (read-waive-input-data request)
              parsed-waive-data (parse-waive-data waive-input-data)]
              parsed-waive-data))
<commit_msg>Insert info about test waive into the database<commit_after>;
;  (C) Copyright 2017  <NAME>
;
;  All rights reserved. This program and the accompanying materials
;  are made available under the terms of the Eclipse Public License v1.0
;  which accompanies this distribution, and is available at
;  http://www.eclipse.org/legal/epl-v10.html
;
;  Contributors:
;      <NAME>
;

(ns emender-jenkins.waive
    "Test waiving functionality")

(require '[clojure.data.json            :as json])
(require '[clj-fileutils.fileutils      :as file-utils])

(require '[emender-jenkins.results      :as results])
(require '[emender-jenkins.utils        :refer :all])
(require '[emender-jenkins.db-interface :as db-interface])

(defn read-waive-input-data
    [request]
    (try
        (-> request
            :body
            file-utils/slurp-
            (json/read-str :key-fn clojure.core/keyword))
        (catch Exception e
            (throw-exception "Can not read POST data: " e))))

(defn parse-job-name
    [input-data]
    (let [job-name (:job_name input-data)]
        (-> input-data
            (assoc :product (results/job-name->product-name job-name))
            (assoc :version (results/job-name->version job-name))
            (assoc :guide   (results/job-name->book-name job-name))
            (dissoc :job_name))))

(defn assert-not-empty
    [waive-data key-name message]
    (if (empty? (get waive-data key-name))
        (throw-exception message)))

(defn check-waive-data
    [waive-data]
    (assert-not-empty waive-data :product    "Product name not specified")
    (assert-not-empty waive-data :version    "Version not specified")
    (assert-not-empty waive-data :guide      "Guide (book) name not specified")
    (assert-not-empty waive-data :test_suite "Test suite not specified")
    (assert-not-empty waive-data :test_name  "Test name not specified")
    (assert-not-empty waive-data :cause      "Cause not specified"))

(defn parse-waive-data
    [input-data]
    (let [parsed-data (if (:job_name input-data)
                          (parse-job-name input-data)
                          input-data)]
         (check-waive-data parsed-data)
         parsed-data))

(defn waive-test
    [request]
        (let [waive-input-data  (read-waive-input-data request)
              parsed-waive-data (parse-waive-data waive-input-data)]
              (db-interface/insert-test-waive parsed-waive-data)
              parsed-waive-data))

{'fraction_non_alphanumeric': 0.1286427976686095, 'fraction_numerical': 0.0033305578684429643, 'mean_word_length': 2.4419770773638967, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1529264', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1509, 'n_words': 379}