-
Notifications
You must be signed in to change notification settings - Fork 87
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
[GH-61]: Show code block previews of Gitlab permalinks #299
Conversation
MI-1840: Show code block previews of Gitlab permalinks
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? 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 ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
…-plugin-gitlab into permalink_preview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM, with nits.
The big question I have if we should be using MessageHasBeenPosted
here instead, to rewrite the post asynchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @shivamjosh 👍
I have a few requests including one regarding performance, and a few questions.
I also have a request that when there has been prior review on the work, to please link to the existing PR in the new PR's description: Brightscout#4. GitHub isn't allowing me to reply on conversations there so I'm copying this discussion here Brightscout#4 (comment)
Have you checked if there's a difference between Github and Gitlab permalinks or just copied this regex from Github plugin?
I have copied it from Github plugin and then made changes according to the GitLab plugin.
How confident are we that the URL formats between GitHub and GitLab are generally identical?
server/utils.go
Outdated
// isInsideLink reports whether the given index in a string is preceded | ||
// by zero or more space, then (, then ]. | ||
// | ||
// It is a poor man's version of checking markdown hyperlinks without | ||
// using a full-blown markdown parser. The idea is to quickly confirm | ||
// whether a permalink is inside a markdown link or not. Something like | ||
// "text ]( permalink" is rare enough. Even then, it is okay if | ||
// there are false positives, but there cannot be any false negatives. | ||
// | ||
// Note: it is fine to go one byte at a time instead of one rune because | ||
// we are anyways looking for ASCII chars. | ||
func isInsideLink(msg string, index int) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this implementation or explanation from another source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this implementation is taken from the Github plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we link to the code here using a GitHub permalink?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
server/permalinks.go
Outdated
|
||
// makeReplacements performs the given replacements on the msg and returns | ||
// the new msg. The replacements slice needs to be sorted by the index in ascending order. | ||
func (p *Plugin) makeReplacements(msg string, replacements []replacement, glClient *gitlab.Client) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this code adapted from the GitHub plugin's implementation of this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put a comment linking to the original function using a GitHub permalink?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
…lab into permalink_preview
…ab into permalink_preview
* [MI-1956] Review fixes 1.Removed nested struct 2.Made a global variable for "gitlabPermalinkRegex" 3.Made replacement before interacting with gitlab API 4. Used LogDebug instead of LogError * Run checkstyle 1. Added new line at the end of the file 2. Run check-style * Review Fixes 1.Made requests concurrently * Review Fixes 1. Added New line at the end of file * Review fixes 1.Made requests concurrently * Review fixes 1.Made requests concurrently * Review fixes 1.Made first letter copital of comments 2.Made requests concurrently with proper order * Review Fixes 1.used gofmt and golint * Merge branch 'permalink_preview' of /~https://github.com/Brightscout/mattermost-plugin-gitlab into permalink_preview_fixes * Review fixes 1.Used better name of myMap * Review Fixes 1.Used proper name of myMap * Review fixes 1.Used make check-style * MI-1840: Show code block previews of Github permalinks * MI-1840: Minor fix * MI-1840: Done review fixes * MI-1840: Added unit test for permalink * Fixed lint errors * [MI-1956] Review fixes 1.Removed nested struct 2.Made a global variable for "gitlabPermalinkRegex" 3.Made replacement before interacting with gitlab API 4. Used LogDebug instead of LogError * Run checkstyle 1. Added new line at the end of the file 2. Run check-style * Review Fixes 1.Made requests concurrently * Review Fixes 1. Added New line at the end of file * Review fixes 1.Made requests concurrently * Review fixes 1.Made requests concurrently * Review fixes 1.Made first letter copital of comments 2.Made requests concurrently with proper order * Review Fixes 1.used gofmt and golint * Merge branch 'permalink_preview' of /~https://github.com/Brightscout/mattermost-plugin-gitlab into permalink_preview_fixes * Review fixes 1.Used better name of myMap * Review Fixes 1.Used proper name of myMap * Review fixes 1.Used make check-style * Review Fixes 1.Removed one of the empty line * Review Fixes 1.Revert all changes unrelated to the permalink preview feature. 2.Added checkAndRefreshToken method * Review fixes 1.Changed the name of a function * Unit tests started working * Removed Package-lock.json * [MI-1956] Added Package-lock.json Co-authored-by: raghavaggarwal2308 <raghav.aggarwal@brightscout.com> Co-authored-by: Nityanand Rai <nityanand.rai@brightscout.com>
@mickmister @levb Fixed the review fixes you mentioned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (upon resolving @mickmister's comments)
…-plugin-gitlab into permalink_preview
Sorry @raghavaggarwal2308 I missed that this was ready due to the label. I'll look shortly. |
/update-branch |
We don't have permissions to update this PR, please contact the submitter to apply the update. |
…ab into permalink_preview
@raghavaggarwal2308 I have retested this and this is working as expected. Thank you 👍 I have only 1 small ask. Now that there is a separate piece of functionality involving private repos, the exiting filed no longer affects anything related to private repos. For this PR - Can you please add some text to the description of the existing filed that will clarify the scope. This will add context that the code previews are not covered by the existing switch. |
@DHaussermann Updated the description of EnablePrivateRepos |
…ab into permalink_preview
…ab into permalink_preview
@DHaussermann Heads up that the PR is ready for your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and passed
The last point has now been addressed. The label on the exiting radio button has been updated to clarify the scope.
LGTM!
@raghavaggarwal2308 thanks for the effort on this. Sorry it took me so long to circle back.
@hanzei I had applied the I am reluctant to merge new features into |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
@hanzei I'm okay with including this into |
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 #61