[[PageOutline(2-5,Contents,pullout)]] = Lightweight code review of changesets = == Description == This plugin adds a lightweight means to review changesets directly on existing changeset pages. (!JavaScript is required.) [[Image(review1.png)]] This plugin comes with its own {{{CommitTicketReferenceMacro}}} which can be optionally used instead of the built-in one to display the current status within the ticket: [[Image(ticket1.png)]] When a review summary is provided, it gets added as a comment to all tickets referenced in the changeset (also shown above). There are other good code review tools out there that I've used (e.g., [http://code.google.com/p/gerrit/ gerrit]) but I wanted something very lightweight that fits well into existing Trac tools and ticket workflow. The few existing Trac-based code review plugins (below) appear to be unmaintained. And so this plugin was born. See also: CodeReviewPlugin, PeerReviewPlugin, ExoWebCodeReviewPlugin == Configuration == 1. Install the plugin (after downloading and unzipping): {{{ cd codereviewerplugin/0.12 sudo python setup.py bdist_egg sudo cp dist/TracCodeReviewer*.egg /your/trac/location/plugins/ }}} See [http://trac.edgewall.org/wiki/TracPlugins TracPlugins] for more installation details and options. You'll likely need to restart Trac's web server after installation. 2. Enable the plugin ''and'' if using the built-in {{{commit-updater}}}, disable {{{CommitTicketReferenceMacro}}}: {{{ [components] tracopt.ticket.commit_updater.committicketupdater = enabled tracopt.ticket.commit_updater.committicketreferencemacro = disabled coderev.* = enabled }}} You can alternatively use the Trac Web Admin GUI to enable or disable components. 3. (''optional'') Customize the names for the three statuses (make sure there are always exactly three in the shown order of meaning): {{{ [codereviewer] status_choices = REJECTED,PENDING,PASSED }}} 4. After the above, run: {{{ sudo trac-admin /path/to/projenv upgrade }}} See the examples section [wiki:CodeReviewerPlugin#Examples below] for more configuration options. == Bugs/Feature Requests == Existing bugs and feature requests for CodeReviewerPlugin are [report:9?COMPONENT=CodeReviewerPlugin here]. If you have any issues, create a [http://trac-hacks.org/newticket?component=CodeReviewerPlugin&owner=robguttman new ticket]. == Download == Download the zipped source from [download:codereviewerplugin here]. == Source == You can check out CodeReviewerPlugin from [http://trac-hacks.org/svn/codereviewerplugin here] using Subversion, or [source:codereviewerplugin browse the source] with Trac. == Examples == The screenshots in the examples above show basic examples. There are some additional extensions: === Workflow - field validation === There are many ways to integrate code reviews into your Trac ticket workflow. As just one example, you may have a {{{phase}}} custom field that includes different phases: 1. implementation 1. codereview 1. verifying If you wanted to prevent the {{{phase}}} from moving beyond "codereview" until all pending code reviews were completed and the last changeset passed review, then if using this plugin's commit ticket reference macro you can add the following [wiki:DynamicFieldsPlugin DynamicFields plugin] rules: {{{ [ticket-custom] phase.invalid_if.1 = verifying phase.invalid_when.1 = .codereviewstatus .pending (msg:Pending code reviews.) phase.invalid_if.2 = verifying phase.invalid_when.2 = .codereviewstatus:last .failed (msg:The last code review did not pass.) }}} === Continuous Integration (Jenkins / Hudson / Bitten / etc.) === [http://code.google.com/p/gerrit/ Gerrit's] philosophy is to treat a code review similar to a Jenkins test job - i.e., code changes do not get promoted to the next stage in a continuous integration / deployment pipeline until they pass a review. You can achieve this effect with this plugin via an included [browser:codereviewerplugin/0.12/coderev/util/reviewer.py Reviewer] class. In brief, [browser:codereviewerplugin/0.12/coderev/util/reviewer.py Reviewer] accepts a target git reference (e.g., "develop" or "master") and its {{{get_next_changeset()}}} method will return the changeset that is closest to that target (since the last changeset found) whose referenced ticket(s) have been completed. A "completed" ticket is one that passed the workflow tests described above - i.e., * the ticket has no PENDING changesets to review, ''and'' * the ticket's last changeset PASSED review. You can configure this plugin to trigger a Jenkins job (or any command) in {{{trac.ini}}}: {{{ [codereviewer] command = curl http://jenkins.example.com/job/stage_deploy/build?token=mytoken }}} In the example above, each time a code review is submitted for a completed ticket, the {{{stage_deploy}}} Jenkins job gets triggered. The job would then call [browser:codereviewerplugin/0.12/coderev/util/reviewer.py Reviewer.get_next_changeset()] to determine what git changeset to deploy (if any). (Note that this trigger for, say, a stage environment would be in addition to any trigger for running tests against the HEAD of your branch - or however you may currently have your CI system setup.) ==== Ticket-changeset map ==== In order for the [browser:codereviewerplugin/0.12/coderev/util/reviewer.py Reviewer] to know all changesets that reference a given ticket, it needs a reliable ticket-changeset map. The built-in {{{revision}}} table is unfortunately not sufficiently reliable for some version control systems (e.g., git) - this is a known issue. So this plugin comes with its own changeset listener that manages a new {{{codereviewer_map}}} table. For existing changesets, you can run a provided [browser:codereviewerplugin/0.12/coderev/util/sync.py sync.py] utility once to populate the table (but should nto need it after that). ==== Completeness criteria ==== You can also add "completeness" criteria to determine when a ticket is actually complete and ready for deployment. For example, if your workflow encourages ongoing code reviews on tickets that may not be fully complete, you can specify one or more ticket fields to use as additional criteria to determine completeness in {{{trac.ini}}}: {{{ [codereviewer] completeness = phase=(codereview|verifying|releasing) }}} In the above example, a "complete" ticket is now defined as not only having all changesets reviewed and the last review PASSED, but also that the ticket's custom phase field has a value of either "codereview", "verifying", or "releasing". The format of the completeness {{{trac.ini}}} options is a comma-delimited list of field-rule pairs where a rule is a regex that is used to match the field's value. === Workflow - ticket changes === You can have code review submissions automatically change fields of completed tickets. Continuing the workflow example from above, if a ticket's custom phase field gets set to "codereview" and reassigned to a reviewer, the reviewer may typically send the ticket back to "implementation" and the author after a failed review. The plugin can do this automatically via specifying this in {{{trac.ini}}}: {{{ [codereviewer] failed = phase=implementation,owner={author} passed = phase=verifying,owner={author} }}} Upon a failed review in the above example, the ticket's phase field will get set to "implementation" and the ticket's owner field will get set to the same value as the author field (assuming there is one). The curly braces syntax indicates to copy the value from the indicated field. Similarly, a passed review will change the ticket's phase field to "verifying" and set the owner field to the author. Note: these automated ticket changes will only happen for ''completed'' tickets following the same definition as defined above (i.e., all changesets are reviewed and the last review PASSED, and satisfy all completeness criteria if defined) - with the exception that the last review does not need to have passed to trigger the failed ticket change rules (obviously). == Recent Changes == [[ChangeLog(codereviewerplugin, 3)]] == Author/Contributors == '''Author:''' [wiki:robguttman] [[BR]] '''Maintainer:''' [wiki:robguttman] [[BR]] '''Contributors:'''