Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Better link previews for private instances#41843

Merged
novoselrok merged 7 commits into
mainfrom
rn/private-instances-better-link-previews
Sep 23, 2022
Merged

Better link previews for private instances#41843
novoselrok merged 7 commits into
mainfrom
rn/private-instances-better-link-previews

Conversation

@novoselrok

@novoselrok novoselrok commented Sep 21, 2022

Copy link
Copy Markdown
Contributor

Introduces a new OpenGraphMetadataMiddleware that serves a separate template with OpenGraph metadata meant for unauthenticated requests to private instances from social bots (e.g. Slackbot). Instead of redirecting the bots to the sign-in page, they can parse the OpenGraph metadata and produce a nicer link preview for a subset of Sourcegraph app routes.

⚠️ The OpenGraphMetadataMiddleware does not access any private data on the instance, it purely extracts the data already available in the URL and presents it in a nicer manner.

Screenshot:

(Ignore the long ugly ngrok URL, imagine sourcegraph.sourcegraph.com instead 🙂)

Screenshot 2022-09-21 at 15 12 29

Test plan

  • Run Sourcegraph in enterprise mode
  • Run ngrok with ngrok http --host-header=rewrite 3080 to expose your instance to the world
  • Navigate to the ngrok URL (something like https://c70e-2a00-ee2-4e06-b400-820-34aa-bcc3-1523.eu.ngrok.io) and copy a repo/blob/search URL
  • Paste it into Slack
  • You should get a link preview with data from the URL and not the sign-in page

@cla-bot cla-bot Bot added the cla-signed label Sep 21, 2022

@pjlast pjlast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this would look nice (if it works)

Maybe give it a shot 🤷

Comment on lines +64 to +67
title := path
if formattedLineRange != "" {
title += "?" + formattedLineRange
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, instead of adding this line range to the title, add it to the card as a label. See other comments

Comment thread cmd/frontend/internal/cli/middleware/opengraph.go
Comment thread cmd/frontend/internal/cli/middleware/opengraph.html
@novoselrok novoselrok marked this pull request as ready for review September 21, 2022 13:21
@novoselrok novoselrok requested a review from a team September 21, 2022 13:21

@unknwon unknwon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! (assuming it works 😁 )

@pjlast

pjlast commented Sep 22, 2022

Copy link
Copy Markdown
Contributor

@novoselrok does this affect our current link expansion at all? For example if I paste a sourcegraph.com link in Slack it looks like this:
image

@novoselrok

novoselrok commented Sep 22, 2022

Copy link
Copy Markdown
Contributor Author

@novoselrok does this affect our current link expansion at all?

It does not. The current link expansion only works for the .com instance. And this PR is only enabled for non-.com instances, so they should be mutually exclusive.

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Lemme know if you run into any issues -- global feature flags are not super well exercised (but they should hopefully work just fine)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants