<commit_before>(ns frontend.components.build
  (:require [cljs.core.async :as async :refer [>! <! alts! chan sliding-buffer put! close!]]
            [frontend.datetime :as datetime]
            [frontend.models.container :as container-model]
            [frontend.models.build :as build-model]
            [frontend.models.plan :as plan-model]
            [frontend.models.project :as project-model]
            [frontend.components.build-head :as build-head]
            [frontend.components.build-invites :as build-invites]
            [frontend.components.build-steps :as build-steps]
            [frontend.components.common :as common]
            [frontend.components.project.common :as project-common]
            [frontend.state :as state]
            [frontend.utils :as utils :include-macros true]
            [frontend.utils.github :as gh-utils]
            [frontend.utils.vcs-url :as vcs-url]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [sablono.core :as html :refer-macros [html]]))

(defn report-error [build controls-ch]
  (let [build-id (build-model/id build)
        build-url (:build_url build)]
    ;; XXX add circle.yml errors
    (when (:failed build)
      [:div.alert.alert-danger
       (if-not (:infrastructure_fail build)
         [:div.alert-wrap
          "Error! "
          [:a {:href "/docs/troubleshooting"}
           "Check out common problems "]
          "or "
          [:a {:title "Report an error in how Circle ran this build"
               :on-click #(put! controls-ch [:report-build-clicked {:build-url build-url}])}
           "report this issue"]
          " and we'll investigate."]

         [:div
          "Looks like we had a bug in our infrastructure, or that of our providers (generally "
          [:a {:href "https://status.github.com/"} "GitHub"]
          " or "
          [:a {:href "https://status.aws.amazon.com/"} "AWS"]
          ") We should have automatically retried this build. We've been alerted of"
          " the issue and are almost certainly looking into it, please "
          (common/contact-us-inner controls-ch)
          " if you're interested in the cause of the problem."])])))

(defn config-diagnostics [build]
  config-diagnostics-isnt-finished
  "")

(defn container-pill [{:keys [container current-container-id]} owner opts]
  (reify
    om/IRender
    (render [_]
      (html
       (let [container-id (container-model/id container)
             controls-ch (get-in opts [:comms :controls])]
         [:li {:class (when (= container-id current-container-id) "active")}
          [:a.container-selector
           {:on-click #(put! controls-ch [:container-selected container-id])
            :class (container-model/status-classes container)}
           (str "C" (:index container))]])))))

(defn container-pills [container-data owner opts]
  (reify
    om/IRender
    (render [_]
      (let [{:keys [containers current-container-id]} container-data
            controls-ch (get-in opts [:comms :controls])]
        (html
         [:div.containers.pagination.pagination-centered (when-not (< 1 (count containers))
                                                           {:style {:display "none"}})
          [:ul.container-list
           (for [container containers]
             (om/build container-pill
                       {:container container
                        :current-container-id current-container-id}
                       {:opts opts
                        :react-key (:index container)}))]])))))

(defn show-trial-notice? [plan]
  (and (plan-model/trial? plan)
       (plan-model/trial-over? plan)
       (> 4 (plan-model/days-left-in-trial plan))))

(defn notices [data owner opts]
  (reify
    om/IRender
    (render [_]
      (html
       (let [build-data (:build-data data)
             project-data (:project-data data)
             build (:build build-data)
             controls-ch (get-in opts [:comms :controls])]
         [:div.row-fluid
          [:div.offset1.span10
           [:div (common/messages (:messages build))]
           [:div (report-error build controls-ch)]
           (when (and (:plan project-data) (show-trial-notice? (:plan project-data)))
             (om/build project-common/trial-notice (:plan project-data) {:opts opts}))
           (when (and (:project project-data)
                      (project-common/show-enable-notice (:project project-data)))
             (om/build project-common/enable-notice (:project project-data) {:opts opts}))
           (when (and (:project project-data)
                      (project-common/show-follow-notice (:project project-data)))
             (om/build project-common/follow-notice (:project project-data) {:opts opts}))
           (when (build-model/display-build-invite build)
             (om/build build-invites/build-invites
                       (:invite-data build-data)
                       {:opts (assoc opts :project-name (vcs-url/project-name (:vcs_url build)))}))]])))))

(defn build [data owner opts]
  (reify
    om/IRender<commit_msg>clean up notices a bit<commit_after>(ns frontend.components.build
  (:require [cljs.core.async :as async :refer [>! <! alts! chan sliding-buffer put! close!]]
            [frontend.datetime :as datetime]
            [frontend.models.container :as container-model]
            [frontend.models.build :as build-model]
            [frontend.models.plan :as plan-model]
            [frontend.models.project :as project-model]
            [frontend.components.build-head :as build-head]
            [frontend.components.build-invites :as build-invites]
            [frontend.components.build-steps :as build-steps]
            [frontend.components.common :as common]
            [frontend.components.project.common :as project-common]
            [frontend.state :as state]
            [frontend.utils :as utils :include-macros true]
            [frontend.utils.github :as gh-utils]
            [frontend.utils.vcs-url :as vcs-url]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [sablono.core :as html :refer-macros [html]]))

(defn report-error [build controls-ch]
  (let [build-id (build-model/id build)
        build-url (:build_url build)]
    ;; XXX add circle.yml errors
    (when (:failed build)
      [:div.alert.alert-danger
       (if-not (:infrastructure_fail build)
         [:div.alert-wrap
          "Error! "
          [:a {:href "/docs/troubleshooting"}
           "Check out common problems "]
          "or "
          [:a {:title "Report an error in how Circle ran this build"
               :on-click #(put! controls-ch [:report-build-clicked {:build-url build-url}])}
           "report this issue"]
          " and we'll investigate."]

         [:div
          "Looks like we had a bug in our infrastructure, or that of our providers (generally "
          [:a {:href "https://status.github.com/"} "GitHub"]
          " or "
          [:a {:href "https://status.aws.amazon.com/"} "AWS"]
          ") We should have automatically retried this build. We've been alerted of"
          " the issue and are almost certainly looking into it, please "
          (common/contact-us-inner controls-ch)
          " if you're interested in the cause of the problem."])])))

(defn config-diagnostics [build]
  config-diagnostics-isnt-finished
  "")

(defn container-pill [{:keys [container current-container-id]} owner opts]
  (reify
    om/IRender
    (render [_]
      (html
       (let [container-id (container-model/id container)
             controls-ch (get-in opts [:comms :controls])]
         [:li {:class (when (= container-id current-container-id) "active")}
          [:a.container-selector
           {:on-click #(put! controls-ch [:container-selected container-id])
            :class (container-model/status-classes container)}
           (str "C" (:index container))]])))))

(defn container-pills [container-data owner opts]
  (reify
    om/IRender
    (render [_]
      (let [{:keys [containers current-container-id]} container-data
            controls-ch (get-in opts [:comms :controls])]
        (html
         [:div.containers.pagination.pagination-centered (when-not (< 1 (count containers))
                                                           {:style {:display "none"}})
          [:ul.container-list
           (for [container containers]
             (om/build container-pill
                       {:container container
                        :current-container-id current-container-id}
                       {:opts opts
                        :react-key (:index container)}))]])))))

(defn show-trial-notice? [plan]
  (and (plan-model/trial? plan)
       (plan-model/trial-over? plan)
       (> 4 (plan-model/days-left-in-trial plan))))

(defn notices [data owner opts]
  (reify
    om/IRender
    (render [_]
      (html
       (let [build-data (:build-data data)
             project-data (:project-data data)
             plan (:plan project-data)
             project (:project project-data)
             build (:build build-data)
             controls-ch (get-in opts [:comms :controls])]
         [:div.row-fluid
          [:div.offset1.span10
           [:div (common/messages (:messages build))]
           [:div (report-error build controls-ch)]

           (when (and plan (show-trial-notice? plan))
             (om/build project-common/trial-notice plan {:opts opts}))

           (when (and project (project-common/show-enable-notice project))
             (om/build project-common/enable-notice project {:opts opts}))

           (when (and project (project-common/show-follow-notice project))
             (om/build project-common/follow-notice project {:opts opts}))

           (when (build-model/display-build-invite build)
             (om/build build-invites/build-invites
                       (:invite-data build-data)
                       {:opts (assoc opts :project-name (vcs-url/project-name (:vcs_url build)))}))]])))))

(defn build [data owner opts]
  (reify
    om/IRender
{'fraction_non_alphanumeric': 0.13388707604073966, 'fraction_numerical': 0.0009888262632255513, 'mean_word_length': 2.0454682324601023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3492405', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2858, 'n_words': 746}