<commit_before>;
;  (C) Copyright 2016  <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.config
    "Module that contains all functions required to load configuration from the INI file.")

(require '[clojure.pprint :as pprint])

(require '[emender-jenkins.config-loader :as config-loader])

(def default-port
    "Default port used when no -p or --port CLI option is specified."
    "3000")

(defn update-configuration
    "Update selected items in the configuration structure."
    [configuration]
    (-> configuration
        (update-in [:config :verbose]                    config-loader/parse-boolean)
        (update-in [:config :pretty-print]               config-loader/parse-boolean)
        (update-in [:config :include-jenkins-reply]      config-loader/parse-boolean)
        (update-in [:config :verbose-show-configuration] config-loader/parse-boolean)
        (update-in [:fetcher :delay]                     config-loader/parse-int)))

(defn load-configuration-from-ini
    "Load configuration from the provided INI file and perform conversions on numeric and Boolean values."
    [ini-file-name]
    (-> (config-loader/load-configuration-file ini-file-name)
        update-configuration))

(defn assoc-in-if-not-nil
    "Assoc new (updated) value into the configuration map, but only when new value exists."
    [input selector value]
    (if value
        (assoc-in input selector value)
        input))

(defn override-options-by-cli
    "Update configuration options read form the INI file by new values."
    [configuration jenkins-url test-jobs-suffix]
    (-> configuration
        (assoc-in-if-not-nil [:jenkins :jenkins-url]      jenkins-url)
        (assoc-in-if-not-nil [:jobs    :test-jobs-suffix] test-jobs-suffix)))

(defn print-configuration
    "Print actual configuration to the output."
    [configuration]
    (pprint/pprint configuration))

(defn get-api-prefix
    "Read prefix for API calls from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :api :prefix))

(defn verbose?
    "Read verbose mode settings from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :config :verbose))

(defn get-version
    "Read service version from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :info :version))

(defn get-jenkins-url
    "Read Jenkins URL from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :jenkins :jenkins-url))

(defn get-jenkins-auth
    "Read Jenkins auth string from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :jenkins :jenkins-auth))

(defn pretty-print?
    "Read the pretty-print settings (it is used for JSON output etc.)"
    [request]
    (-> request :configuration :config :pretty-print))

(defn verbose-show-configuration?
    "Read the verbose-show-configuration settings."
    [request]
    (-> request :configuration :config :verbose-show-configuration))

(defn include-jenkins-reply?
    "Read the include-jenkins-reply settings."
    [request]
    (-> request :configuration :config :include-jenkins-reply))

(defn get-credentials-id
    "Read the Jenkins credentials ID."
    [request]
    (-> request :configuration :jenkins :credentials-id))
<commit_msg>New functions: get-preview|stage|prod-test-jobs-suffix<commit_after>;
;  (C) Copyright 2016  <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.config
    "Module that contains all functions required to load configuration from the INI file.")

(require '[clojure.pprint :as pprint])

(require '[emender-jenkins.config-loader :as config-loader])

(def default-port
    "Default port used when no -p or --port CLI option is specified."
    "3000")

(defn update-configuration
    "Update selected items in the configuration structure."
    [configuration]
    (-> configuration
        (update-in [:config :verbose]                    config-loader/parse-boolean)
        (update-in [:config :pretty-print]               config-loader/parse-boolean)
        (update-in [:config :include-jenkins-reply]      config-loader/parse-boolean)
        (update-in [:config :verbose-show-configuration] config-loader/parse-boolean)
        (update-in [:fetcher :delay]                     config-loader/parse-int)))

(defn load-configuration-from-ini
    "Load configuration from the provided INI file and perform conversions on numeric and Boolean values."
    [ini-file-name]
    (-> (config-loader/load-configuration-file ini-file-name)
        update-configuration))

(defn assoc-in-if-not-nil
    "Assoc new (updated) value into the configuration map, but only when new value exists."
    [input selector value]
    (if value
        (assoc-in input selector value)
        input))

(defn override-options-by-cli
    "Update configuration options read form the INI file by new values."
    [configuration jenkins-url test-jobs-suffix]
    (-> configuration
        (assoc-in-if-not-nil [:jenkins :jenkins-url]      jenkins-url)
        (assoc-in-if-not-nil [:jobs    :test-jobs-suffix] test-jobs-suffix)))

(defn print-configuration
    "Print actual configuration to the output."
    [configuration]
    (pprint/pprint configuration))

(defn get-api-prefix
    "Read prefix for API calls from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :api :prefix))

(defn verbose?
    "Read verbose mode settings from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :config :verbose))

(defn get-version
    "Read service version from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :info :version))

(defn get-jenkins-url
    "Read Jenkins URL from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :jenkins :jenkins-url))

(defn get-jenkins-auth
    "Read Jenkins auth string from the configuration passed via HTTP request."
    [request]
    (-> request :configuration :jenkins :jenkins-auth))

(defn pretty-print?
    "Read the pretty-print settings (it is used for JSON output etc.)"
    [request]
    (-> request :configuration :config :pretty-print))

(defn verbose-show-configuration?
    "Read the verbose-show-configuration settings."
    [request]
    (-> request :configuration :config :verbose-show-configuration))

(defn include-jenkins-reply?
    "Read the include-jenkins-reply settings."
    [request]
    (-> request :configuration :config :include-jenkins-reply))

(defn get-credentials-id
    "Read the Jenkins credentials ID."
    [request]
    (-> request :configuration :jenkins :credentials-id))

(defn get-test-jobs-prefix
    [request]
    (-> request :configuration :jobs :test-jobs-prefix))

(defn get-preview-test-jobs-suffix
    [request]
    (-> request :configuration :jobs :preview-test-jobs-suffix))

(defn get-stage-test-jobs-suffix
    [request]
    (-> request :configuration :jobs :stage-test-jobs-suffix))

(defn get-prod-jobs-prefix
    [request]
    (-> request :configuration :jobs :prod-test-jobs-suffix))

{'fraction_non_alphanumeric': 0.11253598534415074, 'fraction_numerical': 0.003140539125883277, 'mean_word_length': 3.2413984461709213, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, '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': '5977532', 'n_tokens_mistral': 2261, 'n_tokens_neox': 2175, 'n_words': 690}