<commit_before>(ns github-bot-app.action.merge-conflict
  (:require [clojure.tools.logging :as log]
            [tentacles.issues :as gh-issues]
            [tentacles.pulls :as gh-pulls]
            [github-bot-app.pools :as pools]
            [github-bot-app.action.timer :refer [github-api-time!]])
  (:import java.util.concurrent.TimeUnit))


(defn- search-open-pulls
  [owner repo base-ref config]
  (github-api-time!
    (gh-pulls/pulls
     owner repo
     (merge
      (:auth-options config)
      {:state "open"
       :base base-ref}))))


(defn- specific-pull
  [owner repo pull-id config]
  (github-api-time!
    (gh-pulls/specific-pull
     owner repo pull-id
     (:auth-options config))))


(defn run-action [event payload config]
  (when (and (= event
                "pull_request")
             (= (:action payload)
                "closed")
             (get-in payload [:pull_request :merged] false))
    (let [owner (get-in payload [:repository :owner :login])
          repo (get-in payload [:repository :name])
          merged-pull-id (get-in payload [:pull_request :number])
          base-ref (get-in payload [:pull_request :base :ref])
          open-pulls (search-open-pulls owner repo base-ref config)
          schedule-uuid (java.util.UUID/randomUUID)]
      (log/info (pr-str
                 {:event :pull-request
                  :action :merged
                  :number merged-pull-id
                  :base-ref base-ref
                  :others {:count (count open-pulls)
                           :numbers (map :number open-pulls)}}))
      (doseq [p open-pulls]
        (pools/dispatch
         #(let [pull (specific-pull owner repo (:number p) config)]
            (-> pull
                (select-keys [:number :state :mergeable])
                (merge {:api-call :specific-pull})
                pr-str
                log/info))))
      (pools/schedule
       5 TimeUnit/MINUTES
       (fn []
         (log/info (pr-str {:schedule :run
                            :task schedule-uuid}))
         (pools/dispatch
          (fn []
            (let [open-pulls-later (search-open-pulls owner repo base-ref config)]
              (log/info {:api-call :open-pulls
                         :base-ref base-ref
                         :count (count open-pulls-later)
                         :numbers (map :number open-pulls-later)})
              (doseq [p open-pulls-later]
                (pools/dispatch
                 (fn []
                   (let [pull-id (:number p)
                         pull (specific-pull owner repo pull-id config)]
                     (-> pull
                         (select-keys [:number :state :mergeable])
                         (merge {:api-call :specific-pull})
                         pr-str
                         log/info)                     
                     (when (not (get pull :mergeable true))<commit_msg>only signal merge conflicts if ‘mergeable’ is set to false<commit_after>(ns github-bot-app.action.merge-conflict
  (:require [clojure.tools.logging :as log]
            [tentacles.issues :as gh-issues]
            [tentacles.pulls :as gh-pulls]
            [github-bot-app.pools :as pools]
            [github-bot-app.action.timer :refer [github-api-time!]])
  (:import java.util.concurrent.TimeUnit))


(defn- search-open-pulls
  [owner repo base-ref config]
  (github-api-time!
    (gh-pulls/pulls
     owner repo
     (merge
      (:auth-options config)
      {:state "open"
       :base base-ref}))))


(defn- specific-pull
  [owner repo pull-id config]
  (github-api-time!
    (gh-pulls/specific-pull
     owner repo pull-id
     (:auth-options config))))


(defn run-action [event payload config]
  (when (and (= event
                "pull_request")
             (= (:action payload)
                "closed")
             (get-in payload [:pull_request :merged] false))
    (let [owner (get-in payload [:repository :owner :login])
          repo (get-in payload [:repository :name])
          merged-pull-id (get-in payload [:pull_request :number])
          base-ref (get-in payload [:pull_request :base :ref])
          open-pulls (search-open-pulls owner repo base-ref config)
          schedule-uuid (java.util.UUID/randomUUID)]
      (log/info (pr-str
                 {:event :pull-request
                  :action :merged
                  :number merged-pull-id
                  :base-ref base-ref
                  :others {:count (count open-pulls)
                           :numbers (map :number open-pulls)}}))
      (doseq [p open-pulls]
        (pools/dispatch
         #(let [pull (specific-pull owner repo (:number p) config)]
            (-> pull
                (select-keys [:number :state :mergeable])
                (merge {:api-call :specific-pull})
                pr-str
                log/info))))
      (pools/schedule
       5 TimeUnit/MINUTES
       (fn []
         (log/info (pr-str {:schedule :run
                            :task schedule-uuid}))
         (pools/dispatch
          (fn []
            (let [open-pulls-later (search-open-pulls owner repo base-ref config)]
              (log/info {:api-call :open-pulls
                         :base-ref base-ref
                         :count (count open-pulls-later)
                         :numbers (map :number open-pulls-later)})
              (doseq [p open-pulls-later]
                (pools/dispatch
                 (fn []
                   (let [pull-id (:number p)
                         pull (specific-pull owner repo pull-id config)]
                     (-> pull
                         (select-keys [:number :state :mergeable])
                         (merge {:api-call :specific-pull})
                         pr-str
                         log/info)                     
                     (when (false? (:mergeable pull))
{'fraction_non_alphanumeric': 0.12215957628566547, 'fraction_numerical': 0.00034170510849137196, 'mean_word_length': 1.4412010008340284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6429754', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1634, 'n_words': 406}