Aimlessly Going Forward

blog by Tomas Sedovic

Bookmarklet to expand inline comments in Gerrit

tl;dr: drag this link to your Bookmarks bar: Expand Gerrit Comments.

A core part of the OpenStack development culture is doing code reviews. To get a patch merged in an openstack project, it must be reviewed and approved by two core reviewers.

The reviews are coordinated through Gerrit where one can see the entire history of the proposed change, diffs, test results and the inline comments.

Unfortunately, when one reviews a file, the existing inline comments are collapsed by default and Gerrit offers no quick way to expand them all -- you have to click on each one and the click targets aren't particularly Fitts'-friendly.

If only there was a common way to script any browser!

So here's a simple bookmarklet that that you can drag to your browser's Bookmarks bar:

Expand Gerrit Comments

When you're browsing a Gerrit page with inline comments (such as this one), just click on the Expand Gerrit Comments button and enjoy the flames!

The code behind this magick is quite straightforward:

Array.prototype.forEach.call(
    document.querySelectorAll(".commentPanelContent"),
    function(el, ix) {
        el.style.display = 'block';
    });

It should work in any modern browser. Licensed under WTFPL 2.0.

Happy bikeshedding.

Tomas Sedovic on 4 February, 2014