Repository navigation
MM-8880: Show code block previews of Github permalinks - #137
Conversation
|
@agnivade Could you include a screenshot of an example of how it looks to the description so we can get a quick PM review? cc @aaronrothschild |
|
Yep, done ! |
|
LGTM. Do we cut off the code at a certain number of characters? |
|
Good point actually. I think number of lines is better than number of characters. How about a max of 10 lines with an ellipsis at end if there are more lines to indicate that lines have been cut off in the preview ? |
marianunez
left a comment
There was a problem hiding this comment.
@agnivade Could we handle the case for a single code line https://github.com/mattermost/mattermost-server/blob/cbb25838a61872b624ac512556d7bc932486a64c/app/authentication.go#L20 ? The original concept was to show the given line and include 3 lines before/after to show the surrounding code block (much like github does in code review changes screen)
|
gentle ping @marianunez |
|
@agnivade sorry for the delay. Will be getting to this PR today. Feel free to re-requets review when necessary given that the PR falls out of our review list and sometimes gets out of our radar. |
marianunez
left a comment
There was a problem hiding this comment.
Overall LGTM. Some suggested changes below - will review the tests next
alifarooq0
left a comment
There was a problem hiding this comment.
Thanks @agnivade for your contribution! 🎉 Had a few comments. Your test looks great! I was wondering if you can also add tests for makeReplacements as that is where all the magic happen :)
|
@ali-farooq0 - Thanks for the wonderful review. Regarding testing But I have tests for |
|
Oops my bad ! I mistakenly amended to the previous commit. So you won't see the exact changes done for this review. You will also see Maria's review changes. Sorry about that :( |
- Added a mock github client to test makeReplacements. - Some minor nits on changing no. to number and adding periods at end of sentences. - Changing the captureMap from a map to a struct.
There was a problem hiding this comment.
Nice @agnivade! Still feel like getReplacements should be the one that fetches all the details from github and puts it together in nice little struct, but the way it is currently set up is fine as well, especially since we've added tests now 👍
Just one minor fix as per https://github.com/mattermost/mattermost-plugin-github/pull/137/files#r344789251 and this PR should be good to go 👍
|
@ali-farooq0 - It looks like the build was cancelled ? Can you restart it ? |
|
@DHaussermann this is ready for QA. |
|
Hey @agnivade I'm not seeing this work as expected. Once I enable After this subscriptions and @ mentions stop working. Once I disable Subscriptions and @ mentions then start working again. Can you help me isolate this behavior? Can you confirm if these errors are related to the new feature and if I need to collect more info somehow? |
|
Hi @DHaussermann - Yes I have seen the " RPC call to KVGet API failed: connection is shut down," several times. But I worked around it by just restarting the plugin process. Everything starts working again. I thought it was an unrelated issue and didn't have time to look deeper, because everything works fine with a restart. On a deeper look, the error comes from the Please let me know how can I help further. |
|
Thanks @agnivade can you also give me some guidance on the functionality?
Expected: In the channel where the event was delivered, link included in GitHub post shows a preview. |
|
Ah no, you are using it wrong. You don't need any subscriptions or delivery of any event whatsoever. And secondly, that link is not a permalink. It's just a URL to a file. Here is what I would suggest: Once you enable the feature, just copy paste any text containing a github permalink. That's all. Then you should be able to see the preview. As an example type You can get a permalink by clicking on a line number of a file in github. Then click on the 3 dots on the left, click on copy permalink. You can also test a line range, by pressing the shift key and clicking on a close-by line to get a line range. Then do the same to get its permalink. Let me know if that helps. |
|
Thanks @agnivade this does help. I think I mistakenly focused on the subscription events because I noticed they stop working :) . With a proper link I see the functionality working. I also notice the same behavior with the preview. After it is generated once, the plugin stops working. I then have to disable and re-enable the plugin to see a preview again. To try and isolate this I deployed the plugin from the Is there anyway to determine conclusively if the issue is introduced by this PR? |
This causes failures in the RPC calls, and without the userID, we cannot do anything either.
|
@DHaussermann - It was a corner case where an empty userID was being passed. Apparently, restarting the plugin did not send these erroneous messages. Please check again with the latest patch. |
DHaussermann
left a comment
There was a problem hiding this comment.
Thanks for the fix @agnivade !
Tested and passed.
- Tested new feature is working
- Tested ranges for link
- Tested code link in between other text
- Regression tested plugin
No issues found
LGTM!
Summary
For every message we now hook into the MessageWillBePosted event, and check
if it contains a permalink to a Github file.
If yes, we parse out the link, and make an API call to the Github contents API.
Get the file contents and filter out the required lines given in the permalink anchor.
Then we construct a code block in markdown and replace the original string.
Added a config key to gate this feature.
Screenshots:
With config disabled:

After enabling it:

The newly formed hyperlink is a link to the original permalink
Config setting:

Ticket Link
MM-18880
Fixes #128