add Matrix Integration option
Review Request #11219 — Created Oct. 14, 2020 and submitted
Admins can choose to add Matrix Integration.
This will send notifications to the registered matrix room
about new review requets and updates to existing ones.
Tested in RB4.
Edited Slack unit test cases to test Matrix integration.
All tests have passed except 2 of then complaining about
missing image attachmenttests with errors are:
- test_notify_new_review_request_with_image_file_attachment
- test_notify_updated_review_request_with_new_image_attachments
Summary | ID | Author |
---|---|---|
1856a55e951f1b646079b6489dad7d121359f98a | ruonan |
Description | From | Last Updated |
---|---|---|
I think you might need to uncommit the files in the .idea/ directory since they are from PyCharm |
hailan | |
Can you please attach the icon.png and icon@2x.png files to the review request? |
david | |
Hmmm... the mentors will have the final say on this. Personally, I would move the matrixValue lines to MatrixIntegration, since … |
hailan | |
I just realized today that the integrations are in alphabetical order. So, you may want to move MatrixIntegration at lines … |
hailan | |
Hm - it looks like we're hardcoding in the matrix.org homeserver in here. But we should make it so that … |
mike_conley | |
'Slack' to 'Matrix' |
hailan | |
'Slack' to 'Matrix' |
hailan | |
Does Matrix also require urls to be formatted like this? If so, maybe replace Slack/Mattermost with Matrix in the comments |
hailan | |
'Slack' -> 'Matrix' |
hailan | |
E501 line too long (87 > 79 characters) |
reviewbot | |
I agree with Hailan's review that this smells bad. Since we already have code that's checking the fields, let's pull … |
david | |
Please keep this list in alphabetical order. |
david | |
Please add a blank line between these two. The module docstring should also be clear that this is about matrix. |
david | |
Does the capitalization listed here match the capitalization in the matrix app? If it's capitalized there, it should be here … |
david | |
Please add a period at the end of this help text. |
david | |
Can we tweak the usage of "e.g." here? "The server HTTP requests will be sent to, e.g., https://matrix.org" |
david | |
This can wrap a little bit tighter. |
david | |
Please add a module docstring to this file. |
david | |
Let's switch these to keep them in alphabetical order. |
david | |
We need to be very careful regarding the use of str in Python, because it has different meanings in Python … |
david | |
Same comments here regarding str and format_html |
david | |
Same comments here regarding str and format_html |
david | |
This is probably fine to keep since it's a debug message, but let's use a named logger. At the top-level … |
david | |
This would be better using a format string: url = ('%s/_matrix/client/r0/rooms/%s/send/' 'm.room.message?access_token=%s' % (server, room_id, access_token)) |
david | |
This blank line can go away. |
david | |
Instead of using the continuation character here, can we just wrap it in parens? |
david | |
It feels like the contents of the notify method could be moved back into this class. We're not calling it … |
david | |
Leftover debug output? |
david | |
Leftover debug output? |
david | |
Leftover debug output? |
david | |
Col: 10 'authorize' is defined but never used. |
reviewbot | |
This should be moved, so that it is in alphabetical order. |
jblazusi | |
I forgot to include that I think that this field should have a default value set to https://matrix.org. I am … |
jblazusi | |
Lines 10 and 11 should be swapped, so that the alphabetical order is maintained. |
jblazusi | |
This comment should end with a period. |
jblazusi | |
E302 expected 2 blank lines, found 1 |
reviewbot | |
E303 too many blank lines (2) |
reviewbot | |
E127 continuation line over-indented for visual indent |
reviewbot | |
E127 continuation line over-indented for visual indent |
reviewbot | |
W291 trailing whitespace |
reviewbot | |
E127 continuation line over-indented for visual indent |
reviewbot | |
W293 blank line contains whitespace |
reviewbot | |
E303 too many blank lines (3) |
reviewbot | |
E128 continuation line under-indented for visual indent |
reviewbot | |
E128 continuation line under-indented for visual indent |
reviewbot | |
E128 continuation line under-indented for visual indent |
reviewbot | |
E128 continuation line under-indented for visual indent |
reviewbot | |
E127 continuation line over-indented for visual indent |
reviewbot | |
E128 continuation line under-indented for visual indent |
reviewbot | |
E127 continuation line over-indented for visual indent |
reviewbot | |
E302 expected 2 blank lines, found 1 |
reviewbot | |
E127 continuation line over-indented for visual indent |
reviewbot | |
Please add a second blank line here. |
david | |
This needs a docstring. |
david | |
It might be nice to change this to use re.sub and pass a function for the repl argument. That way … |
david | |
This should use format_html from django.utils.html. |
david | |
This should use format_html from django.utils.html. Please also use single quotes. |
david | |
Please use single quotes throughout. Final item also needs a trailing comma. |
david | |
This needs a module docstring. |
david | |
This needs a class docstring. |
david | |
Please put this """ on its own line. |
david | |
This needs a trailing comma. |
david | |
This line can go away. |
david | |
Please add a docstring for this. |
david | |
E128 continuation line under-indented for visual indent |
reviewbot | |
E128 continuation line under-indented for visual indent |
reviewbot | |
"Matrix" |
chipx86 | |
It looks like the text is wrapping too early. You should be able to fit more per line, I think? |
chipx86 | |
Same here. |
chipx86 | |
will be sent to. |
chipx86 | |
... and clicking on the "Advanced" tab. |
chipx86 | |
This should be replace_shortcode. It should also go on the class, since it's specific to this implementation. |
chipx86 | |
Docstring summaries must be one line, without wrapping, and must fit within column bounds. |
chipx86 | |
How about: "... replaced by their equivalent Unicode characters." |
chipx86 | |
No blank line here. |
chipx86 | |
emoji_unicode |
chipx86 | |
We should define the regex as a constant and compile it, so this is faster every time it needs to … |
chipx86 | |
We don't need to mention Slack here, since this isn't related to Slack's implementation, right? |
chipx86 | |
This should be localized using ugettext_lazy. |
chipx86 | |
Mind sorting these alphabetically? It helps with maintenance. |
chipx86 | |
This will be nicer if formatted as: ASSETS_BASE_URL = \ 'https://...' |
chipx86 | |
Since this is newly-added, let's pick a more modern date and time (like today's). |
chipx86 | |
The order of arguments here doesn't match the documented order. Can you fix that up? |
chipx86 | |
This needs , optional. |
chipx86 | |
This needs , optional. |
chipx86 | |
String building is faster using format strings (%). |
chipx86 | |
Same here. |
chipx86 | |
This will need an .encode('utf-8') after it. |
chipx86 | |
When formatting multi-line strings/arguments, we generally format it like: url = ( '...' '...' % (...) ) |
chipx86 | |
Mind alphabetizing these while you're here? |
chipx86 | |
Old code probably had an old pattern for this, but you can get rid of exc_info= and instead use logger.exception(...). |
chipx86 | |
Can this just include format_link's code from above? I don't think we need this split up at all. |
chipx86 | |
Completely optional request, but it'd be more maintainable if these could be broken up around HTML tags a bit better, … |
chipx86 | |
Feels like this wraps too early. |
chipx86 | |
Blank line betewen these. |
chipx86 | |
Formatting here isn't consistent with other tests (or style guidelines). The keys should be on their own lines. This applies … |
chipx86 | |
You'll need to pass id=10000 as a parameter to create_review_request() to avoid an issue that can impact other tests. |
chipx86 | |
Looks like a ! snuck in here. |
chipx86 | |
Missing a "Returns". |
chipx86 | |
Missing , optional. |
chipx86 | |
Is this doable at this stage? |
chipx86 | |
"profile" or "Profile"? Can you change ">" to "->"? It's more standard. |
chipx86 | |
on the "Advanced" tab. |
chipx86 | |
Let's put the "e.g., https://matrix.org" in parens, and end with a period after. |
chipx86 | |
Missing a trailing comma. |
chipx86 | |
For format_html(), it's very important that we differentiate between what's HTML and what's text going into it. We don't want … |
chipx86 | |
This will also need to use {} and arguments when calling format_html(). Also, HTML attribute values should have " around … |
chipx86 | |
String concatenation in Python isn't very efficient. Rather than doing this, a common pattern is: html = [] html.append(...) html.append(...) … |
chipx86 | |
Blank line between these. |
chipx86 | |
No blank line here. |
chipx86 | |
The pattern should be compiled for the instance in __init__, rather than each time this function is called (otherwise it … |
chipx86 | |
This should be a reviewboard.integrations.models.IntegrationConfig. |
chipx86 |
- Commits:
-
Summary ID Author ce0368c33c923cacd01d18e4f80b950c993cd160 ruonan 866d5ec060eef2a56e7dca80345522b167d0ff65 ruonan
Checks run (2 succeeded)
- Groups:
- Description:
-
~ Admins can choose to add Matrix Integration. This will send notifications to the registered matrix room about new review requets and updates to existing ones.
~ Admins can choose to add Matrix Integration.
+ This will send notifications to the registered matrix room + about new review requets and updates to existing ones. - Testing Done:
-
Tested in RB4.
~ Edited Slack unit test cases to test Matrix integration. All tests have passed except 2 of then complaining about missing image attachment ~ tests with errors are: ~ Edited Slack unit test cases to test Matrix integration. ~ All tests have passed except 2 of then complaining about + missing image attachment + + tests with errors are:
- test_notify_new_review_request_with_image_file_attachment - test_notify_updated_review_request_with_new_image_attachments
-
-
-
Hmmm... the mentors will have the final say on this. Personally, I would move the matrixValue lines to MatrixIntegration, since basechat is shared among all chat integration services. Something like "if value is :warning: then replace it with the warning emoji string '\U000026A0'"
-
-
-
Does Matrix also require urls to be formatted like this? If so, maybe replace Slack/Mattermost with Matrix in the comments
-
-
This is great work, Ruonan! Just one comment to start, since it's a high-level piece of feedback that might require you to update forms.py and integration.py.
-
Hm - it looks like we're hardcoding in the matrix.org homeserver in here. But we should make it so that custom home servers can be used, too. Can you add the server to the configuration form?
- Commits:
-
Summary ID Author 866d5ec060eef2a56e7dca80345522b167d0ff65 ruonan a90c228ba80becf283a4337552e522132d73fb6f ruonan - Diff:
-
Revision 3 (+2766)
- Commits:
-
Summary ID Author a90c228ba80becf283a4337552e522132d73fb6f ruonan 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan - Diff:
-
Revision 4 (+2768)
Checks run (2 succeeded)
-
-
I agree with Hailan's review that this smells bad. Since we already have code that's checking the fields, let's pull out the
value
and then have a small method that replaces these three shortcode emojis with the unicode values. -
-
Please add a blank line between these two. The module docstring should also be clear that this is about matrix.
-
Does the capitalization listed here match the capitalization in the matrix app? If it's capitalized there, it should be here too.
Please add a period at the end of this help text.
-
-
Can we tweak the usage of "e.g." here?
"The server HTTP requests will be sent to, e.g., https://matrix.org"
-
-
-
-
We need to be very careful regarding the use of
str
in Python, because it has different meanings in Python 2 and 3. In this case, everything is unicode so we shouldn't have to have any explicit casting.In general we prefer using format strings over the + operator for strings, but in this case since we're dealing with HTML, we should use
django.utils.html
'sformat_html
method:string = format_html('<strong>{}</strong><p>{}</p>', fallback_text, title)
This will ensure that no matter what is in those strings, we won't expose ourselves to possible XSS security problems.
-
-
-
This is probably fine to keep since it's a debug message, but let's use a named logger. At the top-level of the file, do:
logger = logging.getLogger(__name__)
Then here, change it to
logger.debug(...)
-
This would be better using a format string:
url = ('%s/_matrix/client/r0/rooms/%s/send/' 'm.room.message?access_token=%s' % (server, room_id, access_token))
-
-
-
It feels like the contents of the notify method could be moved back into this class. We're not calling it from anywhere else, and having it as its own top-level means we have that giant docstring appearing twice.
-
-
-
- Commits:
-
Summary ID Author 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan ad3ac30ded8b199586a2e0e6c1e001eea30c8af1 ruonan - Diff:
-
Revision 5 (+522 -18)
- Commits:
-
Summary ID Author ad3ac30ded8b199586a2e0e6c1e001eea30c8af1 ruonan 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan - Diff:
-
Revision 6 (+2768)
Checks run (2 succeeded)
-
Nice Work!
I am receiving a single test failure and it seems to be linked with encoding. (Test Case #57) Line 701 there is a little warning sign. Not sure whether this is intended in the test, or the integration is failing.
This also came up during manual testing. Changing the description or posting a code review succesfully displays in a Matrix Chatroom. However, when creating a general comment the request fails, due to some kind ofUnicodeEncodeError: 'ascii' codec can't u'\u26a0' in position 0: ordinal not in range(128)
. This is most likely due to the symbol, and I imagine something similar would occur if there was an error symbol.
Lastly, it would be nice if you could include pictures in the CR, similar to how Hailan has done it. This way others can download the correct images, because of this I was not able to see any of the Matrix logos. -
-
-
-
-
I forgot to include that I think that this field should have a default value set to
https://matrix.org
. I am not sure when this would be changed, maybe in the future if matrix chooses to change their server URL?It seems to be the same whether you are using the downloaded application or the web browser.
- Commits:
-
Summary ID Author 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan f03e07d68e23432826db188cacc758ea5c2a2715 ruonan
Checks run (1 failed, 1 succeeded)
flake8
- Commits:
-
Summary ID Author 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan f03e07d68e23432826db188cacc758ea5c2a2715 ruonan 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan f03e07d68e23432826db188cacc758ea5c2a2715 ruonan 53b0abfba0c21358ae40c84d9f5e40ddce30904e ruonan
Checks run (1 failed, 1 succeeded)
flake8
- Commits:
-
Summary ID Author 93a0f81d3d91d67cd63dd8813aad1e0f50794538 ruonan f03e07d68e23432826db188cacc758ea5c2a2715 ruonan 53b0abfba0c21358ae40c84d9f5e40ddce30904e ruonan 1d2ed35e70c64aaff31d52c54d9e2ca339c9df39 ruonan
- Commits:
-
Summary ID Author 1d2ed35e70c64aaff31d52c54d9e2ca339c9df39 ruonan e96a19a2539f319a51ae6889ab37b4bfc9cc0b2a ruonan
Checks run (2 succeeded)
- Commits:
-
Summary ID Author e96a19a2539f319a51ae6889ab37b4bfc9cc0b2a ruonan e96a19a2539f319a51ae6889ab37b4bfc9cc0b2a ruonan ec114a76f36b1f33f99f0f44fe187d0c52a4d07d ruonan - Diff:
-
Revision 11 (+2738 -16)
- Added Files:
- Commits:
-
Summary ID Author e96a19a2539f319a51ae6889ab37b4bfc9cc0b2a ruonan ec114a76f36b1f33f99f0f44fe187d0c52a4d07d ruonan 80abb55b3af5447b29dd89467b5c05b3fd3b0963 ruonan
Checks run (2 succeeded)
-
This is great! Pretty much all my comments are stylistic in nature. Once fixed up, this will be ready to land!
-
-
-
-
-
-
This should be
replace_shortcode
.It should also go on the class, since it's specific to this implementation.
-
-
-
-
-
We should define the regex as a constant and compile it, so this is faster every time it needs to post.
-
-
-
-
-
-
-
-
-
-
-
-
When formatting multi-line strings/arguments, we generally format it like:
url = ( '...' '...' % (...) )
-
-
Old code probably had an old pattern for this, but you can get rid of
exc_info=
and instead uselogger.exception(...)
. -
-
Completely optional request, but it'd be more maintainable if these could be broken up around HTML tags a bit better, so it's easier to really digest the code and tweak it later if needed, like:
... '<p>#1: Test Review request</p>' '<strong><font color=#efcc96>Description</font>' ...
-
-
-
Formatting here isn't consistent with other tests (or style guidelines). The keys should be on their own lines.
This applies to all occurrences below.
-
You'll need to pass
id=10000
as a parameter tocreate_review_request()
to avoid an issue that can impact other tests. -
-
-
-
- Commits:
-
Summary ID Author 80abb55b3af5447b29dd89467b5c05b3fd3b0963 ruonan 1856a55e951f1b646079b6489dad7d121359f98a ruonan
Checks run (2 succeeded)
-
Looking good! I found a few small tweaks we can make to wording.
The biggest thing in here though is a security vulnerability in building the HTML to send. It's an easy fix.
format_html()
is just being called wrong. -
-
-
-
-
For
format_html()
, it's very important that we differentiate between what's HTML and what's text going into it. We don't want a title of<script>EVIL THING</script>
going in.So this should be:
string = format_html('<strong>{}</strong><p>{}</p>', fallback_text, title)
Also,
string
is reserved in Python, so let's call ithtml
. -
This will also need to use
{}
and arguments when callingformat_html()
.Also, HTML attribute values should have
"
around them. -
String concatenation in Python isn't very efficient. Rather than doing this, a common pattern is:
html = [] html.append(...) html.append(...) ... payload = { 'formatted_body': ''.join(html), }
Basically, for the most part, joining strings is faster than concatenating strings.
-
-
-
The pattern should be compiled for the instance in
__init__
, rather than each time this function is called (otherwise it doesn't provide any performance gain over just passing a pattern into are
function).Once you compile, you'll call
.sub(...)
on the pattern instead. -