vim-rhubarb icon indicating copy to clipboard operation
vim-rhubarb copied to clipboard

Add GitHub Wiki Support

Open sheluchin opened this issue 5 years ago • 8 comments

Some commands, like :GBrowse, do not work correctly when used on a wiki repo. For example, executing :GBrowse on the Home.md page takes you to https://github.com/tpope/vim-fugitive.wiki/blob/master/Home.md which doesn't exist.

sheluchin avatar May 21 '19 18:05 sheluchin

I would welcome an implementation of this. Documenting what the behavior should be would also help. Is it possible to view an old revision of a page? A commit object? Are trees (directories) a thing or is it a flat namespace?

tpope avatar May 21 '19 21:05 tpope

I'm seeing this problem with a regular privat erepository. Running :Gbrowse takes me to https://github.com/org/repo/blob/my-branch while the proper URL is https://github.com/org/repo/tree/my-branch.

hovsater avatar Aug 24 '19 13:08 hovsater

It's not a "problem", it's a feature request that lacks enough information to implement.

Edit: what you're describing has nothing to do with wikis.

tpope avatar Aug 24 '19 13:08 tpope

@tpope you’re right, I’ve submitted a separate issue describing what I’m seeing in #49. Sorry for creating unnecessary noise in this issue.

hovsater avatar Aug 24 '19 13:08 hovsater

I'll answer using the Ethereum Wiki as an example, as it seems to be the most popular wiki on GitHub and has enough content to use for reference.

The URL to a wiki looks like this:

https://github.com/ethereum/wiki/wiki
                   │        │    │
                   │        │    └── standard title set by GitHub
                   │        │
                   │        └── repo title chosen by creator
                   │
                   └── owner name (org. name or username)

I'll refer to this as <base_url> for simplicity.

As editing the wiki through the web interface is very common, spaces are usually included in page titles. GitHub's web interface replaces them with hyphens.

For example, the page titled 5 strategies of contribution is accessible at:

https://github.com/ethereum/wiki/wiki/5-strategies-of-contribution

Is it possible to view an old revision of a page?

Yes, viewing a page revision is possible at:

<base_url>/page-title/<sha>

Example:

https://github.com/ethereum/wiki/wiki/5-strategies-of-contribution/b4ba41ef3a0127b338c082343c30d5d46486e8bb

Is it possible to view a commit object?

Yes, viewing a commit object is possible, but this behaviour is not documented, as far as I can tell, and looks a little bit hacky:

<base_url>/_compare/<sha>

Example:

https://github.com/ethereum/wiki/wiki/_compare/b4ba41ef3a0127b338c082343c30d5d46486e8bb

It relies on the functionality that allows revision comparison. This will compare all files across two revisions:

<base_url/_compare/<sha1-first-rev>...<sha1-second-rev>

Example:

https://github.com/ethereum/wiki/wiki/_compare/30d60370456d603fca92a79691937679c8cae89e...b4ba41ef3a0127b338c082343c30d5d46486e8bb

While comparing revisions of a specific file looks like this:

<base_url>/page-title/_compare/<sha1-first-rev>...<sha1-second-rev>

Example:

https://github.com/ethereum/wiki/wiki/5-strategies-of-contribution/_compare/30d60370456d603fca92a79691937679c8cae89e...b4ba41ef3a0127b338c082343c30d5d46486e8bb

Are trees (directories) a thing or is it a flat namespace?

Trees are kind of a thing. It's a little weird. You can create directories in the repo when you're editing the repo locally, but they get flattened by the GH web interface. For example, you might have:

$ tree
.
└── some_dir
    └── some-file.md

To access it through the web interface, you would disregard the tree and go to:

<base_url>/some-file

Trying to access it through the expected full path does not work:

<base_url>/some_dir/some-file

Other Notes

  • the entire revision history of the wiki is accessible at:

    <base_url>/_history
    

    Example:

    https://github.com/ethereum/wiki/wiki/_history
    
  • the home page of every wiki is accessible through the <base_url>, but the history of that page is only accessible at:

    <base_url>/Home/_history
    

    Example:

    https://github.com/ethereum/wiki/wiki/Home/_history
    
  • likewise, the revision history of any particular page is available at:

    <base_url>/page-title/_history
    

Hope this helps. Please let me know if there's any other info that might be useful.

sheluchin avatar Oct 19 '19 12:10 sheluchin

Thanks for the intel. Looks gross but I'm not really surprised.

tpope avatar Oct 19 '19 20:10 tpope

The wiki feature on GitHub looks pretty half-baked and the underscore prefixes might suggest an unstable interface, especially considering those endpoints are not documented, but it has been that way for as long as I can remember and the wiki is a fairly popular feature in some communities.

sheluchin avatar Oct 20 '19 10:10 sheluchin

@tpope Would you accept an initial implementation that only opens/copies the URL for the current version of ~~markdown files~~ the supported markup filetypes? Something along the lines of:

  • If the remote is a GitHub repo that ends in .wiki, proceed with the following logic
  • If the ~~file does not end in .md~~ filetype is not one of the supported markup formats, echo a warning/error and return
  • Transform the file name into the url format (e.g. spaces to hyphens)
  • Open or copy the url ignoring line number, visual selection and history

While not ideal, it seems better than the existing behavior for GitHub wikis.

Edit: the implementation should support all of the markup formats GitHub Wikis support, not just markdown.

benelan avatar Jul 31 '24 23:07 benelan