mattermost-plugin-gitlab icon indicating copy to clipboard operation
mattermost-plugin-gitlab copied to clipboard

[GH-61]: Show code block previews of Gitlab permalinks

Open shivamjosh opened this issue 3 years ago • 11 comments

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: image

After enabling it: image

The newly formed hyperlink is a link to the original permalink

Config setting: image

Ticket Link

Fixes https://github.com/mattermost/mattermost-plugin-gitlab/issues/61

shivamjosh avatar Jun 02 '22 09:06 shivamjosh

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.

mattermod avatar Jun 02 '22 09:06 mattermod

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.

codecov[bot] avatar Jun 06 '22 13:06 codecov[bot]

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!

mattermod avatar Jun 23 '22 01:06 mattermod

@mickmister @levb Fixed the review fixes you mentioned.

raghavaggarwal2308 avatar Aug 03 '22 07:08 raghavaggarwal2308

@mickmister In GitLab, we have two types of permalinks -

  1. 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
  2. When we go to the file and click on the Permalink button on the top right and then copy the permalink Screenshot from 2022-08-19 23-47-29

    • This permalink contains the commit ID in the URL Example:https://gitlab.com/raghavaggarwal2308/Calculator/-/blob/0d2465ed07d4b314ec0f9a838bb2f064e34dc0d7/index.html#L7

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.

raghavaggarwal2308 avatar Aug 19 '22 18:08 raghavaggarwal2308

We are working on fixing the above issue and will submit it by tomorrow.

raghavaggarwal2308 avatar Aug 23 '22 17:08 raghavaggarwal2308

@mickmister Fixed the issue and added the comments to link the code with Github plugin.

raghavaggarwal2308 avatar Aug 24 '22 08:08 raghavaggarwal2308

@levb @mickmister Gentle reminder for re-review

raghavaggarwal2308 avatar Sep 01 '22 13:09 raghavaggarwal2308

@levb @mickmister Gentle reminder for re-review

raghavaggarwal2308 avatar Sep 12 '22 17:09 raghavaggarwal2308

@levb @mickmister Gentle reminder for re-review

raghavaggarwal2308 avatar Sep 16 '22 20:09 raghavaggarwal2308

@levb @mickmister Gentle reminder for re-review

raghavaggarwal2308 avatar Sep 19 '22 12:09 raghavaggarwal2308

@mickmister @levb Gentle reminder for re-review

raghavaggarwal2308 avatar Sep 28 '22 13:09 raghavaggarwal2308

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!

mattermod avatar Oct 10 '22 01:10 mattermod

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 avatar Oct 13 '22 21:10 mickmister

@raghavaggarwal2308 Sorry I meant to mention you in the above comment

mickmister avatar Oct 13 '22 21:10 mickmister

@mickmister We are supporting both now

raghavaggarwal2308 avatar Oct 14 '22 11:10 raghavaggarwal2308

@mickmister Gentle reminder for re-review

raghavaggarwal2308 avatar Nov 17 '22 08:11 raghavaggarwal2308

@mickmister gentle reminder for re-review

raghavaggarwal2308 avatar Nov 25 '22 09:11 raghavaggarwal2308

@raghavaggarwal2308 There are no changes from when I approved the PR

mickmister avatar Dec 01 '22 03:12 mickmister

@mickmister Apologies for this 🙏🏽 . Can you please remove the Dev-review label if all the dev reviews are complete?

raghavaggarwal2308 avatar Dec 01 '22 08:12 raghavaggarwal2308

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 avatar Dec 01 '22 15:12 mickmister

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.

raghavaggarwal2308 avatar Dec 01 '22 17:12 raghavaggarwal2308

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!

mattermod avatar Dec 12 '22 01:12 mattermod

@DHaussermann Gentle reminder for review

raghavaggarwal2308 avatar Jan 12 '23 06:01 raghavaggarwal2308

@DHaussermann Gentle reminder to review the PR

hanzei avatar Feb 21 '23 07:02 hanzei

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!

mattermost-build avatar Mar 04 '23 01:03 mattermost-build

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.

image

image

Please let me know if you can provide some detail on this.

DHaussermann avatar Mar 06 '23 00:03 DHaussermann

@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: image

raghavaggarwal2308 avatar Mar 06 '23 07:03 raghavaggarwal2308

@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 avatar Mar 06 '23 17:03 DHaussermann

@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.

raghavaggarwal2308 avatar Mar 06 '23 18:03 raghavaggarwal2308