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

Enable link unfurling for Slack messages (with commit link support) #101

Merged
merged 10 commits into from
Jan 4, 2021

Conversation

yasunariw
Copy link
Collaborator

@yasunariw yasunariw commented Dec 28, 2020

Description of the task

(depends on #94)

This PR creates an initial thin pipeline for adding link unfurling functionality to Slack messages. We support commit links for now, with the possibility of extension to other link types (e.g., issues, PRs) down the road.

One caveat is that currently, Slack message generation code for unfurled links and event notifications reside in separate files (slack_message.ml and slack.ml respectively). This is because the latter message format tightly couples description of an action on a GH resource (e.g., "opened a PR", "pushed commits", "merged issue") with description of the resource itself (e.g., "a PR w/ N comments", "commit xyz with 5 changed files"). Since unfurled messages only need the latter, we can't take advantage of the existing code in slack.ml elegantly. A near-future goal should be to share more code between them. (Code reuse seems to be a concern from before -- #54)

Users first need to configure their app to support the unfurling. Part of it is to support Slack's Events API, which this PR implements.

Like GH's official integration, we don't unfurl when a message contains three or more links.

How to test

This shouldn't affect existing tests. New tests for url pattern matching are defined in tests/github_link_test.ml. You can also test by posting messages w/ links to a channel the bot is a member of.

make test

References

@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch from b1abb0a to 76cb8bb Compare December 28, 2020 14:30
@yasunariw yasunariw force-pushed the yasu/slack-webhook-to-api branch from 67f0996 to 6451321 Compare December 29, 2020 01:46
@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch 2 times, most recently from 115dfb8 to 78e7077 Compare December 29, 2020 09:41
@yasunariw yasunariw force-pushed the yasu/slack-webhook-to-api branch from 6451321 to cf9b42f Compare December 29, 2020 23:49
@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch 2 times, most recently from d3462c8 to 82fb241 Compare December 30, 2020 11:04
@yasunariw yasunariw force-pushed the yasu/slack-webhook-to-api branch from cf9b42f to d527ce4 Compare December 30, 2020 12:43
@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch from 82fb241 to 495382b Compare December 30, 2020 12:43
@yasunariw yasunariw marked this pull request as ready for review December 30, 2020 12:46
@yasunariw yasunariw changed the title Unfurl PR, issue, and commit links in Slack messages Unfurl commit links in Slack messages Dec 30, 2020
@yasunariw yasunariw changed the title Unfurl commit links in Slack messages Enable link unfurling for Slack messages (with commit link support) Dec 30, 2020
Copy link
Contributor

@ygrek ygrek left a comment

Choose a reason for hiding this comment

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

minor comments, please fix and merge

@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch from 495382b to f961df5 Compare December 31, 2020 10:25
@yasunariw yasunariw force-pushed the yasu/slack-webhook-to-api branch from 6e18496 to 7404d4a Compare January 4, 2021 02:51
@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch from f961df5 to 3200af0 Compare January 4, 2021 06:26
@yasunariw yasunariw changed the base branch from yasu/slack-webhook-to-api to master January 4, 2021 06:28
The new file `slack_message.ml` should only contain generation
logic for messages that describe the state of some info on GH
(e.g., a description of a PR), and *not* an action taken on GH
(e.g, "XYZ opened a PR".

This decoupling is desired because we eventually want to reuse
code between link unfurl generation and event notification
generation, and link unfurl only concerns the former type of
info described above. Currently, it's difficult to do as
there is tight coupling in `slack.ml`.

Currently we support commit link unfurls. We can later easily
expand the selection of unfurlable links by adding onto
`slack_message.ml`.
Link unfurling requires usage of Slack's Events API. The first
step in configuring it is url verification. Subsequently, we can
start accepting event callback notifications, one of which is
chat_unfurl.
Again, currently supports commit links but can be extended later on.

We shouldn't unfurl if three or more links are present, or if the
link type isn't supported for none of the urls.
Check for different possible url schemes and other variations.
@yasunariw yasunariw force-pushed the yasu/slack-unfurl-links branch from 3200af0 to cfc4921 Compare January 4, 2021 06:46
@yasunariw yasunariw merged commit ea80939 into master Jan 4, 2021
@yasunariw yasunariw deleted the yasu/slack-unfurl-links branch January 4, 2021 07:48
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

2 participants