From a9528c5326d38e615c14d68b755b6e9523dd5411 Mon Sep 17 00:00:00 2001 From: Vitaly Samigullin Date: Sat, 25 May 2024 14:47:07 +0000 Subject: [PATCH] feat: support Slack user groups (#116) Slack user groups (subteams) are supported. Closes https://github.com/pilosus/dienstplan/issues/115 --- CHANGELOG.md | 4 +++- src/dienstplan/commands.clj | 6 +++--- test/dienstplan/api_test.clj | 4 ++-- test/dienstplan/commands_test.clj | 8 +++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a7ae4..3414832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ file. This change log follows the conventions of ## [Unreleased] -Nothing here yet. +- Support user groups + ([#115](https://github.com/pilosus/dienstplan/issues/115)) so that + they can be used in rotations just like normal users. ### Added diff --git a/src/dienstplan/commands.clj b/src/dienstplan/commands.clj index 5bb7a63..8d91ba5 100644 --- a/src/dienstplan/commands.clj +++ b/src/dienstplan/commands.clj @@ -252,7 +252,7 @@ Caveats: @dienstplan help ```") -(def regex-user-mention #"(?s)(?\<@[A-Z0-9]+\>)") +(def regex-user-mention #"(?s)(\<@[A-Z0-9]+\>)|(\)") (def regex-channel-mention #"(?s)(?\<#[A-Z0-9]+\>)") @@ -352,7 +352,7 @@ Caveats: helpers/stringify string/trim) users (re-seq regex-user-mention text) - result (if users (map #(second %) users) nil)] + result (if users (map #(first %) users) nil)] result)) ;; Parse command arguments @@ -485,7 +485,7 @@ Caveats: text (if duty (format - "Hey %s, you are an on-call person for `%s` rotation.\n%s" + "Hey %s, you are an on-call for `%s` rotation.\n%s" duty rotation description) (format "Rotation `%s` not found in channel %s" diff --git a/test/dienstplan/api_test.clj b/test/dienstplan/api_test.clj index 78a55f7..c705090 100644 --- a/test/dienstplan/api_test.clj +++ b/test/dienstplan/api_test.clj @@ -136,7 +136,7 @@ (is (= 200 (:status who-response))) (is (= {:channel "C123" - :text "Hey <@U123>, you are an on-call person for `my-rota` rotation.\nDo what thou wilt shall be the whole of the Law"} + :text "Hey <@U123>, you are an on-call for `my-rota` rotation.\nDo what thou wilt shall be the whole of the Law"} (-> who-response :body (json/parse-string true)))) @@ -343,7 +343,7 @@ (is (= 200 (:status who-response))) (is (= {:channel "C123" - :text "Hey <@U789>, you are an on-call person for `my-rota` rotation.\nDo what thou wilt shall be the whole of the Law"} + :text "Hey <@U789>, you are an on-call for `my-rota` rotation.\nDo what thou wilt shall be the whole of the Law"} (-> who-response :body (json/parse-string true))))))) diff --git a/test/dienstplan/commands_test.clj b/test/dienstplan/commands_test.clj index c183716..686983d 100644 --- a/test/dienstplan/commands_test.clj +++ b/test/dienstplan/commands_test.clj @@ -72,6 +72,12 @@ ["run command for users <@U123>, <@U345> and <@U678> please" ["<@U123>" "<@U345>" "<@U678>"] "Multiple users mentioned"] + ["user group mentioned" + [""] + "User group"] + ["user group mentioned" + [""] + "Unicode characters"] [nil nil "Nil"] ["" nil "Blank string"]]) @@ -500,7 +506,7 @@ (def params-command-exec!-who [[{:context {:channel "channel" :ts "1640250011.000100"} :command :who :args {:rotation "rota"}} {:mention/duty "user1" :rota/description "Do what thou wilt shall be the whole of the Law"} - "Hey user1, you are an on-call person for `rota` rotation.\nDo what thou wilt shall be the whole of the Law" + "Hey user1, you are an on-call for `rota` rotation.\nDo what thou wilt shall be the whole of the Law" "Rota found"] [{:context {:channel "channel" :ts "1640250011.000100"} :command :who :args {:rotation "rota"}} []