Meta links to Github often broken

You can find a lot of references to code in github as you browse through meta.discourse.org, but many of the links no longer work…

I think one solution would be to require that a github permalink is posted (or at least warn the poster when their github link is not a permalink).

I’ve come across dozens of them today. For example, see “How Discourse Stays Online - (Message Bus, Faye, Long Polling)

You just hit y to get a Permalink on Github.

So many broken links makes meta more difficult to use. Considering these links are typically posted by the Discourse founders, all the more likely to be followed into the future…

There are probably some exceptions that you’re 99% sure will stay around, such as README.md, but search for “https://github.com/discourse/discourse/blob/master/” and see how many of these are no longer valid.

1 Like

I don’t know when the permalink feature was added but I only knew about it with this announcement

The post you mentioned is far older than that announcement :wink:

2 Likes

Yes, links break over time. This is not specific to meta, or Discourse, or even Github. Does Github provide a stable means of determining whether a URL is a permalink based on its structure? If not, it’s going to be awfully tricky to implement a warning.

3 Likes

If you have a URL with this format:

https://github.com/:owner/:repo/blob/:commit/:file

You can figure out if it’s a permalink by hitting this URL:

https://api.github.com/repos/:owner/:repo/commits/:commit

If the returned SHA is equal to :commit itself, then it’s a permalink. Otherwise, it’s not. Personally, I’d just rewrite non-permalinks into permalinks automatically, though.

2 Likes

There doesn’t seem to be a straightforward way to get a permanent link from the entered GitHub link if we wanted to rewrite links into permalink automatically. I guess checking if the link is permalink like @notriddle suggested and adding a warning would be a way to go here?

4 Likes

Actually, it’s fairly easy to come up with the permanent link if you’re parsing out the URL as they suggested.

Just replace the :commit segment with the actual commit hash you get back from the API. (And re-attach the query and anchor strings.)

1 Like

Can you give us a fully-worked example of how to go from a /tree/ link to a /blob/ link programmatically? I can’t figure it out from the examples provided.

3 Likes

This is now available in the new discourse-github plugin.

Github Permalink

Replace Github non-permalinks with permalinks.

How to use:

  1. Enable github permalinks enabled in Settings -> Plugins.
10 Likes

This topic was automatically closed after 46 hours. New replies are no longer allowed.