mattermost-plugin-gitlab
mattermost-plugin-gitlab copied to clipboard
[GH-61]: Show code block previews of Gitlab permalinks
Summary
For every message, we now hook into the MessageWillBePosted event and check if it contains a permalink to a Gitlab file.
If yes, we parse out the link and make an API call to the Gitlab files 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
Fixes https://github.com/mattermost/mattermost-plugin-gitlab/issues/61
Hello @shivamjosh,
Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.
Per the Mattermost Contribution Guide, we need to add you to the list of approved contributors for the Mattermost project.
Please help complete the Mattermost contribution license agreement?
Once you have signed the CLA, please comment with /check-cla and confirm that the CLA check is green.
This is a standard procedure for many open source projects.
Please let us know if you have any questions.
We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team.
Codecov Report
Patch coverage: 64.12% and project coverage change: +1.84 :tada:
Comparison is base (
4a527b4) 31.20% compared to head (9fc71e6) 33.05%.
Additional details and impacted files
@@ Coverage Diff @@
## master #299 +/- ##
==========================================
+ Coverage 31.20% 33.05% +1.84%
==========================================
Files 21 22 +1
Lines 3778 4000 +222
==========================================
+ Hits 1179 1322 +143
- Misses 2479 2547 +68
- Partials 120 131 +11
| Impacted Files | Coverage Δ | |
|---|---|---|
| server/configuration.go | 33.33% <ø> (ø) |
|
| server/main.go | 0.00% <0.00%> (ø) |
|
| server/plugin.go | 14.52% <5.40%> (-0.55%) |
:arrow_down: |
| server/permalinks.go | 67.92% <67.92%> (ø) |
|
| server/utils.go | 78.02% <87.34%> (+7.14%) |
:arrow_up: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
This PR has been automatically labelled "stale" because it hasn't had recent activity. A core team member will check in on the status of the PR to help with questions. Thank you for your contribution!
@mickmister @levb Fixed the review fixes you mentioned.
@mickmister In GitLab, we have two types of permalinks -
-
When we go to a file and copy the permalink directly
- This permalink contains the branch name in the URL.
Example:
https://gitlab.com/raghavaggarwal2308/Calculator/-/blob/test/index.html#L7
- This permalink contains the branch name in the URL.
Example:
-
When we go to the file and click on the
Permalinkbutton on the top right and then copy the permalink
- This permalink contains the commit ID in the URL
Example:
https://gitlab.com/raghavaggarwal2308/Calculator/-/blob/0d2465ed07d4b314ec0f9a838bb2f064e34dc0d7/index.html#L7
- This permalink contains the commit ID in the URL
Example:
But in Github, we have only one type of permalink i.e: permalink with the commit ID
Example:https://github.com/raghavaggarwal2308/Hamagi/blob/7322e6554c839af1da0bfb30d71b070f473111bf/shopping/src/App.js#L13
Our current code is working for the permalink containing the commit ID and not for the permalink with the branch name.
We are working on fixing the above issue and will submit it by tomorrow.
@mickmister Fixed the issue and added the comments to link the code with Github plugin.
@levb @mickmister Gentle reminder for re-review
@levb @mickmister Gentle reminder for re-review
@levb @mickmister Gentle reminder for re-review
@levb @mickmister Gentle reminder for re-review
@mickmister @levb Gentle reminder for re-review
This PR has been automatically labelled "stale" because it hasn't had recent activity. A core team member will check in on the status of the PR to help with questions. Thank you for your contribution!
Our current code is working for the permalink containing the commit ID and not for the permalink with the branch name.
What's the complexity of supporting both?
@raghavaggarwal2308 Sorry I meant to mention you in the above comment
@mickmister We are supporting both now
@mickmister Gentle reminder for re-review
@mickmister gentle reminder for re-review
@raghavaggarwal2308 There are no changes from when I approved the PR
@mickmister Apologies for this 🙏🏽 . Can you please remove the Dev-review label if all the dev reviews are complete?
Our current code is working for the permalink containing the commit ID and not for the permalink with the branch name.
What's the complexity of supporting both?
@mickmister We are supporting both now
@raghavaggarwal2308 Does this mean this was committed before my comment? Just want to make sure I understand what's going on
Our current code is working for the permalink containing the commit ID and not for the permalink with the branch name.
What's the complexity of supporting both?
@mickmister We are supporting both now
@raghavaggarwal2308 Does this mean this was committed before my comment? Just want to make sure I understand what's going on
@mickmister Yes, it was committed before that. Mentioned it in this comment.
This PR has been automatically labelled "stale" because it hasn't had recent activity. A core team member will check in on the status of the PR to help with questions. Thank you for your contribution!
@DHaussermann Gentle reminder for review
@DHaussermann Gentle reminder to review the PR
This PR has been automatically labelled "stale" because it hasn't had recent activity. A core team member will check in on the status of the PR to help with questions. Thank you for your contribution!
Hi @shivamjosh
I'm not seeing this work as expected. I see only the normal link preview regardless of if the new code block feature is enabled.
Maybe the GitLab functionality is different from what I'm trying? With this link https://gitlab.com/dhaussermann/dkh-public/-/blame/323cdf25b439e9d01bcb139859b39fc4580e65a1/scipt.js#L11-L12 should I be seeing a code block? Your example in the summaty only points to 1 line but, I have tried this as well.


Please let me know if you can provide some detail on this.
@DHaussermann You are using the "blame" link. Please use a normal permalink (Ex: https://gitlab.com/raghavaggarwal2308/Calculator/-/blob/main/app.js#L12) I think "blame" links are not supported on Github plugin as well
On github plugin:

@raghavaggarwal2308 Thanks for the guidance on this. I was struggling a bit with the GitLab UI to get a link to more than 1 line of code. I did not realize I was getting the blame link instead of the blob link. 🤦♂️
That said - I have now done some testing and the feature is woking. I do have 1 follow-up point to ask about. Regarding private repos it seems we don't fetch the code block previews. Even if private repos is enabled in plugin config AND the user making the post is connected in GitLab as a permission user - The code block does not get retrieved.
Can you confirm if this is the expected behavior?
@DHaussermann This feature should work for private repos as well. It's working fine on my machine. Can you share some details? Like the link you are using or the server logs when you posted the link in the channel.