SHA-1 Git hashes can be mapped to code review or code repository URL to offer a web visualization with additional context.
The resolve-hash
command allows to get such URL from a Git hash, or another VCS reference. It can search Phabricator, Gerrit, GitHub and GitLab currently.
Ouf of the box, it will detect your ~/.arcrc configuration and use GitHub public API. You can create a small YAML configuration file it to add Gerrit and GitLab in the mix.
Install it. Use it.
The resolve-hash
package is available on PyPI.
1 2 3 4 5 |
$ pip install resolve-hash $ resolve-hash 6411f75775a7aa8db https::⃫github.com/10up/simple-local-avatars/commit/6411f75775a7aa8db2ef097d70b12926018402c1 |
Specific use cases
Projects moved from GitHub to GitLab
GitLab requires any query to the search API to be authenticated. You can generate a personal access token in your user settings; the API scope is enough, so check only read_api
.
Then you can add create a $HOME/.config/resolve-hash.conf
file with the following content:
1 2 |
# GitLab gitlab_public_token: glpat-sometoken |
For Wikimedia contributors
Gerrit exposes a REST API. To use it, create a $HOME/.config/resolve-hash.conf
file with the following content:
1 2 3 |
# Gerrit REST API gerrit: - https://gerrit.wikimedia.org/r/ |
Gerrit will be then queried before GitHub:
1 2 |
$ resolve-hash 311d17f289470 https::⃫gerrit.wikimedia.org/r/c/mediawiki/core/+/768149 |
Note if you’ve configured Arcanist to interact with phabricator.wikimedia.org, your configuration in ~/.arcrc is used BEFORE the Gerrit one. Tell me if you’re in that case, we’ll allow to order resolution strategies.
What inspired this project?
Terminator allows plugins to improve the behavior of the terminal. Some plugins allows to expressions like Bug:1234 to offer a link to the relevant bug tracker.
What if we can detect hashes, especially VCS hashes, to offer a link to the code review system, like Phabricator or Gerrit, or at least to a public code hosting facility like GitHub?
What’s next?
We can add support for private instances of GitHub Enterprise and GitLab. Code I wrote in VCS package is already ready to accept any GitHub or GitLab URL, and is so prepared to accept a specific instance, so it’s a matter of declare new configuration options and add the wrapper code in VcsHashSearch class.
A cache would be useful to speed up the process. Hashes are stable enough for that.
Write a Terminator plugin, so we solve the root problem described above.
The code is extensible enough to search other kind of hashes than commits, but I’m not sure we’ve reliable sources of hashes for know files or packages.
References
- Nasqueron DevCentral
- Python package repository