Review keyword

This section describes how to configure keywords, and how to use keywords in a changelist description to create a review, and add a changelist to a review.

Review keyword configuration

The keyword can be configured with a regular expression so that most any keyword syntax can be used. If you choose to customize the review keyword, take care to choose syntax and terminology that is unlikely to occur in a changelist description, to avoid unexpected Swarm activity.

To configure the review keyword, add the following block to the SWARM_ROOT/data/config.php file:

<?php
// this block should be a peer of 'p4'
'reviews' => array(
'patterns' => array(
'octothorpe' => array( // #review or #review-1234 with surrounding whitespace/eol
'regex' => '/(?P<pre>(?:\s|^)\(?)\#(?P<keyword>review|append|replace)(?:-(?P<id>[0-9]+))?(?P<post>[.,!?:;)]*(?=\s|$))/i',
'spec' => '%pre%#%keyword%-%id%%post%',
'insert' => "%description%\n\n#review-%id%",
'strip' => '/^\s*\#(review|append|replace)(-[0-9]+)?(\s+|$)|(\s+|^)\#(review|append|replace)(-[0-9]+)?\s*$/i',
),

'leading-square' => array( // [review] or [review-1234] at start
'regex' => '/^(?P<pre>\s*)\[(?P<keyword>review|append|replace)(?:-(?P<id>[0-9]+))?\](?P<post>\s*)/i',
'spec' => '%pre%[%keyword%-%id%]%post%',
),
'trailing-square' => array( // [review] or [review-1234] at end
'regex' => '/(?P<pre>\s*)\[(?P<keyword>review|append|replace)(?:-(?P<id>[0-9]+))?\](?P<post>\s*)?$/i',
'spec' => '%pre%[%keyword%-%id%]%post%',
),
),
),

Multiple patterns can be specified; the first successful match is used and none of the other patterns are evaluated.

The keyword types are grouped under their identifiers. In each group, the regex item specifies the regular expression to be used to identify the review keyword in the changelist description. The spec item is used when the review keyword needs to be updated.

Note

The use of named capture groups in the regex, for example (?<pre>\s*). The values captured during regex matching are used to replace any identically named placeholder values in the spec item that are surrounded by percent % characters. In the example configuration above, the pre and post capture groups and placeholders maintain any whitespace surrounding the review keyword.

For octothorpe (or "hashtag") review keywords, these can appear anywhere in the changelist description. The strip item is used to ensure that the keyword is removed from the review description if it appears at the start or end of the changelist description. The insert item is currently not used; it is included here to prevent future upgrade issues. The intended use case is when a review is started and the changelist does not already contain a review keyword, the insert item would be used to add the review keyword to the changelist description.

For more information on named capture groups in PHP, see: http://www.regular-expressions.info/named.html

Create a review

By default, including the keyword #review within a changelist description (separated from other text with whitespace, or on a separate line) tells Swarm that a review should begin when the changelist is shelved or committed.

Once a review has begun, Swarm adds the review identifier to the #review keyword, for example #review-1234. This tells Swarm which review should be updated whenever the original changelist is re-shelved or committed.

Note

Add a changelist to a review

Once a review has been started you can add a changelist to the review. It can be useful to add changelists to an existing review. For example, if follow up changes are made to files in a review or if you need to group a number of changelists under a single review.

Note

The changelist must not be part of another review, if it is Swarm will reject it.

Note

Swarm acts on the first valid keyword it finds in the changelist description, Swarm then ignores any further valid keywords it finds in the description.

By default, the #append-, #replace-, and #review- keywords along with the review identifier (separated from other text with whitespace, or on a separate line) can be used in a changelist description to add changelists to an existing review. The options available depend on whether the review is pre-commit or post-commit:

Tip

When the content of a review is changed, Swarm checks to see which branches are in the new revision of the review:

Example: Appending a changelist to review 1234:

Add #append-1234 to the changelist description.

Important

Committing a review with Swarm (recommended): Swarm automatically commits the files in the approved revision of the review.

Committing a review outside of Swarm:

Before you commit the review:

  1. Unshelve the review into the pending changelist associated with the review.
  2. Reshelve the files in the pending changelist.
  3. Commit the pending changelist.
  4. This process ensures that all of the files in the approved revision of the review are committed.
  5. Workflow technology preview feature disabled (default):

    Swarm can be configured to automatically check that the files being committed match the files in the approved revision of the review, see the strict trigger option.

    Workflow technology preview feature enabled:

    Swarm can be configured to automatically check that the files being committed match the files in the approved revision of the review by using the On commit with a review workflow rule. For information about the On commit with a review rule, see Workflow rules.

Example: Replacing the files in a review 1234 with the files in a changelist:

Add #replace-1234 to the changelist description.

Tip

When you replace a review with a changelist, the base versions of the files in the new revision of the review are the base versions of the files in the replacement changelist.

Keyword workflow

For workflow examples using keywords, see Review creation, and modification outside of Swarm.