Skip to content

Commit

Permalink
feat: support Slack user groups (#116)
Browse files Browse the repository at this point in the history
Slack user groups (subteams) are supported.

Closes #115
  • Loading branch information
pilosus committed May 25, 2024
1 parent b927d42 commit a9528c5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/dienstplan/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Caveats:
@dienstplan help
```")

(def regex-user-mention #"(?s)(?<userid>\<@[A-Z0-9]+\>)")
(def regex-user-mention #"(?s)(\<@[A-Z0-9]+\>)|(\<!subteam\^.*?\>)")

(def regex-channel-mention #"(?s)(?<channelid>\<#[A-Z0-9]+\>)")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/dienstplan/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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)))))))
Expand Down
8 changes: 7 additions & 1 deletion test/dienstplan/commands_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
["run command for users <@U123>, <@U345> and <@U678> please"
["<@U123>" "<@U345>" "<@U678>"]
"Multiple users mentioned"]
["user group <!subteam^S075SU084QG|@compliance-team> mentioned"
["<!subteam^S075SU084QG|@compliance-team>"]
"User group"]
["user group <!subteam^S075SU084QG|@zdravstvuy-товарищ-bürgermeister> mentioned"
["<!subteam^S075SU084QG|@zdravstvuy-товарищ-bürgermeister>"]
"Unicode characters"]
[nil nil "Nil"]
["" nil "Blank string"]])

Expand Down Expand Up @@ -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"}}
[]
Expand Down

0 comments on commit a9528c5

Please sign in to comment.