Skip to: Site menu | Main content

Check your commits!

SVNChecker is a framework for Subversion pre-commit hook scripts. The SVNChecker handles Subversion (SVN) pre-commit hooks in order to implement checks of files before they are commited. For example, you can check for the code style or unit tests.

Overview



SVNChecker Overview

Document Version 1.0

28. September 2007

svnchecker.sourceforge.net

 

About

SVNChecker is a framework for Subversion pre-commit hook scripts. The SVNChecker framework handles Subversion pre-commit hooks in order to implement checks of files before they are commited. For example, you can check for the code style or unit tests. The output of the checks can be send by mail or be written into a file or simply print to the console.

License


Copyright 2006 Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


Design

Language


SVNChecker is written in
Python.


Checks


Checks are scripts that do a particular check on the transaction, e.g. pylint
or unit tests. They are located in the `checks` folder. All checks have to define
a class `Check` with a main method.

class Check:
    (msg, exitCode) main(transaction, config)



Handlers


Handlers are scripts that do something with the result of the checks. For example, they send
an email or create console output. They are located in the `handlers` folder. All
handlers have to define a `Handler` class with a main method.

class Handler:
    void main(transaction, config, module, msg, exitCode)



The Transaction class


The transaction class is responsible for getting information about the current
transaction, for example, to be committed files or committing user. It has the
following functions:

String getUserID()
String{} getFiles()
String getFile(filename)
String getCommitMsg()
String getReposPath()
String getRevision()
Boolean fileExists(filename)
String getKeyword(keyword, filename)
Boolean fileExists(filename)
String getKeyword(keyword, filename)



The Configuration class


The configuration class is responsible for getting configuration variables. It
has the following self-explaining functions:

String[] getArray(String)
String getString(String)
Boolean getBoolean(String)
Integer getInteger(String)



Installation

Requirements


Subversion 1.2 is required. Some checks or handlers may depend on external tools or other modules, those have to be installed on the server, otherwise an error will be raised.


Download

 



Hooks


To install those scripts you have to create two hook files in your svn hooks
directory (`pre-commit` and `post-commit`). Both have to be executable:

#!/bin/sh
pathtosvnchecker/Main.py PreCommit $1 $2 || exit 1

 

#!/bin/sh
pathtosvnchecker/Main.py PostCommit $1 $2 || exit 1



Configuration



Configuration file


The script searchs for the `svncheckerconfig.ini` file in the current hooks
directory. Multiple values can be comma separated. All configuration, which
checks and handlers are enabled and the configuration of the particular
checks and handlers, has to be done in this file. If no configuration file was
found, an error will be raised.


File format


The configuration file has a standard ini file format, e.g.

[Default]
Main.PreCommitChecks=Mantis,Unit
Main.PostCommitChecks=Log


For the available configuration variables please read the documentation of the
particular module.


Checks and Handlers


For each check you have to specify which Handler will be executed on Success and
on Failure, for example, if you have the Log check:

[Default]
Log.SuccessHandlers=Mail,File
Log.FailureHandlers=Console


After that you have to configure the particular variables of the checks, e.g.
mail addresses or files, they are explained later.


Resolving of Variables


The resolving of variables is done in two steps. First, it will be looked for the exact variable name, e.g. "Checkstyle.!SuccessFile". If this one could not be found, the value before the "." will be replaced by Main, e.g. "Main.!SuccessFile".


Profiles


You can split the configuration file into profiles, e.g. you could specify one
profile per project. All profile variables have to be in a section named with
the profile name. For each profile you have to specify a regular exression.
The default section is "Default" and does not have a Regex variable.
If the path of the commited file relative to the repository location matches
this profile, it is used and no other profile will be checked. If no matching
profile was found the default profile with no prefix is used. If a particular
variable was not found in the profile the default variable will be used.
If this variable does not exist an error will be raised. A small example,
assuming that your profile name is TENT:

[Default]
Main.PreCommitChecks=Mantis,Unit
Main.PostCommitChecks=Log
 
[TENT]
Main.Regex=^TENT/
Main.PreCommitChecks=Checkstyle,Mantis


The `Checks.PreCommit` variable has been overwritten, but the `Checks.PostCommit`
variable is not specified, thus the global one from the example above will be used.


Modules


You always have to replace `%Check%` in the config file with the real name of the check, without `.py` extension.


Main.py


Main Functions of the framework.



handlers/File.py


Writes the messages into a file.



handlers/Mail.py


Sends the messages per mail.



handlers/Console.py


Prints the messages to the console.


handlers/MantisHandler.py


Adds the log message to the correct MANTIS issue and updates the SVNRevision field of the bug.


modules/MantisModule.py


Handles access to the MANTIS issue tracker via the
Mantis Connect Web Service.



checks/Log.py


Creates the logfile.



checks/MantisCheck.py


Checks if a log message contains a valid MANTIS ID, with a MANTIS ID <#> that is set to status 'in_progress' and if the MANTIS ID belongs to the commmiter.


checks/Checkstyle.py


Checks java files for code style.

Requirement: checkstyle



checks/Keywords.py


Checks if svn:keywords for added files are set.



checks/UnitTests.py


Checks if a unit test for a file is commited.



checks/XMLValidator.py


Checks xml files for correctness and agains schema and dtd.

Requirement: xerces-2.8



checks/AccessRights.py


Implements simple access rights. A list of rule names is given. Then for each rule a list of files to check and ignore is given and if you are not in the !AllowUsers group or are in the !DenyUsers group you dont' have rights to edit them.



checks/Pylint.py


Checks python files against pylint.