GitHub URL UX

I was adding a GitHub URL to a presentation to reference the source code of what I was talking about. The URL was:

https://github.com/slaclab/slactwin/blob/3c84ca7d4b3b31c21d07a95cf77766507d4e1c97/slactwin/pkcli/db.py

That's pretty long for text on a slide and took up more real estate than I liked. A hyperlink would work, but I wanted people to see that the link was from GitHub and hopefully that would prompt them to click on it and look at the source code. Git (and by extension GitHub) works with shortened commit hashes. Usually, just the first few characters of a hash are enough to uniquely identify a commit. Looking at the repo, it seems like GitHub is using the first 7 characters. So, I tried shortening the URL:

https://github.com/slaclab/slactwin/blob/3c84ca7/slactwin/pkcli/db.py

Voila! That works! That will fit nicely on my slide. I find GitHub, in general, is kind to its users regarding URLs. For example, you can go to /issues/pr_number, and it will redirect to /pulls/pr_number:

https://github.com/radiasoft/sirepo/issues/7292
# redirects because 7292 is actually a PR
https://github.com/radiasoft/sirepo/pull/7292

Often in issues, emails, Slack, etc., people will put something like #1234. Just by looking at the number, it is impossible to know whether it is an issue or a PR. So, GitHub lets you just say it is one or the other, and it will do the work of redirecting if you guessed wrong. One caveat is that (to my eyes) there is confusion in their URLs regarding words being plural:

# pull is singular
https://github.com/radiasoft/sirepo/pull/7292
# issues is plural
https://github.com/radiasoft/sirepo/issues/7292
# pull -> pulls searches author:<number>
https://github.com/radiasoft/sirepo/pulls/7292
# issues -> issue is a 404
https://github.com/radiasoft/sirepo/issue/7292

That's a bit odd. I wonder why? Also, in case you didn't know, when you want to provide a link to a line of code, you can select the line number next to the link, and GitHub will link directly to that line (with it highlighted). Before copying the link, you can press y, which will change /blob/master in the URL to /blob/<commit_sha>. Including the commit SHA in links ensures future readers go to exactly the line of code you were looking at when you created the link. Without this, who knows what line 62 in foo.py on master will be pointing to 3 years from now.

P.S.

While writing this, I learned git has configuration for the number it uses when abbreviating hashes. Nice.