<commit_before>(ns metabase.api.slack
  "/api/slack endpoints"
  (:require [clojure.set :as set]
            [clojure.tools.logging :as log]
            [compojure.core :refer [PUT]]
            [metabase.api.common :refer :all]
            [metabase.config :as config]
            [metabase.integrations.slack :as slack]))

(defendpoint PUT "/settings"
  "Update the `slack-token`. You must be a superuser to do this."
  [:as {{slack-token :slack-token} :body}]
  {slack-token [Required NonEmptyString]}
  (check-superuser)
  (try
    ;; just check that channels.list doesn't throw an exception (that the connection works)
    (when-not config/is-test?
      (slack/GET :channels.list, :exclude_archived 1, :token slack-token))
    {:ok true}
    (catch clojure.lang.ExceptionInfo info
      {:status 400, :body (ex-data info)})))

(define-routes)<commit_msg>Fix setting Slack token :scream_cat:<commit_after>(ns metabase.api.slack
  "/api/slack endpoints"
  (:require [clojure.set :as set]
            [clojure.tools.logging :as log]
            [compojure.core :refer [PUT]]
            [metabase.api.common :refer :all]
            [metabase.config :as config]
            [metabase.integrations.slack :as slack]))

(defendpoint PUT "/settings"
  "Update the `slack-token`. You must be a superuser to do this."
  [:as {{slack-token :slack-token} :body}]
  {slack-token [Required NonEmptyString]}
  (check-superuser)
  (try
    ;; just check that channels.list doesn't throw an exception (that the connection works)
    (when-not config/is-test?
      (slack/GET :channels.list, :exclude_archived 1, :token slack-token))
    (slack/slack-token slack-token)
    {:ok true}
    (catch clojure.lang.ExceptionInfo info
      {:status 400, :body (ex-data info)})))

(define-routes)
{'fraction_non_alphanumeric': 0.13546936481169197, 'fraction_numerical': 0.004496908375491849, 'mean_word_length': 3.0454545454545454, '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': '2236945', 'n_tokens_mistral': 612, 'n_tokens_neox': 589, 'n_words': 159}