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

Code Previews not working with private repos

Open tuxity opened this issue 3 years ago • 11 comments

Hello,

I can't get code preview in any channels when I link a file from a private repo. I have no error messages when I set MM server to debug mode. It just send default Github public link metadata.

Mattermost Server team edition version 6.2.1 Github plugin 2.0.1 Code Previews enabled for public and private repositories in Github plugin configuration Connected via /github connect private Tested with a Dockerfile from a public and private repos

I tested reconnecting account to GH, disabling/enabling Code Preview

I don't know if I'm missing something, tell me if you need more information.

tuxity avatar Jan 05 '22 10:01 tuxity

Hi @tuxity,

Did you enable code previews for public and private repositories in the plugins settings?

hanzei avatar Jan 07 '22 14:01 hanzei

Yes it is enable.

tuxity avatar Jan 07 '22 14:01 tuxity

To which options is the setting set?

hanzei avatar Jan 07 '22 16:01 hanzei

to "Enable for public and private repositories. This might leak confidential code into public channels."

tuxity avatar Jan 07 '22 16:01 tuxity

I can't reproduce the issue.

  1. Do you see any related error in the server logs?
  2. Is the repository you tested with part of a organisation?

hanzei avatar Jan 07 '22 16:01 hanzei

I tried to put the server in debug mode and there is no error in logs I also tested with a private repo from an organisation and also one of my personal private repo and not working.

I also tried to disable and enable the plugin again, the plugin is not restricted to an organisation

Should I try to reinstall the plugin ? I will have to resetup every subscriptions in channels ?

tuxity avatar Jan 07 '22 17:01 tuxity

Just to double check: You created the permalink by selecting the lines of code in the UI and clicking on Copy permalink? Screenshot from 2022-01-10 09-08-01

hanzei avatar Jan 10 '22 08:01 hanzei

Haven't tried this type of link, I was checking with URL in browser like

https://github.com/mattermost/mattermost-plugin-github/blob/master/Makefile
https://github.com/mattermost/mattermost-plugin-github/blob/master/Makefile#L27
(but with private repo ofc)

When I use permalink it's working correctly indeed. https://github.com/mattermost/mattermost-plugin-github/blob/1068fe3eb5bf57b7c7cba22a43cc9491137a109a/Makefile#L12

So maybe the plugin isn't supposed to parse this type of URL for private repo ? The only difference is the commit id after /blob/ instead of the branch name

All my coworkers in my team use the URL from browser directly to reference a file, commit, PR... and we only get image

tuxity avatar Jan 10 '22 08:01 tuxity

Yes, that is indeed the expected behavior currently. https://github.com/mattermost/mattermost-plugin-github/blob/40e7fcf8bdfa2f49bae44b214ed96588ffe6c4df/server/plugin/permalinks.go#L96-L100

But I'm wondering if the plugin should support links to branches and tags. On caveat is that the content might change in the future and it's hard to keep the message in sync. So it would be a snapshot of the content at the time the message is posted.

@agnivade Do you have thoughts on this ideas, as you originally implemented the feature?

hanzei avatar Jan 20 '22 09:01 hanzei

This feature is primarily supposed to work with permalinks, not with regular links. The original implementation mainly mirrored GitHub's permalink preview implementation. And as you can see from above, GitHub will also only expand permalinks, not all kinds of links.

This usually applies to all kinds of permalink previews - they are tied to a single id/hash. And not something that can change. Otherwise, this becomes a link preview, not permalink preview. We could do that of course, but then we deviate from the usual accepted standard.

As a first step, I'd suggest to document this more prominently, and how to capture and share permalinks, not regular links.

And to clarify, this has no relation to the type of repo - public/private. It only expands permalinks.

agnivade avatar Jan 20 '22 18:01 agnivade

Made this a Help Wanted documentation ticket

hanzei avatar Mar 01 '22 12:03 hanzei