Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Slack mentions #143

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

phongulus
Copy link
Contributor

@phongulus phongulus commented Mar 14, 2024

Description of the task

Basic support for Slack mentions. When a GitHub handle can be matched with a Slack email, the Slack user is mentioned in Monorobot's messages and unfurled links (only links from supported repos).

The matching is done by

  • removing all hyphens, dots from the GitHub handle and lowercase-ing.
  • canonicalising the Slack email address, removing hyphens, removing the email domain, lowercase.

Monorobot keeps a cache of the Slack user list that's refreshed every 24 hours. Alternatively, GitHub handle to Slack email mapping can also be manually injected in .monorobot.json under user_mappings - in the case of conflicting mappings, the mapping in .monorobot.json takes precedence.

If Monorobot can't match a Slack user in the cached mapping, they are not mentioned.

How to test

Some basic tests were added. Test with

make runtest

Old tests should remain the same, as the GitHub handles there are not present in the Slack user list cache file.

References

@phongulus phongulus changed the title WIP: Support for Slack mentions Support for Slack mentions Mar 18, 2024
@phongulus phongulus marked this pull request as ready for review March 18, 2024 10:00
lib/api_remote.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/slack.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
@phongulus
Copy link
Contributor Author

phongulus commented Mar 25, 2024

This is what the mentions look like right now:

Monorobot messages:

Screenshot 2024-03-25 at 12 45 47

Unfurled links:

Screenshot 2024-03-25 at 12 46 48

Mentions in the author_name field of unfurls don't get properly decoded by Slack, so I'm putting them in pretext.

@phongulus phongulus requested a review from tysg March 25, 2024 04:50
lib/action.ml Outdated Show resolved Hide resolved
@phongulus
Copy link
Contributor Author

Rolled back mentions in push/commit notifications @yasunariw @tysg. Now things look like this:

Screenshot 2024-03-25 at 16 42 08

lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/api_local.ml Outdated Show resolved Hide resolved
lib/api_remote.ml Outdated Show resolved Hide resolved
lib/slack.ml Outdated Show resolved Hide resolved
lib/slack.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
let ({ sha; commit; author; files; _ } : api_commit) = api_commit in
let title = Slack.pp_api_commit api_commit in
let slack_mention =
match author with
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option.map_default ? or is it done like this for readability ?

Copy link
Contributor Author

@phongulus phongulus Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember, but I suppose the current match statement would look a bit cleaner since using Option.map_default would look something like this:

let slack_mention =
    author
    |> Option.map_default
        (fun gh_user -> gh_user |> match_github_user_to_slack_id |> Slack.format_slack_mention)
        ""

@rr0gi
Copy link
Contributor

rr0gi commented Apr 1, 2024

(please cleanup the commits / squash before merge)

lib/action.ml Outdated Show resolved Hide resolved
src/request_handler.ml Outdated Show resolved Hide resolved
lib/slack_message.ml Outdated Show resolved Hide resolved
lib/slack.atd Outdated Show resolved Hide resolved
lib/slack.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
src/request_handler.ml Outdated Show resolved Hide resolved
@@ -105,6 +105,7 @@ let () =
| Ok config ->
match Context.refresh_secrets ctx with
| Ok ctx ->
let%lwt () = Action_local.refresh_username_to_slack_id_tbl ~ctx in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test harness should be modified to refresh the context with a handcrafted mapping (in OCaml, not from file) for some github/slack profiles in the existing test cases

I would prefer to update the output of the existing test cases with the changes from this feature, not to create new ones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably a good idea to have a separate file for Slack profiles, since we'd probably want to test with an actual Slack users.list payload. I don't think the existing test cases have any message body with GitHub user mentions either, so we should keep some of the new test files.

lib/action.ml Outdated Show resolved Hide resolved
Copy link
Collaborator

@yasunariw yasunariw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! lgtm, let's cleanup commits and merge

@phongulus phongulus force-pushed the phong/github-username-with-slack branch 2 times, most recently from 3d45ae8 to 60866f4 Compare April 22, 2024 02:57
@phongulus phongulus force-pushed the phong/github-username-with-slack branch from 60866f4 to 94d723f Compare April 22, 2024 04:51
@yasunariw yasunariw merged commit 0b08002 into ahrefs:master Apr 22, 2024
1 check passed
@rr0gi
Copy link
Contributor

rr0gi commented May 16, 2024

this behaviour should be mentioned in readme please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants