{"id":851,"date":"2022-03-06T14:47:34","date_gmt":"2022-03-06T13:47:34","guid":{"rendered":"https:\/\/www.dereckson.be\/blog\/?p=851"},"modified":"2022-03-06T14:47:35","modified_gmt":"2022-03-06T13:47:35","slug":"get-url-from-git-commit-hash","status":"publish","type":"post","link":"https:\/\/www.dereckson.be\/blog\/2022\/03\/06\/get-url-from-git-commit-hash\/","title":{"rendered":"Get URL from Git commit hash"},"content":{"rendered":"\n<p>SHA-1 Git hashes can be mapped to code review or code repository URL to offer a web visualization with additional context.<\/p>\n\n\n\n<p>The <code>resolve-hash<\/code> command allows to get such URL from a Git hash, or another VCS reference. It can search Phabricator, Gerrit, GitHub and GitLab currently.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install it. Use it.<\/h2>\n\n\n\n<p>The <code>resolve-hash<\/code> package is <a href=\"https:\/\/pypi.org\/project\/resolve-hash\/\" data-type=\"URL\" data-id=\"https:\/\/pypi.org\/project\/resolve-hash\/\">available on PyPI<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ pip install resolve-hash\n\n$ resolve-hash 6411f75775a7aa8db\nhttps::\u20ebgithub.com\/10up\/simple-local-avatars\/commit\/6411f75775a7aa8db2ef097d70b12926018402c1\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Specific use cases<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Projects moved from GitHub to GitLab<\/h3>\n\n\n\n<p>GitLab requires any query to the search API to be authenticated. You can <a href=\"https:\/\/gitlab.com\/-\/profile\/personal_access_tokens\">generate a personal access token in your user settings<\/a>; the API scope is enough, so check only <code>read_api<\/code>.<\/p>\n\n\n\n<p>Then you can add create a <code>$HOME\/.config\/resolve-hash.conf<\/code> file with the following content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># GitLab\ngitlab_public_token: glpat-sometoken<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">For Wikimedia contributors<\/h3>\n\n\n\n<p>Gerrit exposes a REST API. To use it, create a <code>$HOME\/.config\/resolve-hash.conf<\/code> file with the following content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Gerrit REST API\ngerrit:\n  - https:\/\/gerrit.wikimedia.org\/r\/<\/code><\/pre>\n\n\n\n<p>Gerrit will be then queried before GitHub:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ resolve-hash 311d17f289470\nhttps::\u20ebgerrit.wikimedia.org\/r\/c\/mediawiki\/core\/+\/768149<\/code><\/pre>\n\n\n\n<p>Note if you&#8217;ve configured Arcanist to interact with phabricator.wikimedia.org, your configuration in ~\/.arcrc is used BEFORE the Gerrit one. Tell me if you&#8217;re in that case, we&#8217;ll allow to order resolution strategies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What inspired this project?<\/h2>\n\n\n\n<p>Terminator <a href=\"https:\/\/terminator-gtk3.readthedocs.io\/en\/latest\/plugins.html\">allows plugins to improve the behavior<\/a> of the terminal. Some plugins allows to expressions like Bug:1234 to offer a link to the relevant bug tracker.<\/p>\n\n\n\n<p>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?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s next?<\/h2>\n\n\n\n<p>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&#8217;s a matter of declare new configuration options and add the wrapper code in <a href=\"https:\/\/devcentral.nasqueron.org\/source\/resolve-hash\/browse\/main\/src\/resolvehash\/search\/vcs.py\">VcsHashSearch<\/a> class.<\/p>\n\n\n\n<p>A <a href=\"https:\/\/devcentral.nasqueron.org\/T1694\">cache would be useful<\/a> to speed up the process. Hashes are stable enough for that.<\/p>\n\n\n\n<p><a href=\"https:\/\/devcentral.nasqueron.org\/T1695\">Write a Terminator plugin<\/a>, so we solve the root problem described above.<\/p>\n\n\n\n<p>The code is extensible enough to search other kind of hashes than commits, but I&#8217;m not sure we&#8217;ve reliable sources of hashes for know files or packages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Nasqueron DevCentral<ul><li><a href=\"http:\/\/devcentral.nasqueron.org\/tag\/resolve_hash\/\">Kanban workboard<\/a><\/li><li><a href=\"https:\/\/devcentral.nasqueron.org\/source\/resolve-hash\/\">Repository<\/a><\/li><li><a href=\"https:\/\/devcentral.nasqueron.org\/maniphest\/task\/edit\/form\/1\/?tags=resolvehash\">Report an issue<\/a><\/li><\/ul><\/li><li>Python package repository<ul><li><a href=\"https:\/\/pypi.org\/project\/resolve-hash\/\">Package on PyPI<\/a><\/li><li><a href=\"https:\/\/pypi.org\/project\/resolve-hash\/#description\">README<\/a><\/li><\/ul><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,30],"tags":[302,81,357,206,268,274],"class_list":["post-851","post","type-post","status-publish","format-standard","hentry","category-dev","category-wikimedia","tag-cli","tag-gerrit","tag-git","tag-phabricator","tag-python","tag-wikimedia"],"_links":{"self":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/comments?post=851"}],"version-history":[{"count":4,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/851\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/851\/revisions\/855"}],"wp:attachment":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/media?parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/categories?post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/tags?post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}