Add ability to Embed GitLab Onebox

AI-generated summary

The discussion revolves around adding GitLab onebox embedding to Discourse, similar to GitHub’s implementation. Yoginth proposes the feature, noting that GitLab needs to support it, while itsbhanusharma clarifies that onebox support depends on GitLab’s capabilities. cpradio explains that GitHub has custom onebox engines, and erlend_sh welcomes a PR for GitLab support. misaka4e21 shares a plugin and a pull request (#385) that implements the feature, with sam suggesting it should be merged into core instead of remaining a plugin. Screenshots show the current implementation, with feedback on icon and spacing issues. riking raises concerns about support for non-gitlab.com instances, and misaka4e21 considers broader URL patterns. codinghorror suggests limiting support to gitlab.com for now.

Add ability to Embed GitLab Onebox by displaying the code inside like GitHub Does in Discourse.

https://gitlab.com/DevsPen/Theme/blob/master/about.json

1 Like

Gitlab needs to support it. Onebox probably has nothing to do with it.

Have you checked how they render on iframely?

3 Likes

I’m not so sure. Gitlab is similar to Github, which has its own onebox engine/rule

onebox/lib/onebox/engine at main · discourse/onebox · GitHub

5 Likes

So github is treated differently?

Yes. It has a few custom engines to one box it’s urls

3 Likes

Oh okay! I was unaware of it.

We’d be happy to support a PR that adds custom onebox behaviors for GitLab.

7 Likes

https://github.com/discourse/onebox/pull/385

A plugin as well:
https://github.com/misaka4e21/discourse-onebox-gitlab

5 Likes

This is very cool, but I feel like we should just fold it all into onebox, no need to add one more plugin here.

Can you show some screenshots of how it looks?

Excellent work @misaka4e21!

4 Likes

The plugin will only be necessary when the pull request is not merged. All things in the plugin are included in the PR.


(It seems that the GitHub icon is wrongly displayed.)

2 Likes

cool lets get the icon sorted as well, also the spacing the the gutter looks really big.


The GitHub favicon is now removed for GitLab. The independent icon of GitLab should be added to the discourse onebox.scss and assets instead of the onebox repo, in order to be shown.

As for the spacing issue, it is the same as current GitHub ones.

5 Likes

Hmm, this only supports gitlab.com urls, not other domains?

Here’s an example:

https://git.pleroma.social/pleroma/pleroma/blob/develop/mix.exs#L28-30

2 Likes

Yes it currently supports only gitlab.com.

Should we match any URL with pattern /<user>/<repo>/blob/<branch|commit>/<path> without checking it to be a GitLab instance?

And, there is also other git hosting platform, such as gogs: Making sure you're not a bot!

I searched for identifying elements, and there’s nothing good in the <head>, but body[data-page="projects:blob:show"] might be a good one.

Of cousre, Discourse has <meta name="generator" content="Discourse..."> :wink:

2 Likes

I think gitlab.com only for now is fine, we can further refine it later.

5 Likes