Created
December 14, 2023 00:12
-
-
Save escherize/f70f20fee56bf9f0724934fde1fdff6a 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
(ns emoji-hash | |
(:require | |
;; n.b. these can be used inside of mods.edn! | |
[babashka.http-client :as http] | |
;; [babashka.deps :as deps] | |
[babashka.pods :as pods] | |
[babashka.process :refer [process check sh pipeline pb]] | |
[babashka.fs :as fs] | |
[babashka.tasks :refer [shell]] | |
[cheshire.core :as json] | |
[clojure.core.match :refer [match]] | |
[clojure.java.browse :as browse] | |
[clojure.string :as str] | |
[clojure.pprint :as pprint] | |
[huff2.core :as h] | |
[huff2.extension :as h2e] | |
[org.httpkit.server :as httpkit.server] | |
[selmer.parser :refer [<<]] | |
[clojure.walk :as walk] | |
[honey.sql :as hdb] | |
[camel-snake-kebab.core :as csk])) | |
(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 slack-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/{{owner}}/{{repo}}/issues/{{issue-num}}") | |
http/get | |
:body | |
(json/decode keyword) | |
:title | |
slack-sanitize)) | |
(defn -main [& args] | |
(let [[issue-num] args] | |
(println (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 e | |
(format "[#%s](https://github.com/metabase/metabase/pull/%s)" issue-num issue-num)))))) | |
(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