# I link di Meta a GitHub spesso non funzionano

**URL:** https://meta.discourse.org/t/meta-links-to-github-often-broken/85151
**Category:** Site feedback
**Created:** [12 Aprile 2018, 11:59am UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151 "2018-04-12T11:59:35Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![ryanerwin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryanerwin/32/94589_2.png) [@ryanerwin](https://meta.discourse.org/u/ryanerwin)
#### Post date: [12 Aprile 2018, 11:59am UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/1 "2018-04-12T11:59:35Z")

</div>

You can find a lot of references to code in github as you browse through [meta.discourse.org](http://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)](https://meta.discourse.org/t/how-discourse-stays-online-message-bus-faye-long-polling/3238/7)”

You just hit `y` to [get a Permalink](https://help.github.com/articles/getting-permanent-links-to-files/#press-y-to-permalink-to-a-file-in-a-specific-commit) 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/](https://meta.discourse.org/search?q=https%3A%2F%2Fgithub.com%2Fdiscourse%2Fdiscourse%2Fblob%2Fmaster%2F)” and see how many of these are no longer valid.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [12 Aprile 2018, 12:21pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/2 "2018-04-12T12:21:06Z")

</div>

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

> **[Introducing embedded code snippets](https://github.blog/news-insights/product-news/introducing-embedded-code-snippets/)**
>
> Your team can get more done when they have all of the information they need in one place. Now, you can see helpful references in issues you’re already working in…

The post you mentioned is far older than that announcement 😉

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [12 Aprile 2018, 10:36pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/3 "2018-04-12T22:36:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![notriddle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/notriddle/32/133055_2.png) [@notriddle](https://meta.discourse.org/u/notriddle)
#### Post date: [12 Aprile 2018, 10:49pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/4 "2018-04-12T22:49:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![maja](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/maja/32/129533_2.png) [@maja](https://meta.discourse.org/u/maja)
#### Post date: [28 Agosto 2018, 9:38am UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/7 "2018-08-28T09:38:43Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [4 Settembre 2018, 4:51pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/8 "2018-09-04T16:51:38Z")

</div>

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.)

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [4 Settembre 2018, 11:46pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/9 "2018-09-04T23:46:48Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [8 Ottobre 2018, 5:27pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/10 "2018-10-08T17:27:36Z")

</div>

This is now available in the new [`discourse-github`](https://github.com/discourse/discourse-github#github-permalink) plugin.

> ### Github Permalink
> 
> Replace Github non-permalinks with [permalinks](https://help.github.com/articles/getting-permanent-links-to-files/).
> 
> #### How to use:
> 
> 1. Enable `github permalinks enabled` in Settings -\> Plugins.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [10 Ottobre 2018, 4:00pm UTC](https://meta.discourse.org/t/meta-links-to-github-often-broken/85151/11 "2018-10-10T16:00:04Z")

</div>

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