Scripting

Top  Previous  Next

Scripting is the easiest way to implement custom behaviors with Code Collaborator.

Command Line Client

You can use the Command Line Client to script actions on your user's machines, or install it on the same machine as the Code Collaborator Server and invoke it with a trigger.

The Command Line Client can create, delete, and edit reviews, including templates and review custom fields.  It can assign or remove participants within a review, and even move reviews to the next phase (e.g. from "planning" to "inspection").  It can also create comments and defects, including defect custom fields, and mark defects as external.

You can use the Command Line Client to create, edit, enable or disable user accounts.  It can be used to set up user information like email addresses and phone numbers.  It can also be used to set up author or file-based subscriptions.

Batching Commands

Often when scripting you find that you need to run multiple Command Line Client commands.  It's OK to simply run them one after the other in your script, but it is more efficient to group them together using the ccollab admin batch command.  The batch command takes as input an XML file which lists the commands to be run and optionally global options to use to run them.

It's faster to run multiple commands using the batch command because the Command Line Client only has to connect and authenticate with the Code Collaborator Server once.  Also the XML input format is useful if the data you are passing to the Command Line Client contains characters difficult to encode on the command-line like line feeds, quotes, or multi-byte characters.

Extracting Data

The ccollab admin review-xml command lets you extract data from one or more reviews in your script.  You can supply an XSL file to format the output, or an XPATH expression to select only the specific data you need.  You can even use XPATH functions to perform some computation.

Prompting

You can disable all interactive prompting by specifying the non-interactive global option.

If non-interactive is not specified, the Command Line Client will automatically prompt for server url, user, and password as necessary when it connects to the Code Collaborator Server.  You can also use the special value "ask" when specifying a review.  Using "ask" will cause the Command Line Client to interactively prompt the user with the list of reviews they are currently involved in.

If you are invoking more than one command, you can use the special value "last" in combination with "ask".  Using "last" will cause the Command Line Client to address the review most recently accessed by the Command Line Client.  Typically the first command in the script will use "ask" and then subsequent commands use "last" to access the same review.

Opening a Browser

Code Collaborator is fundamentally a web-based tool and the actual reviewing goes on in a browser.  Many Command Line Client commands automatically open a browser to allow the user to take the next step.  You can prevent the Command Line Client from opening a browser by specifying the no-browser global option.

You can also explicitly open a browser using the ccollab browse command.  Note the browse command ignores the no-browser global option.

"Virtual" Script Users

Often when setting up scripting it is convenient to create a Code Collaborator user which the script will use to log in to the Code Collaborator server.  Simply create a user in the normal way and give the credentials (login and password) to the script.  The "virtual" script user will not consume a license because it will never log in to the Code Collaborator web interface.

Downloading file version content

A special URL lets you download the binary contents of any file version efficiently. In this example, the file version ID is 12345:

http://myserver.com:8080/data/server?versionid=12345