The community is discussing the issue of broken links to Github on meta.discourse.org. ryanerwin suggests requiring Github permalinks or warning users when non-permalinks are posted, as many links are no longer valid. notriddle provides a method to determine if a URL is a permalink by using the Github API, and riking suggests rewriting non-permalinks to permalinks automatically. mpalmer expresses concerns about the complexity of implementing this feature, but zogstrip announces that a plugin, discourse-github, is now available to replace non-permalinks with permalinks. This plugin can be enabled in the plugin settings to address the issue of broken links.
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.
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.
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.
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?
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.