From 09b3d1510b55bb59e56448a6c0257feb3802c0c7 Mon Sep 17 00:00:00 2001 From: eyjhb Date: Wed, 12 Mar 2025 00:02:58 +0100 Subject: [PATCH 1/5] notify: fewer words for a token --- machines/gerd/services/notify/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machines/gerd/services/notify/app.py b/machines/gerd/services/notify/app.py index cbc0fa1..7c6a083 100644 --- a/machines/gerd/services/notify/app.py +++ b/machines/gerd/services/notify/app.py @@ -361,7 +361,7 @@ def set_user_default_matrix_room(username: str, roomid: str): con.commit() -def generate_token(num_words: int = 5) -> str: +def generate_token(num_words: int = 3) -> str: mnemo = Mnemonic("english") words = mnemo.generate(strength=256) return "-".join(words.split(" ")[0:num_words]) From 5564c8cbfcb4f8efd60b81288b2f1c474f34ed69 Mon Sep 17 00:00:00 2001 From: eyjhb Date: Wed, 12 Mar 2025 00:03:15 +0100 Subject: [PATCH 2/5] notify: no need to include dashes in token --- machines/gerd/services/notify/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/machines/gerd/services/notify/app.py b/machines/gerd/services/notify/app.py index 7c6a083..88dcd9d 100644 --- a/machines/gerd/services/notify/app.py +++ b/machines/gerd/services/notify/app.py @@ -291,7 +291,8 @@ def send_notification(): con = get_db() cur = con.cursor() res = cur.execute( - "SELECT username FROM tokens WHERE token = ?", (token,) + "SELECT username FROM tokens WHERE REPLACE(token, '-', '') = ? OR token = ? ", + (token, token), ).fetchone() if not res: From 2380f6694da2c933eac9f9fbe0f03b834fe6fda0 Mon Sep 17 00:00:00 2001 From: eyjhb Date: Wed, 12 Mar 2025 00:04:14 +0100 Subject: [PATCH 3/5] notify: better documentation --- machines/gerd/services/notify/app.py | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/machines/gerd/services/notify/app.py b/machines/gerd/services/notify/app.py index 88dcd9d..2de7532 100644 --- a/machines/gerd/services/notify/app.py +++ b/machines/gerd/services/notify/app.py @@ -222,6 +222,18 @@ def index(): default room !yREJWHUMJhGROiHbtu:fricloud.dk or #na-offtopic:rend.al + + token + Authorization Token + empty + enable-trade-decide or enabletradedecide + + + jq + jq filter + . + [.[].commits | .name ] | join("\\n") +
@@ -240,6 +252,27 @@ def index(): doCheck = false; }} ''{script_example_with_token}''; +
+

Notes

+

+ jq is very powerful, and can easily be used to turn webhook data into useful information in a notification. + Just append your `jq=`, to your notification URL, and then watch the magic. + Below is an example for doing it with Forgejo, when new commits are pushed. +

+ +
(.total_commits | tostring)
++ " commits pushed to "
++ .repository.full_name
++ "\n\n" +
+  # format commits
+  ([.commits.[]
+  | "- "
+    + (.message | gsub("[\n\t]"; ""))
+    + " (" + .author.name + ")" ]
+  | join("\n"))
++ "\n\n"
++ "Changes: " + .compare_url
+