Created
December 14, 2023 02:09
-
-
Save escherize/f308ee4ee58970671de3d2da93b8c76c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(ns emoji-hash | |
(:require [babashka.deps :as deps] | |
[babashka.http-client :as http] | |
[cheshire.core :as json] | |
[clj-yaml.core :as yaml] | |
[clojure.data.xml :as xml] | |
[clojure.edn :as edn] | |
[selmer.parser :refer [<<]] | |
[clojure.string :as str])) | |
#_(deps/add-deps '{:deps {}}) | |
(def emojis | |
["๐" "๐" "๐" "๐" "๐" "๐ " "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" | |
"๐" "๐" "๐" "๐" "๐" "๐" "๐" #_"๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" | |
#_"๐" #_"๐" "๐ " "๐ก" "๐ข" "๐ฃ" "๐ค" #_"๐ฅ" "๐ฆ" #_"๐ง" #_"๐จ" #_"๐ฉ" "๐ช" #_"๐ซ" "๐ฌ" | |
"๐ญ" "๐ฎ" #_"๐ฏ" "๐ฐ" #_"๐ฑ" #_"๐ฒ" "๐ณ" "๐ด" "๐ต" "๐ถ" "๐ท" "๐ธ" "๐น" "๐บ" "๐ป" | |
"๐ผ" "๐ฝ" "๐พ" "๐ฟ" "๐" "๐" "๐" "๐" "๐" "๐ " "๐" "๐" "๐" "๐" "๐" | |
#_"๐" "๐" #_"๐" #_"๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐ " "๐" "๐" "๐" "๐" | |
"๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" | |
"๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐ " "๐ก" "๐ข" "๐ฃ" "๐ค" "๐ฅ" "๐ฆ" "๐ง" | |
"๐จ" #_"๐ฉ" "๐ช" "๐ซ" "๐ฌ" "๐ญ" "๐ฎ" "๐ฏ" "๐ฐ" "๐ฑ" "๐ฒ" "๐ณ" "๐ด" "๐ต" "๐ถ" | |
"๐ท" "๐ธ" "๐น" "๐บ" "๐ป" "๐ผ" "๐ฝ" "๐พ" "๐ฟ" "๐" "๐" "๐" "๐" "๐" "๐ " | |
"๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐" "๐ " "๐ก" | |
"๐ข" "๐ฃ" "๐ค" "๐ฅ" "๐ฉ" "๐ซ" "๐ฌ" "๐ฐ" "๐ณ" "๐ด" "๐ต" "๐ถ" "๐ท" "๐ธ" "๐น" "๐บ" | |
"๐ป" "๐ผ" "๐ " "๐ก" "๐ข" "๐ฃ" "๐ค" "๐ฅ" "๐ฆ" "๐ง" "๐จ" "๐ฉ" "๐ช" "๐ซ"]) | |
(defn hash-to-emojis [obj] | |
(let [h1 (hash obj) | |
h2 (hash h1) | |
index1 (mod h1 (count emojis)) | |
index2 (mod h2 (count emojis)) | |
emoji1 (nth (cycle emojis) index1) | |
emoji2 (nth (cycle emojis) index2)] | |
(str emoji1 emoji2))) | |
(defn sanitize [s] | |
(let [replace {""" "\"" "&" "&" "<" "<" | |
">" ">" "'" "'" " " " " "'" "'" | |
;; can't have [ or ] inside a slack link! | |
"]" "โฉ" "[" "โจ"}] | |
(reduce (fn [s [k v]] (clojure.string/replace s k v)) s replace))) | |
(defn get-title [owner repo issue-num] | |
(-> "https://api.github.com/repos/%s/%s/issues/%s" | |
(format owner repo issue-num) | |
http/get :body (json/decode keyword) :title sanitize)) | |
(defn emoji-hash [issue-num] | |
(try | |
(format "%s:[%s](https://github.com/metabase/metabase/pull/%s)" | |
(hash-to-emojis issue-num) | |
(get-title "metabase" "metabase" issue-num) | |
issue-num) | |
(catch Exception _ | |
(format "[#%s](https://github.com/metabase/metabase/pull/%s)" issue-num issue-num)))) | |
(defn -main [& args] | |
(let [issue-number (first *command-line-args*)] | |
(when-not (re-matches #"\d+" issue-number) | |
(binding [*out* *err*] | |
(println "Usage: eh issue-number"))) | |
(println (emoji-hash issue-number)))) | |
(when (= *file* (System/getProperty "babashka.file")) | |
(apply -main *command-line-args*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment