Code Review: The Unit of Work Should Be a Single Commit
Join the DZone community and get the full member experience.Join For Free
i’m fascinated by source-control, as my readers know. i’m not sure if this is is a bad idea, but there’s a code-review tool that could use source-control as its storage backend. i’ve no time to make it, and if someone else does, i’d be very excited.
a new code review application for use by teams doing trunk based development with in-house source-control installations, and wanting to follow the “continuous review” idiom that google pioneered with their “mondrian” code review system. guido van ruossum’s 2006 video is a great start, and though it’s not super related to this article, i want to call out one guido statement (2m 35s in):
namely, “code review is a good alternative to pair programming”, that love of extreme programmers (of which thoughtworks has thousands), and he talks to it at 5 mins 20 seconds in and goes as far as to say “best alternative” :)
this tool is aimed at those building on devops foundation, and wanting to go further towards cd. it would be installable in the source-control infrastructure, as it would review the commits of. if you’re already using a paid github service for your ‘system’ you probably don’t need a new review system, and the same would be true for atlassian’s stash.
angularjs (or similar), source-control as the data-store (sharing accounts with that underlying system), sinatra (or similar) for the web-server middle bit. there would need to be some triggered scripting for each commit as it comes in, and some shelling out to the command line. there’s need to be some “rebuild of index” capability too, because things crash or get out of step.
a commit in a trunk (say svn, perforce, git, etc) causes a triggered generation of a diff that’s committed to second repo in the same source-control infrastructure. the web-server app (sinatra), passes that diff (in json form) to an angular page that is demanding it. reviewers interoperate with the document in the browser, add their code-reviews comments as nodes within the same json document. when finished, a reviewer hits a “save review” button and it goes back (via a put). the json document on the back-end gets committed to the repo dedicated to the reviews. the key (with a .json suffix) is obviously the change-list number (or hash). thus the original json diff gets expanded with each review info incrementally until the review is “done”. each of those is a bump to .json resource’s head revision.
over time the review is a series of changes to the original doc. there’s a neatness to that progression. there’s only so many times someting is modified in review before it is considered ‘done’. that’s important because i previously hypothesized what would fit source-control as a backing store .
there’s some complexity around two or more people reviewing the same commit in trunk. you would probably lock a commit for the duration of each review in the first version, and implement a auto-merge on the server-side in a follow up release. ideally you’d interoperate with the canonical source-control store on a per-document basis. this is easier for subversion (restfully) than for git as the latter really wants a clone before usage of working copy, though there are more advanced ways around that – especially for github.
power users could “checkout” the review repository, and do analysis on it. that would include history mining for various things like “strongest reviewer” and “most likely to fawn over someone else’s review without adding value him/herself”. then there review bubbles in the same style as the commit bubbles idea.
in terms of integration with the trunk (on which we’re doing a review), commits need to be blocked until the review has garnered enough karma.
git’s most popular workflows mean that a transient branch is created, and the review happens against that, but maybe that’s more advanced than the first version of this app would be. specifically “after commit” code review as a team gets better committing and before they move to the pre-commit style.
there’s a pointlessness to making another code review tool. even if you could make a claim that an angular-like front end exchanging json documents with a source-control repo, it solves no existing problem. it serves only perfectionism – sorry gang!
it is such a small application, that someone could easily make it in open-source land. it is perhaps a race to zero in terms of price-point, as the business of tools for developers can often be. given there are a few viable review tools and services, we have to ask ourselves if this would be worth it just to have the ‘meta’ accolade of having code-reviews stored in source-control.
competition / need
in the commercial space there’s atlassian’s crucible (related to their stash project i guess). what i do not like about crucible in particular is the unit of work (alluded to in this article’s title). for crucible, the unit of work is a “code review”, and that could be a number of commits. i think that’s an impediment to actually doing code reviews, and definitely an impediment to throughput as detracts from effective time in the code review tool.
there’s also the quite new upsource from jetbrains – gotta love those guys.
open-source-land has rietveld which contains some lines of code from mondrian from some years ago, but is not mondrian. there’s also gerrit which is a further spinoff. both are undergoing active development.
the open-source phabricator from facebook is particularly compelling though – and worth calling out on its own, because of it’s completeness and ease of use.
it is also far closer to the key feature i particularly like, than the likes of crucible:
the unit of work for a code review should be a single commit,
and the key for that should be the commit id itself.
this is probably because it is made by people that really understood how mondrian (and command line tools) worked at google, and fed the “high throughput” machine. it does its job well, works with subversion as well as git, mercurial, and perforce (via git-fusion though). anyone wanting to try phabricator should do so through a handy demo site (by phab.io who can do the hosting for you).
lastly, it can be configured to do code review after commit, or pre-commit (meaning they’ve done some extra tooling for subversion because of a lack of lightweight branches), which is quite neat. an enterprise dev-team can get better and better at code review, and plan to turn on the pre-commit gating when they are sure they are ready. hopefully driven by throughput metrics. colleague sam newman said something well in respect of this retrofitted capability [i paraphrase]:
[this] effectively reimplements the pull request model, albeit by building layers of tooling on top of [the scm technology].
the genus of continuous review
turning a unified diff into a json document
a stackoverflow question: what’s the best way to turn a subversion diff into json? (hint: regex is not the best way).
more recently i’ve been intrigued by ccs which may be a better storage format (more mergeable than json). angular would need json in the browser, but there’s no reason why a middle-tier piece couldn’t transparently translate between ccs and json. same’s true for yaml, which might be a better fit that ccs, as not all of the latter’s features are needed for this.
monkeying around with source-control as a backing store
i’m trying to avoid a relational schema here. blog links:
very small data (as mentioned)
feature toggles: app-config workflow using scm (relates to the project below)
and a github project: app-config app that uses angularjs as a front-end for json documents held in source control.
Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.