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
- Download from Sourceforge: http://sourceforge.net/project/showfiles.php?group_id=202244
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/shpathtosvnchecker/Main.py PreCommit $1 $2 || exit 1
#!/bin/shpathtosvnchecker/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,UnitMain.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,FileLog.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
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,UnitMain.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.
- `Main.PreCommitChecks`: The Checks to be
enabled at the pre-commit phase.
- `Main.PostCommitChecks`: The Handlers to
be enabled at the post-commit phase.
- `%Check%.SuccessHandlers`: Handlers to
execute when `%Check%` was successfull.
- `%Check%.FailureHandlers`: Handlers to
execute when `%Check%` failed.
handlers/File.py
Writes the messages into a file.
- `%Check%.FailureFile`: File where fail
messages will be written.
- `%Check%.SuccessFile`: File where log
messages will be written.
handlers/Mail.py
Sends the messages per mail.
- `%Check%.FailureAddresses`: E-Mail
addresses where fail messages will be sent to.
- `%Check%.SuccessAddresses`: E-Mail
addresses where log messages will be sent to.
- `Mail.default`: Default mail address.
- `Mail.%Username%`: Mail address for user
`%Username%`.
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.
- `Mantis.URL`: URL to the !MantisConnect
Web Service.
- `Mantis.User`: Username to connect to
Mantis.
- `Mantis.Password`: Password to connect to
Mantis.
checks/Log.py
Creates the logfile.
- `Log.SvnWebUrl`: URL to the svnweb
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
- `Checkstyle.Java`: Path to java.
- `Checkstyle.Classpath`: Classpath for
checkstyle, must include checkstyle-all.jar and checkstyle-optional.jar.
- `Checkstyle.ConfigFile`: Path to checks.xml.
- `Checkstyle.CheckFiles`: List of regex's
for files to check.
- `Checkstyle.IgnoreFiles`: List of regex's
for files to ignore.
checks/Keywords.py
Checks if svn:keywords for added files are set.
- `Keywords.keywords`: Key words to check,
possible values are:
- Date/!LastChangeDate
- Revision/!LastChangedRevision/Rev
- Author/!LastChangedBy
- HeadURL/URL
- ID
- `Keywords.CheckFiles`: List of regex's for
files to check.
- `Keywords.IgnoreFiles`: List of regex's
for files to ignore.
checks/UnitTests.py
Checks if a unit test for a file is commited.
- `Keywords.CheckFiles`: List of regex's for
files to check.
- `Keywords.IgnoreFiles`: List of regex's
for files to ignore.
checks/XMLValidator.py
Checks xml files for correctness and agains schema and dtd.
Requirement: xerces-2.8
- `XMLValidator.Java`: Path to java.
- `XMLValidator.Classpath`: Classpath for
java, must include xercesImpl.jar, xml-apis.jar and xercesSamples.jar.
- `XMLValidator.CheckFiles`: List of regex's
for files to check.
- `XMLValidator.IgnoreFiles`: List of regex's
for files to ignore.
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.
- `AccessRights.Rules`: List of rules that
should be checked.
- `AccessRights.%RULE%.CheckFiles`: List of
regex's for files to check.
- `AccessRights.%RULE%.IgnoreFiles`: List of
regex's for files to ignore.
- `AccessRights.%RULE%.AllowUsers`: List of
users that may edit the files.
- `AccessRights.%RULE%.DenyUsers`: List of
users that may not edit the files.
checks/Pylint.py
Checks python files against pylint.
- `Pylint.CheckFiles`: List of regex's for
files to check.
- `Pylint.IgnoreFiles`: List of regex's for
files to ignore.
- `Pylint.Pylint`: Path to pylint
executable.
- `Pylint.ConfigFile`: Path to pylintrc.



