Repository: readthedocs/readthedocs.org

Issue:
"edit on github" / "view on github" links for "stable" -> 404
See there:

http://borgbackup.readthedocs.org/en/stable/

Link at top right points to:
https://github.com/borgbackup/borg/blob/55fef2457e483701254e5b2a7d4a1a60963971a8/docs/index.rst
(which is 404)

Same for the view/edit links in the bottom left box, they also point to same 404 location.

OTOH, the docs shown for "stable" are (currently) correctly showing 0.28.2 release, which is the latest release.

I tried a "stable" rebuild, did not help.



Discussion:
it would seem more reliable to show a link to a branch there, it seems to me...

55fef2457e483701254e5b2a7d4a1a60963971a8 is the hash of the 0.28.2 _tag_ on github:

```
$ git show 55fef2457e483701254e5b2a7d4a1a60963971a8 | head
tag 0.28.2
Tagger: Thomas Waldmann <tw@waldmann-edv.de>
Date:   Sun Nov 15 22:01:29 2015 +0100

tagged/signed release 0.28.2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAABCgAGBQJWSPKpAAoJECQ6z6lR944BBt4P/2sRtiN7prKpK7dO8QAPuEiM
Tb4gzaLJRf1ZjSGwFGQ+Ma3YXf3OBMG+ZAZIUtn7q4b3BoetuekCIWcGc9FPxOT5
```

it seems that GH doesn't render that properly transparently, so it could be a github bug as well...

Ah, interesting. I only looked in git log output for the hash, but the tags do not show up there.

could somebody please have a look?

This is ticket has not been triaged yet, as we have not had time to focus on this. Feel free to supply test cases or a patch that address the issue you are seeing.

could this be fixed please?

we get new tickets on our tracker all the time because "edit on github" is broken...

could it be related to that I gpg-sign my release tags in git?

I'm seeing the same problem with the files written in markdown in project using a mix of markdown and rST (the "edit on GitHub" links go to e.g. foo.rst when the page was generated from e.g. foo.md):
See e.g. http://zulip.readthedocs.org/en/latest/integration-guide.html

@timabbott are you signing your release tags with gpg, too?

well, i don't know about others but this _is_ fixed here. the original post here says that the [stable release page](http://borgbackup.readthedocs.org/en/stable/) leads to a [404 page](https://github.com/borgbackup/borg/blob/55fef2457e483701254e5b2a7d4a1a60963971a8/docs/index.rst) (which is still 404). but the stable page now points to  a [different page](https://github.com/borgbackup/borg/blob/6a3f2d78644567f6b105414916b449eaa4409540/docs/index.rst) which works fine. also, [tagged releases](http://borgbackup.readthedocs.org/en/1.0.1/) work fine too: they leads to a [working link](https://github.com/borgbackup/borg/blob/1.0.1/docs/index.rst).

i wonder if [github's support for signed commits](https://github.com/blog/2144-gpg-signature-verification) fixed this or something.

anyways, it looks to me like the original issue is fixed. @timabbott's issue seems related not to git tags but to the markdown/rst mix, an issue that should be fixed on RTFD's side, not github.

@anarcat right, it works now for our stable tag. \o/

thus, I am closing this one - please file different bugs in a different issue.

Sounds reasonable, opened https://github.com/rtfd/readthedocs.org/issues/2130 for the markdown issue -- I hadn't realized it was a different bug.  Thanks!

Hmm, the issue seems to have come back:

http://borgbackup.readthedocs.io/en/stable/index.html "edit on github" points to:

https://github.com/borgbackup/borg/blob/89707fc6084c196fa3f973a91937218288f59e03/docs/index.rst

... which is 404.

I've also seen this. http://kinto.readthedocs.io/en/stable/ "edit on github" points to https://github.com/Kinto/kinto/blob/9c331e13643a53ca76208f4efa6c9bb651b165b4/docs/index.rst , which 404s. Like @anarcat said, the hash shown is the hash of the tag, rather than that of the commit. Looking at http://readthedocs.org/api/v1/version/1957996/?format=json, I see the problematic hash listed as the "identifier".

BTW, how about a setting whether one wants to have "edit on github" links or not?

I'ld just switch it off so we would never have to bother with it again. We have a link to github in our docs, so we don't really need that extra link. ;-)

@ThomasWaldmann your last command should be in another issue I believe ;)

Regarding the issue at hand, i've investigated a bit, and here are my findings:
When checking for the "identifier" to use, there's a special case when the slug is `STABLE`:
https://github.com/rtfd/readthedocs.org/blob/b5d06e856ec0eea6f340bc078ab747254b516cd0/readthedocs/builds/models.py#L117

This will return the `identifier` which is the commit hash. This is what's causing problem, because it's the hash of the tag, not of a commit, and thus GitHub doesn't know how to display it. As you can see from the comment there, the issue is that we don't have the original branch name.

So maybe we could store the branch name instead of the tag hash (which seems useless in our case?) in the `identifier` field.

This should be done in the [`update_stable_version`](https://github.com/rtfd/readthedocs.org/blob/b5d06e856ec0eea6f340bc078ab747254b516cd0/readthedocs/projects/models.py#L698) I guess (specifically line [716](https://github.com/rtfd/readthedocs.org/blob/b5d06e856ec0eea6f340bc078ab747254b516cd0/readthedocs/projects/models.py#L716) and [726](https://github.com/rtfd/readthedocs.org/blob/b5d06e856ec0eea6f340bc078ab747254b516cd0/readthedocs/projects/models.py#L726)).

I'll submit a PR with this naive fix, to open up the discussion.

This has been fixed (see http://mockingjay.readthedocs.io/en/stable/ -- it properly links to the hash of the commit on github)
@ericholscher click on first link in top post, then on "edit on github".
this is not fixed. i still see this problem all the time. it could be a bug with github that doesn't properly recognize certain hashes, but it's still a problem regardless. 
Where did the commit `55fef2457e483701254e5b2a7d4a1a60963971a8` come from for borg backup? GitHub doesn't seem to recognize it, but I imagine it came from the project at some point. Did you delete and retag a release or something?

Either that, or we have a bug that is pulling tags in from random places. 
it's not a commit, it's a tag, and it's the whole bug here - github doesn't display tag hashes correctly when you ask them as commits:

```
$ git show 55fef2457e483701254e5b2a7d4a1a60963971a8
tag 0.28.2
Tagger: Thomas Waldmann <tw@waldmann-edv.de>
Date:   Sun Nov 15 22:01:29 2015 +0100

tagged/signed release 0.28.2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAABCgAGBQJWSPKpAAoJECQ6z6lR944BBt4P/2sRtiN7prKpK7dO8QAPuEiM
Tb4gzaLJRf1ZjSGwFGQ+Ma3YXf3OBMG+ZAZIUtn7q4b3BoetuekCIWcGc9FPxOT5
gL4ebFkAPXZ24KrU+c+QCHgPf80E2DfqNZYQsv2yaEPfr0W0c40vOP9bdhmOgZF4
z1GLUrE/36PbVkcneIar7fu/YRV5Rc0Ohl+5g4se+EOyhXQBCcAQkGFZefTpe4eq
s9uVkBTx6eD15BSlEebv34Fxc0SPAj2+UIcrIPtDPrUVLv62wfNu5btwS+41FxXs
2m7QJKXWQAmsM24NGLePGsFP5RJLg+E3IF1ytAdYh3ecHk5xsvoiD3c/z0MAO7Cm
3ukiWQVVX6xpLjpM0iEzBrtaxTv0zPqh1r9n9ecIv2PNVxwmcJ27C8IgMqZ0SpLS
w6whl2mimv7C4Ww7vG1qTzjRjBzLqAOOdZ9SIwVrzAjCYcCSS8wDSpJeIArjDroc
mwbeZoIrWWz40XBFNOsoJQ2a2s98SvJoyO/y8wSnPrgSAlc+bKqGlKnmRLDEASml
dDhGJMywJhS0U5H9fDkJcPCR0zlRk24RqUVISN63e0C6zjsWfwoOpZYFmLF4tIT2
OBbd64Ca7+OkIktQgXC5ujBioX3QBUF7Oris6yVJINYP/eC9fGNX0oYNasoLMiu0
h2eYx+ToARnXU8QFcWLU
=cjuM
-----END PGP SIGNATURE-----

commit 3a72fbe418e075ec7af8695a50dee50603d09b0d
Author: Thomas Waldmann <tw@waldmann-edv.de>
Date:   Sun Nov 15 20:30:58 2015 +0100

    update CHANGES

diff --git a/docs/changes.rst b/docs/changes.rst
index 9d215e63..f60edd59 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -16,8 +16,13 @@ Other changes:
 - do not create docs sources at build time (just have them in the repo),
   completely remove have_cython() hack, do not use the "mock" library at build
   time, #384
-- docs: explain how to regenerate usage and API files (build_api or
-  build_usage) and when to commit usage files directly into git, #384
+- avoid hidden import, make it easier for PyInstaller, easier fix for #218
+- docs:
+
+  - add description of item flags / status output, fixes #402
+  - explain how to regenerate usage and API files (build_api or
+    build_usage) and when to commit usage files directly into git, #384
+  - minor install docs improvements
 
 
 Version 0.28.1
```

so either you:

1. patch github to make it DTRT here (hahaha, just kidding, you're SOL there)
2. ask them nicely to fix this (couldn't resist)
3. handle those cases by hand and inspect the ref given to extract a valid commit... (looks like this is the only option)
OMG. `commit hash` and `tag hash` are two different things? `tag` has them both? But why?
A related problem is if the documentation is generated via `apidoc`, such that no ReST file exists on Github. This will always lead to a 404 error, see #2719. Please add an option to disable these links.
@goerz, in that case, perhaps rtfd/sphinx_rtd_theme/issues/324? :p
So can anybody explain what exactly happens?

1. rtfd clones project sources
2. rtfd tries to find branch? tag? for `/stable/` URL  <-- how does it do this, is there a log for this operation
3. rtfd tries to find commit id for branch/tag name found in step 2
4. rtfd updates to specified commit id
5. rtfd builds the doc
6. rtfd inserts commit id into GitHub edit link URL

The problem is that GitHub skips some commits? Or don't show them by commit id?

It would be nice if build logs were a part of docs footer or something with stats etc.
> OMG. commit hash and tag hash are two different things? tag has them both? But why?

a tag is built on top of a commit, and has extra information, just like branches are not commits, tags are not just commits either. see [this document](https://git-scm.com/book/en/v2/Git-Internals-Git-References) for a good overview of references and tags in git.

>  1. rtfd clones project sources
>  2. rtfd tries to find branch? tag? for /stable/ URL <-- how does it do this, is there a log for this operation
>  3. rtfd tries to find commit id for branch/tag name found in step 2
>  4. rtfd updates to specified commit id
>  5. rtfd builds the doc
>  6. rtfd inserts commit id into GitHub edit link URL
>
> The problem is that GitHub skips some commits? Or don't show them by commit id?

The problem is that RTFD skips step 3 and 4, AFAIK - it just uses the tag hash instead of the commit hash.

Sounds like ya'll have done some good work debugging this issue. The next step is to submit a patch that hopefully fixes the issue. I saw a previous attempt at this that I closed thinking it was fixed in my testing (#2428) -- that might be a good place to start. 
I don't get a feeling that we've debugged the issue. These are all assumptions. Can we have a command that we can checkout and run to repeat rtfd behaviour?
https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/projects/models.py#L698 is probably a good place to start. 
> https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/projects/models.py#L698 is probably a good place to start.

Lame Django question - where is `self.versions` defined in this file? I don't see any properties in `Project` object with such name.
We're [having the exact same problem](/restic/restic/issues/1175) over at the [restic](/restic/restic) documentation, with e.g. http://restic.readthedocs.io/en/stable/installation.html - the below discussion is with this example page in mind.

For the `latest` and `v0.7.1` versions, the "Edit on GitHub" link works just fine. It's just the `stable` version that has the problem this issue is about.

Now, the [RTD documentation](https://docs.readthedocs.io/en/latest/versions.html#versions) states that "We also create a `stable` version, if your project has any tagged releases. `stable` will be automatically kept up to date to point at your highest version".

To me this sounds like RTD is aware of what the highest version is. In restic's case, currently `v0.7.1` for which there is a tag with the same name. Considering that RTD also lists `latest`, `stable` and then every release tag in the sidebar where you select the version to display, it sure seems to understand what versions we have.

To solve this issue, can't you simply put the highest tag's _name_ in the URLs of the links, instead of as now the highest tag's commit hash?

To be clear, in our case the "Edit on GitHub" link in the example page above is currently https://github.com/restic/restic/blob/402b6f5f8d0171d7061cbeab67725fce794fc376/doc/installation.rst - the hash referencing the commit of the `v0.7.1` tag. If instead of this hash you would just use the highest tag name, the URL would instead be https://github.com/restic/restic/blob/v0.7.1/doc/installation.rst, and this works just fine.

This would be in line with what the documentation states about the `stable` version referencing the highest version, so I think it seems rather straight forward to solve it this way.
@ThomasWaldmann (and other people having this issue) can you try re-building your project and see if the problem is solved?

According to https://github.com/rtfd/readthedocs.org/pull/3615#pullrequestreview-106594994 it should.
i rebuilt the "stable" branch of the borg repo (not sure why i still have access to that, @ThomasWaldmann, btw ;), and we still see the issue.
the tag links are a little better, but still ackward. e.,g. it goes to https://github.com/borgbackup/borg/edit/1.1.4/docs/usage/general.rst which says "Sorry, it looks like your fork is outdated!"
Testing a version `stable`, the `Edit` link gives me a 404 still. The `View` link still works for me, but if I try to edit this file on GitHub, the edit button is disabled and tells me that "i must be on a branch" -- so perhaps this is a clue.

Reopening.
can we just remove (or disable by default) the annoying / buggy features like this or that "outdated library version" note?

the problem is not just that readers encounter these bugs and report them HERE, they also frequently report them at the documented software project, causing work for the maintainers of these. and once you have explained it to one user who found it, the next one will find it and open another issue...
@agjohnson I have the exact same symptoms in e.g. https://restic.readthedocs.io/en/stable/040_backup.html. I have asked the project owner of restic to trigger a rebuild of the docs, but haven't heard from him yet on whether or not he did that.

Would be great if stable just pointed to the last release tag instead, that would have solved it by now.
That's because commits nor tags can't be edited. So I think this is kind of another issue (hide the `Edit` button when a version isn't a branch).
@stsewd has a good point, one cannot edit tags either. So at the GitHub end we're left with the branches that exist in the repo. Usually this is master and perhaps some other dev branches.

In order for the edit link to have a purpose, perhaps it simply needs to point to the main branch at all times, regardless of which version you are looking at in RTD?

How to deduct/define the "main" branch is another question though. Maybe the answer to it lies in just looking at what branch the Latest version corresponds to.

EDIT: Then again; What happens on GitHub is a separate concern. Perhaps RTD did what it's supposed to do by linking to the proper file in the proper commit/tag/branch, and that's the end of it, in the sense that it's then up to the user to create a branch from that commit/tag if they want to edit. Just like the "Fork me on GitHub" links on project pages just goes to the original repository, instead of actually starting to fork the original repo into the user's GitHub account.
The restic doc project was rebuilt in RTD, but the same state still applies, for obvious reasons. Not much else we can do about it suppose :) Thanks for your hard work!
I am +1 on reticketing the issue. There were some changes since 2015 and the info needs to be researched again.
Yeah, I don't think this is a bug, is more like an improvement, and it needs a design decision about how to deal with links to no editable versions (tags).
On my deployment, it wouldn't even work on `master` branch?
See http://how.bitshares.works/en/master/
@xeroc I think you are facing another issue https://github.com/rtfd/readthedocs.org/issues/1917
@stsewd are you sure looking at the BitShares docs:

> © Copyright 2018, BitShares Blockchain Foundation. Revision 3c056912.
> Built with Sphinx using a theme provided by Read the Docs. 
@techtonik @xeroc that's another bug, please see https://github.com/rtfd/readthedocs.org/issues/4671
thanks for the link.
So, I just discovered that we have this, `is_editable` thing (sphinx only)

https://github.com/rtfd/readthedocs.org/blob/0f5d979c221da7140138359fc06660ebec6fff9b/readthedocs/doc_builder/backends/sphinx.py#L127-L132

It was added here https://github.com/rtfd/readthedocs.org/commit/4619c8297780c1c0d3e557a9712045e279fd6e95#diff-4ade07b2b17f38e60bfcb27301c99934

The commit msg describes what we are seeing now. But it was never used on the conf.py context.

Anyway, I think we can use that now in the flyout menu with github and friends

https://github.com/rtfd/readthedocs.org/blob/0f5d979c221da7140138359fc06660ebec6fff9b/readthedocs/restapi/templates/restapi/footer.html#L79-L88

Resolving patch:
diff --git a/readthedocs/builds/models.py b/readthedocs/builds/models.py
--- a/readthedocs/builds/models.py
+++ b/readthedocs/builds/models.py
@@ -2,36 +2,55 @@
 """Models for the builds app."""
 
 from __future__ import (
-    absolute_import, division, print_function, unicode_literals)
+    absolute_import,
+    division,
+    print_function,
+    unicode_literals,
+)
 
 import logging
 import os.path
 import re
-from builtins import object
 from shutil import rmtree
 
+from builtins import object
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.db import models
 from django.utils.encoding import python_2_unicode_compatible
-from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import ugettext
+from django.utils.translation import ugettext_lazy as _
 from guardian.shortcuts import assign
 from taggit.managers import TaggableManager
 
 from readthedocs.core.utils import broadcast
 from readthedocs.projects.constants import (
-    BITBUCKET_URL, GITHUB_URL, GITLAB_URL, PRIVACY_CHOICES, PRIVATE)
+    BITBUCKET_URL,
+    GITHUB_URL,
+    GITLAB_URL,
+    PRIVACY_CHOICES,
+    PRIVATE,
+)
 from readthedocs.projects.models import APIProject, Project
 
 from .constants import (
-    BRANCH, BUILD_STATE, BUILD_STATE_FINISHED, BUILD_TYPES, LATEST,
-    NON_REPOSITORY_VERSIONS, STABLE, TAG, VERSION_TYPES)
+    BRANCH,
+    BUILD_STATE,
+    BUILD_STATE_FINISHED,
+    BUILD_TYPES,
+    LATEST,
+    NON_REPOSITORY_VERSIONS,
+    STABLE,
+    TAG,
+    VERSION_TYPES,
+)
 from .managers import VersionManager
 from .querysets import BuildQuerySet, RelatedBuildQuerySet, VersionQuerySet
 from .utils import (
-    get_bitbucket_username_repo, get_github_username_repo,
-    get_gitlab_username_repo)
+    get_bitbucket_username_repo,
+    get_github_username_repo,
+    get_gitlab_username_repo,
+)
 from .version_slug import VersionSlugField
 
 DEFAULT_VERSION_PRIVACY_LEVEL = getattr(
@@ -193,6 +212,10 @@ def identifier_friendly(self):
             return self.identifier[:8]
         return self.identifier
 
+    @property
+    def is_editable(self):
+        return self.type == BRANCH
+
     def get_subdomain_url(self):
         private = self.privacy_level == PRIVATE
         return self.project.get_docs_url(


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_footer.py b/readthedocs/rtd_tests/tests/test_footer.py
--- a/readthedocs/rtd_tests/tests/test_footer.py
+++ b/readthedocs/rtd_tests/tests/test_footer.py
@@ -1,6 +1,10 @@
 # -*- coding: utf-8 -*-
 from __future__ import (
-    absolute_import, division, print_function, unicode_literals)
+    absolute_import,
+    division,
+    print_function,
+    unicode_literals,
+)
 
 import mock
 from django.test import TestCase
@@ -11,13 +15,15 @@
 from readthedocs.core.middleware import FooterNoSessionMiddleware
 from readthedocs.projects.models import Project
 from readthedocs.restapi.views.footer_views import (
-    footer_html, get_version_compare_data)
+    footer_html,
+    get_version_compare_data,
+)
 from readthedocs.rtd_tests.mocks.paths import fake_paths_by_regex
 
 
 class Testmaker(APITestCase):
     fixtures = ['test_data']
-    url = '/api/v2/footer_html/?project=pip&version=latest&page=index'
+    url = '/api/v2/footer_html/?project=pip&version=latest&page=index&docroot=/'
     factory = APIRequestFactory()
 
     @classmethod
@@ -99,6 +105,24 @@ def test_show_version_warning(self):
         response = self.render()
         self.assertTrue(response.data['show_version_warning'])
 
+    def test_show_edit_on_github(self):
+        version = self.pip.versions.get(slug=LATEST)
+        version.type = BRANCH
+        version.save()
+        response = self.render()
+        self.assertIn('On GitHub', response.data['html'])
+        self.assertIn('View', response.data['html'])
+        self.assertIn('Edit', response.data['html'])
+
+    def test_not_show_edit_on_github(self):
+        version = self.pip.versions.get(slug=LATEST)
+        version.type = TAG
+        version.save()
+        response = self.render()
+        self.assertIn('On GitHub', response.data['html'])
+        self.assertIn('View', response.data['html'])
+        self.assertNotIn('Edit', response.data['html'])
+
 
 class TestVersionCompareFooter(TestCase):
     fixtures = ['test_data']