<commit_before>(ns frontend.components.aside
  (:require [cljs.core.async :as async :refer [>! <! alts! chan sliding-buffer close!]]
            [clojure.string :refer [lower-case]]
            [frontend.async :refer [raise!]]
            [frontend.components.common :as common]
            [frontend.components.license :as license]
            [frontend.components.shared :as shared]
            [frontend.components.svg :refer [svg]]
            [frontend.config :as config]
            [frontend.datetime :as datetime]
            [frontend.models.build :as build-model]
            [frontend.models.feature :as feature]
            [frontend.models.project :as project-model]
            [frontend.models.plan :as pm]
            [frontend.routes :as routes]
            [frontend.state :as state]
            [frontend.utils :as utils :include-macros true]
            [frontend.utils.github :as gh-utils]
            [frontend.utils.vcs-url :as vcs-url]
            [frontend.utils.seq :refer [select-in]]
            [goog.style]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [frontend.utils.html :refer [open-ext]]
            [frontend.utils.launchdarkly :as ld])
  (:require-macros [frontend.utils :refer [html inspect]]))

(defn status-ico-name [build]
  (case (:status build)
    "running" :busy-light

    "success" :pass-light
    "fixed"   :pass-light

    "failed"   :fail-light
    "timedout" :fail-light

    "queued"      :hold-light
    "not_running" :hold-light
    "retried"     :hold-light
    "scheduled"   :hold-light

    "canceled"            :stop-light
    "no_tests"            :stop-light
    "not_run"             :stop-light
    "infrastructure_fail" :stop-light
    "killed"              :stop-light

    :none-light))

(defn sidebar-build [build {:keys [vcs_type org repo branch latest?]}]
  [:a.status {:class (when latest? "latest")
              :href (routes/v1-build-path vcs_type org repo (:build_num build))
              :title (str (build-model/status-words build) ": " (:build_num build))}
   (common/ico (status-ico-name build))])

(defn branch [data owner]
  (reify
    om/IDisplayName (display-name [_] "Aside Branch Activity")
    om/IRender
    (render [_]
      (let [{:keys [org repo branch-data vcs_type]} data
            [name-kw branch-builds] branch-data
            display-builds (take-last 5 (sort-by :build_num (concat (:running_builds branch-builds)
                                                                    (:recent_builds branch-builds))))]
        (html
         [:li
          [:div.branch
           {:role "button"}
           [:a {:href (routes/v1-dashboard-path {:org org
                                                 :repo repo
                                                 :branch (name name-kw)
                                                 :vcs_type vcs_type})
                :title (utils/display-branch name-kw)}
            (-> name-kw utils/display-branch (utils/trim-middle 23))]]
          [:div.statuses {:role "button"}
           (for [build display-builds]
             (sidebar-build build {:vcs_type vcs_type :org org :repo repo :branch (name name-kw)}))]])))))

(defn project-settings-link [{:keys [project]} owner]
  (when (and (project-model/can-write-settings? project))
    (let [org-name (:username project)
          repo-name (:reponame project)
          vcs-type (:vcs_type project)]
      [:a.project-settings-icon {:href (routes/v1-project-settings-path {:vcs_type vcs-type
                                                                         :org org-name
                                                                         :repo repo-name})
                                 :title  (str
                                           (project-model/project-name project)
                                           " settings")
                                 :on-click #((om/get-shared owner :track-event) {:event-type :project-settings-clicked
                                                                                 :properties {:org org-name
                                                                                              :repo repo-name}})}
       [:i.material-icons "settings"]])))

(defn branch-list [{:keys [branches show-all-branches? navigation-data]} owner {:keys [identities show-project?]}]
  (reify
    om/IDisplayName (display-name [_] "Aside Branch List")
    om/IRender
      (render [_]
        (let [branches-filter (if show-all-branches?
                                (constantly true)
                                (partial project-model/personal-branch? identities))]
          (html
           [:ul.branches
            (for [branch (filter branches-filter branches)]
              (let [project (:project branch)
                    latest-build (last (sort-by :build_num (concat (:running_builds branch)
                                                                   (:recent_builds branch))))
                    vcs-type (project-model/vcs-type project)
                    org-name (project-model/org-name project)
                    repo-name (project-model/repo-name project)
                    branch-identifier (:identifier branch)]
                [:li {:key (hash [vcs-type org-name repo-name branch-identifier])
                      :class (when (and (= vcs-type (:vcs_type navigation-data))
                                        (= org-name (:org navigation-data))
                                        (= repo-name (:repo navigation-data))
                                        (= (name branch-identifier)
                                           (:branch navigation-data)))
                               "selected")}
                 [:a {:href (routes/v1-dashboard-path {:vcs_type (:vcs_type project)
                                                       :org (:username project)
                                                       :repo (:reponame project)
                                                       :branch (name branch-identifier)})
                      :on-click #((om/get-shared owner :track-event) {:event-type :branch-clicked
                                                                      :properties {:repo repo-name
                                                                                   :org org-name
                                                                                   :branch (name branch-identifier)}})}
                  [:.branch
                   [:.last-build-status
                    (om/build svg {:class "badge-icon"
                                   :src (-> latest-build build-model/status-icon common/icon-path)})]
                   [:.branch-info
                    (when show-project?
                      [:.project-name
                       {:title (project-model/project-name project)}
                       (project-model/project-name project)])
                    [:.branch-name
                     {:title (utils/display-branch branch-identifier)}
                     (utils/display-branch branch-identifier)]
                    (let [last-activity-time (project-model/most-recent-activity-time branch)]
                      [:.last-build-info
                       {:title (when last-activity-time
                                 (datetime/full-datetime (js/Date.parse last-activity-time)))}
                       (if last-activity-time
                         (list
                          (om/build common/updating-duration
                                    {:start last-activity-time}
                                    {:opts {:formatter datetime/time-ago}})
                          " ago")
                         "never")])]]]
                 (when show-project?
                   (project-settings-link {:project project} owner))]))])))))

(defn project-aside [{:keys [project show-all-branches? navigation-data expanded-repos]} owner {:keys [identities]}]
  (reify
    om/IDisplayName (display-name [_] "Aside Project")
    om/IRender
    (render [_]
      (let [vcs-url (:vcs_url project)
            vcs-type (project-model/vcs-type project)
            org-name (project-model/org-name project)
            repo-name (project-model/repo-name project)]
        (html [:li
               [:.project-heading
                {:class (when (and (= vcs-type (:vcs_type navigation-data))
                                   (= org-name (:org navigation-data))
                                   (= repo-name (:repo navigation-data))
                                   (not (contains? navigation-data :branch)))
                          "selected")
                 :title (project-model/project-name project)}
                [:i.fa.rotating-chevron {:class (when (expanded-repos vcs-url) "expanded")
                                         :on-click #(raise! owner [:expand-repo-toggled {:repo vcs-url}])}]
                [:a.project-name {:href (routes/v1-project-dashboard-path {:vcs_type (:vcs_type project)
                                                                           :org (:username project)
                                                                           :repo (:reponame project)})
                                  :on-click #((om/get-shared owner :track-event) {:event-type :project-clicked
                                                                                  :properties {:org org-name
                                                                                               :repo repo-name
                                                                                               :component "branch-picker"}})}
                 (project-model/project-name project)]
                (project-settings-link {:project project} owner)]

               (when (expanded-repos vcs-url)
                 (om/build branch-list
                           {:branches (->> project
                                           project-model/branches
                                           (sort-by (comp lower-case name :identifier)))
                            :show-all-branches? show-all-branches?
                            :navigation-data navigation-data}
                           {:opts {:identities identities}}))])))))

(defn expand-menu-items [items subpage]
  (for [item items]
    (case (:type item)

      :heading
      [:.aside-item.aside-heading {:key (hash item)}
       (:title item)]

      :subpage
      [:a.aside-item {:key (hash item)
                      :href (:href item)
                      :class (when (= subpage (:subpage item)) "active")}<commit_msg>Add :vcs-type to event properties<commit_after>(ns frontend.components.aside
  (:require [cljs.core.async :as async :refer [>! <! alts! chan sliding-buffer close!]]
            [clojure.string :refer [lower-case]]
            [frontend.async :refer [raise!]]
            [frontend.components.common :as common]
            [frontend.components.license :as license]
            [frontend.components.shared :as shared]
            [frontend.components.svg :refer [svg]]
            [frontend.config :as config]
            [frontend.datetime :as datetime]
            [frontend.models.build :as build-model]
            [frontend.models.feature :as feature]
            [frontend.models.project :as project-model]
            [frontend.models.plan :as pm]
            [frontend.routes :as routes]
            [frontend.state :as state]
            [frontend.utils :as utils :include-macros true]
            [frontend.utils.github :as gh-utils]
            [frontend.utils.vcs-url :as vcs-url]
            [frontend.utils.seq :refer [select-in]]
            [goog.style]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [frontend.utils.html :refer [open-ext]]
            [frontend.utils.launchdarkly :as ld])
  (:require-macros [frontend.utils :refer [html inspect]]))

(defn status-ico-name [build]
  (case (:status build)
    "running" :busy-light

    "success" :pass-light
    "fixed"   :pass-light

    "failed"   :fail-light
    "timedout" :fail-light

    "queued"      :hold-light
    "not_running" :hold-light
    "retried"     :hold-light
    "scheduled"   :hold-light

    "canceled"            :stop-light
    "no_tests"            :stop-light
    "not_run"             :stop-light
    "infrastructure_fail" :stop-light
    "killed"              :stop-light

    :none-light))

(defn sidebar-build [build {:keys [vcs_type org repo branch latest?]}]
  [:a.status {:class (when latest? "latest")
              :href (routes/v1-build-path vcs_type org repo (:build_num build))
              :title (str (build-model/status-words build) ": " (:build_num build))}
   (common/ico (status-ico-name build))])

(defn branch [data owner]
  (reify
    om/IDisplayName (display-name [_] "Aside Branch Activity")
    om/IRender
    (render [_]
      (let [{:keys [org repo branch-data vcs_type]} data
            [name-kw branch-builds] branch-data
            display-builds (take-last 5 (sort-by :build_num (concat (:running_builds branch-builds)
                                                                    (:recent_builds branch-builds))))]
        (html
         [:li
          [:div.branch
           {:role "button"}
           [:a {:href (routes/v1-dashboard-path {:org org
                                                 :repo repo
                                                 :branch (name name-kw)
                                                 :vcs_type vcs_type})
                :title (utils/display-branch name-kw)}
            (-> name-kw utils/display-branch (utils/trim-middle 23))]]
          [:div.statuses {:role "button"}
           (for [build display-builds]
             (sidebar-build build {:vcs_type vcs_type :org org :repo repo :branch (name name-kw)}))]])))))

(defn project-settings-link [{:keys [project]} owner]
  (when (and (project-model/can-write-settings? project))
    (let [org-name (:username project)
          repo-name (:reponame project)
          vcs-type (:vcs_type project)]
      [:a.project-settings-icon {:href (routes/v1-project-settings-path {:vcs_type vcs-type
                                                                         :org org-name
                                                                         :repo repo-name})
                                 :title  (str
                                           (project-model/project-name project)
                                           " settings")
                                 :on-click #((om/get-shared owner :track-event) {:event-type :project-settings-clicked
                                                                                 :properties {:org org-name
                                                                                              :repo repo-name}})}
       [:i.material-icons "settings"]])))

(defn branch-list [{:keys [branches show-all-branches? navigation-data]} owner {:keys [identities show-project?]}]
  (reify
    om/IDisplayName (display-name [_] "Aside Branch List")
    om/IRender
      (render [_]
        (let [branches-filter (if show-all-branches?
                                (constantly true)
                                (partial project-model/personal-branch? identities))]
          (html
           [:ul.branches
            (for [branch (filter branches-filter branches)]
              (let [project (:project branch)
                    latest-build (last (sort-by :build_num (concat (:running_builds branch)
                                                                   (:recent_builds branch))))
                    vcs-type (project-model/vcs-type project)
                    org-name (project-model/org-name project)
                    repo-name (project-model/repo-name project)
                    branch-identifier (:identifier branch)]
                [:li {:key (hash [vcs-type org-name repo-name branch-identifier])
                      :class (when (and (= vcs-type (:vcs_type navigation-data))
                                        (= org-name (:org navigation-data))
                                        (= repo-name (:repo navigation-data))
                                        (= (name branch-identifier)
                                           (:branch navigation-data)))
                               "selected")}
                 [:a {:href (routes/v1-dashboard-path {:vcs_type (:vcs_type project)
                                                       :org (:username project)
                                                       :repo (:reponame project)
                                                       :branch (name branch-identifier)})
                      :on-click #((om/get-shared owner :track-event) {:event-type :branch-clicked
                                                                      :properties {:repo repo-name
                                                                                   :org org-name
                                                                                   :branch (name branch-identifier)}})}
                  [:.branch
                   [:.last-build-status
                    (om/build svg {:class "badge-icon"
                                   :src (-> latest-build build-model/status-icon common/icon-path)})]
                   [:.branch-info
                    (when show-project?
                      [:.project-name
                       {:title (project-model/project-name project)}
                       (project-model/project-name project)])
                    [:.branch-name
                     {:title (utils/display-branch branch-identifier)}
                     (utils/display-branch branch-identifier)]
                    (let [last-activity-time (project-model/most-recent-activity-time branch)]
                      [:.last-build-info
                       {:title (when last-activity-time
                                 (datetime/full-datetime (js/Date.parse last-activity-time)))}
                       (if last-activity-time
                         (list
                          (om/build common/updating-duration
                                    {:start last-activity-time}
                                    {:opts {:formatter datetime/time-ago}})
                          " ago")
                         "never")])]]]
                 (when show-project?
                   (project-settings-link {:project project} owner))]))])))))

(defn project-aside [{:keys [project show-all-branches? navigation-data expanded-repos]} owner {:keys [identities]}]
  (reify
    om/IDisplayName (display-name [_] "Aside Project")
    om/IRender
    (render [_]
      (let [vcs-url (:vcs_url project)
            vcs-type (project-model/vcs-type project)
            org-name (project-model/org-name project)
            repo-name (project-model/repo-name project)]
        (html [:li
               [:.project-heading
                {:class (when (and (= vcs-type (:vcs_type navigation-data))
                                   (= org-name (:org navigation-data))
                                   (= repo-name (:repo navigation-data))
                                   (not (contains? navigation-data :branch)))
                          "selected")
                 :title (project-model/project-name project)}
                [:i.fa.rotating-chevron {:class (when (expanded-repos vcs-url) "expanded")
                                         :on-click #(raise! owner [:expand-repo-toggled {:repo vcs-url}])}]
                [:a.project-name {:href (routes/v1-project-dashboard-path {:vcs_type (:vcs_type project)
                                                                           :org (:username project)
                                                                           :repo (:reponame project)})
                                  :on-click #((om/get-shared owner :track-event) {:event-type :project-clicked
                                                                                  :properties {:vcs-type (:vcs_type project)
                                                                                               :org org-name
                                                                                               :repo repo-name
                                                                                               :component "branch-picker"}})}
                 (project-model/project-name project)]
                (project-settings-link {:project project} owner)]

               (when (expanded-repos vcs-url)
                 (om/build branch-list
                           {:branches (->> project
                                           project-model/branches
                                           (sort-by (comp lower-case name :identifier)))
                            :show-all-branches? show-all-branches?
                            :navigation-data navigation-data}
                           {:opts {:identities identities}}))])))))

(defn expand-menu-items [items subpage]
  (for [item items]
    (case (:type item)

      :heading
      [:.aside-item.aside-heading {:key (hash item)}
       (:title item)]

      :subpage
      [:a.aside-item {:key (hash item)
                      :href (:href item)
                      :class (when (= subpage (:subpage item)) "active")}
{'fraction_non_alphanumeric': 0.11182108626198083, 'fraction_numerical': 0.0007408436356901422, 'mean_word_length': 1.149696426794068, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 172, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479157', 'n_tokens_mistral': 5355, 'n_tokens_neox': 5044, 'n_words': 1178}