Configuring live links in Klocwork reviewsYou can create a replacement schema to automatically create hyperlinks in commit messages, actions, and comments given a unique identifier such as a defect number or ID. You can access the replacement schemas or create a new replacement schema on the Settings tab in Code Review. A replacement schema consists of two parts: a regex and a URL pattern. A regex is a regular expression that matches a particular text pattern in a review comment, a commit message, or an action. The regular expression must contain one or more capturing groups that you can use as a variable in the URL pattern. The URL pattern is a template for the link's target URL. When a regular expression matches some text, it will be replaced with a link who's target URL is generated from the URL pattern with any arguments filled in. Default replacement schemas Code Review provides the following pre-defined replacement schemas:
Default format elements In addition to the default replacement schemas, Code Review also provides the following format elements that you can use in your own custom replacement schemas:
Create a replacement schema To create a new replacement schema, click Create a new schema. In the Regex field, enter the regex expression that matches the pattern that you want to replace. Be sure to include one or more capturing groups in your expression. For example: ref\:(\d+) In the URL pattern field, enter the replacement URL pattern, including format element, into which the capturing group will be injected. For example: /codereview/CodeReview.html#revision_goto:revisionId={0} Note: The URL replacement pattern must contain a format element for each capturing group in the regex field. You can specify the same format element multiple times. For a list of supported expressions, refer to the Java class documentation. Click Create to save the schema. If the regex pattern is matched in the text of a comment, action, or commit message, it will be replaced by the specified URL pattern. Example 1 The following example replaces a user's Twitter handle with a link to the user's Twitter page: Regex: @(\w+) URL pattern: https://twitter.com/{0} Example 2 The following example replaces a simple keyword phrase and ID number with a link to the corresponding record in a bug tracking system: Regex: [bB][uU][gG][\p{Space}|:]*(\d+) URL pattern: http://example.com/bugs?id={0}&project={project} The url pattern above uses the default {project} format element. |