You are here:Home»KB»Programming»General»Redmine»Integrate Subversion with Redmine
Sunday, 25 January 2015 17:01

Integrate Subversion with Redmine

Written by

Installation of Subversion with redmine can be straight forward if you have some easy toread instructions, so here they are.

There are several levels of integration

Basic SVN Integration

  • browse SVN Repositories
  • close jobs via SVN commit messages
  • compare revisions

Read the official Instructions - RedmineSettings - Repositories

According to the instructions this only works if Redmine and the Subversion Server are on the sam physical machine (this needs 100% clarifying but for now we will assume it is true).

This feature allows you to grab the commits from a predefined SVN Repository (most protocols are supported) and this repository is attached to a project, by doing this when you submit a commit to a repository with a message with correct issue reference syntax, redmine will close the related isse(s) in the project. Git , SVN and other SCM are available. This feature also allows you to perfomr comparisons of different revisions and you eben get the choice to see the changes side-by-side or on top of each other, this feature can be useful depending on how your code looks. There is also a repository browse feature built in to redmine. You can have multiple repositorys per project

Enable Fetch Commits Automatically

In Redmine Administration/Settings/Repositories make sure that Fetch Commits Automatically is ticked. If this option is activated, the application automatically retrieves the new revisions when a user consults the repository.

Official article here

Instructions to add a repository

make sure u use a network version for the repository so you can move it if you want.

  • create a project
  • In the project settings, make sure that the 'Repository' module is enabled and go to the 'Repository' tab.
  • Select the SCM that corresponds to your repository and enter the path or URL of your repository.
  • i used these settings, Redmine was able to download the changes from the repository

SCM Subversion
Main repository checked
identifier test-identifier (dont know what this is for, Repository Identifier)
URL https://svn.exampleserver.com:18080/svn/Test/
user svn-redmine
password xxwhateverxxxx


* when the repository is set you cannot change the details after you have created it except for the surname and password.I have read on the redmine official documentation that you should use a network location for you Subversion repository

  • the first time you view the repository redmine will retrieve all of the changes and import the information

Now that you have configured these settings you can close jobs via a svn commit (see below for forming a correct message for closing jobs) but the draw back is that the changes/commits are only retrieved at certain times

  1. when you browse the SVN repository via Redmine
  2. if you set up a CRON job {add details here}

Allow SVN Commits to Close Jobs

In the step above you configured Redmine to interact with Subversion and to retrieve any changes/commits. Redmine currently parses the commit messages for keywords which reference issue, it does this so it can automatically change these keywords into links. These links are found by using a set of default rules and keywords which can be chamged in the admin panel but the default options should be fine for most people.

The one thing Redmine does not do by default is close issues. You need to specify the keywords that you want to be used as closing keywords and enable the option in the Redmine settings via the admin panel.

Links

What Should i Do?

  1. Browse to Administration/Settings/Repositories/'Referencing and fixing issues in commit messages' Section
  2. Enable 'Allow issues of all the other projects to be referenced and fixed'
  3. Add the following into 'Fixing keywords'
    fix,fixes,fixed,close,closed,patches,patched

    If i get a better list i will add it here, but these keywords give you the gist.

  4. Set 'Applied Status' to Closed
  5. Set '% Done' to 100%
  6. Click Save at the bottom left of the page to save all changes
  7. Done

You can configure whatever rule you want but at least this will get you going. Read the official Documentation for the syntax of closing statements you should use in your commit messages.

NB:

  • I do not know if the keywords are case sensitive

Advanced Keywords

Better Issue Referencing

Redmine has a list of keywords it scans for to identify issues as follows:

refs,references,IssueID

I want to extend that to the following list

refs,references,IssueID,bug,bugs,defect,defects,feature,features,issue,issues,patch

I dont know about whether yoou can close multiple issues but i will add the plural version here anyway

Resolve Issue Keywords (optional)

These are different status and have different uses so require their own settings in the'Referencing and fixing issues in commit messages'.

If you want to have the resolved option set from commit messages you need to do the following:

  1. Browse to Administration/Settings/Repositories/'Referencing and fixing issues in commit messages' Section
  2. Add a new 'Fixing' rule
  3. Add the following into 'Fixing keywords'
    resolve,resolves,resolved
  4. Set 'Applied Status' to Resolved
  5. Set '% Done' to 100%
  6. Click Save at the bottom left of the page to save all changes
  7. Done

Example Commit Message Syntax for Redmine

To reference and issue use a command using any of the issue referencing keywords as below:

issue #1234

To close a job use the following or similiar command with any of the other closing keywords

close #1234

The key thing with these is that that the command is in a certain format

{keyword}{a space}{a hash}{issue number}

Resolved Vs Closed Links

Close Jobs Imediately Upon SVN Submit

To get jobs to close when you actually submit the commit further integration is required which is in the next section.

This is a very useful feature because in my opinion this is how everyone will think this integration works, when you submit a commit with closing statements in the message that issue will be immediately closed. In the 'Basic SVN Integration' this does not happen until you browse the repository or your cron job is fired so the commits get parsed and redmine closes the jobs so there could potentially be a gap between closing the jobs and this apopearing on the Redmine installation.

In this method you basically create a post-commit hook that polls the Redmine installation which then instructs Redmine that some changes have been made and that it should fetch them. It should be noted that this can cause a slight slow down in the commiting of the changes to the repository.

There are 2 types of polls you can use:

  1. Fetches changesets for all active projects

    /sys/fetch_changesets?key=<your service key>

  2. Fetches changesets from the repository of a specific project. This will be quicker that the previous method.

    /sys/fetch_changesets?id=<project identifier>&key=<your service key>

And several delivery methods for the hook:

  1. Visual Basic (.vbs)
  2. wget
  3. cURL
  4. Ruby (via command line)

My Instructions

I will be using cURL for these instructions because it is the easiest solution.

Do this once

  1. Download the correct cURL Binary from here. Get the Generic Non-SSL version for your architecture (x86/x64), security will be addressed in a later article
  2. Copy the file to D:\Documents\developer\SubversionEdge\bin - this folder should be in your path from when you installed Collabnet Subversion Edge. You can put this file anywhere but if it is not in your path you need to use the full location of the executable or add that location to your path.
  3. Disable Fetch Commits Automatically - there is no point in fetching changes upon browsing the repository from within redmine if your changes are always upto date.
    • You make this change by going to Administration/Settings/Repositories/ and untick this option.
  4. Enable Enable WS for repository management - This allows the Webservice to be used for triggering refreshes.
    1. You make this change by going to Administration/Settings/Repositories/ and tick this option.
    2. 'Genereate a Key' for the WS Services
  5. Save Changes

Required For Each Repository

For each repository you need create add an exectuable post-commit hook with the commands in it to trigger Redmine in to checking for changes. I will use a Hook that updates only the repositories in that particular project. It will also be very easy to change to refresh all repositories.

post-commit.bat

@ECHO OFF

curl "http://<redmine url>/sys/fetch_changesets?id=<project identifier>&key=<your service key>" 

This is the example code from Redmine's official instructions on calling a URL that will trigger Redmine to refresh all Repositories for that chosen Project.

Create the 'post-commit' Hook

I will assume

  • you have created a test repository called 'Test' and it is physically located at D:\Documents\developer\SubversionEdge\data\repositories\Test
  • Redmine is located at http://localhost/redmine/
  • Your project in Redmine is called 'TestProject'
  • Your WS Key that you generated earlier is 'Password123'
@ECHO OFF

curl "http://localhost/redmine/sys/fetch_changesets?id=TestProject&key=Password123" 
  1. create a file called post-commit.bat
  2. edit this file and add the code above in to it and save.
    NB: if the repository you are updating is in another project you will need to alter the project name accordingly, you cannot just copy the Hook file into another repository.

  3. Move this file to D:\Documents\developer\SubversionEdge\data\repositories\Test\hooks
  4. Done

Upon a successful commit to your Subversion Repository, Redmine will check all of the Repositories that belong to the specified project for changes.

You might be asking why cannot i not just update only a specified repository in Redmine rather than all of the repositories that belong to a project. This is a requested feature but for some reason it has not been added yet. Considering things most people will not notice this and if you use the command that refreshes all repositories in Redmine upon a successful commit you will never need this. If you use the 'Refresh All' command you can just copy this to other repository hook folders without alteration.

Useful Links

Automatically Create SVN Repositories

This is the final level of integration but it is not easy and seems to come with its own issues. You have to edit code and do this and that to get it to work. It is quicker to create the SVN Repository in Subversion Edge and then enter the details into redmine as in 'Basic SVN Integration'

I will not be implementing this aas i have easy control over my Subversion Server

See the official page for more information

Read 2440 times Last modified on Tuesday, 17 February 2015 18:24