Prerequisites of this article are Redmine and Subversion independent servers running on Ubuntu OS. In this previous article you can read how install Redmine on Ubuntu server. The client machines are configured with Windows OS.
Redmine server configuration
First you need to install Subversion client on your Redmine server.
sudo apt-get install subversion
Restart the apache server.
sudo service apache2 restart
Login on Redmine as administrator an go to Administration Settings / Repositories. Check that Subversion repository is enabled.
Add the keyword "Issue" to the field Referencing keywords.
Go to Administration / Settings / General and change this values:
- Objects per page options: 25, 50, 100, 999
- Maximum number of items in Atom feeds: 999
Now go to Redmine project settings / repository and configure the subversion integration:
The last step is to allow remote connections to the MySQL database.
sudo nano /etc/mysql/my.cnf
Edit the line with the bind-address parameter to allow the Subversion server to access the Redmine database with:
bind-address = 0.0.0.0
Restart the MySQL service with:
/etc/init.d/mysql restart
Now we need to grant access to the Redmine user from the Subversion server.
mysql -u root -p
mysql> CREATE USER 'redmine_user'@'%' IDENTIFIED BY PASSWORD 'pass';
mysql> GRANT USAGE ON * . * TO 'redmine_user'@'%' IDENTIFIED BY PASSWORD 'pass';
mysql> GRANT ALL PRIVILEGES ON `redmine_database` . * TO 'redmine_user'@'%';
Subversion server configuration
Now we can configure subversion to allow only commits that are associated to a open Redmine issue.
First we need to install Ruby and MySQL client on the subversion server:
sudo apt-get install ruby
mysql-client
Check the connection with the redmine database with:
mysql -u redmine_user -h redmine_host -p redmine_database
Type exit lo leave the MySQL client.If all is right, go to the subversion root folder and enter to the project database directory, then type:
sudo nano hooks/pre-commit
Copy and paste the following Ruby script:
#!/usr/bin/ruby
repo_path = ARGV[0]
transaction = ARGV[1]
svnlook = '/usr/bin/svnlook'
mysql = '/usr/bin/mysql'
commit_log = `#{svnlook} log #{repo_path} -t #{transaction}`
if (commit_log == nil || commit_log.length < 2)
STDERR.puts("Log message cannot be empty.")
exit(1)
end
if (commit_log =~ /^\s*\(Issue\s#(\d+)\)/)
issue_number = $1
if (issue_number.to_i.to_s == issue_number)
sql = "SELECT COUNT(*) AS result FROM issues I INNER JOIN issue_statuses S ON S.id = I.status_id WHERE S.is_closed = 0 AND I.id = #{issue_number};"
redmine_issue_open = `#{mysql} --host=redmine_host --database=redmine_database --user=redmine_user --password=user_password -e "#{sql};" --skip-column-names`.strip()
if (redmine_issue_open.eql?("0"))
STDERR.puts("Redmine issue #{issue_number} is not in an open state.")
exit(1)
end
else
STDERR.puts("Issue is not a number")
exit(1)
end
else
STDERR.puts("You need to specify a Redmine open issue number with this format:
(Issue #1234)
Commit message goes here")
exit(1)
end
Change the owner and add execution rights to the script with:
sudo chown www-data:www-data hooks/pre-commit
sudo chmod a+rx hooks/pre-commit
Client configuration
Install TortoiseSVN and TurtleMine on the Windows client machine.
Go to the root folder of the project you want to add traceability, left click and select TortoiseSVN / Settings. Go to the Issue Tracker Integration and click the Add button.
Select the Working Copy Path as the local folder on the client machine where the project resides.
Select TurtleMine as Provider.
On the Parameters field you need to write the web address of the Redmine project atom issues feed. To know the address go to your Redmine project / View All Issues / Atom copy and paste the URL to the Parameters field.
To finish Accept the changes.
Now we are ready to do the first commit!!!
Go to your project files, do some changes. Left click the folder and select SVN commit. Then press the Redmine Issues button.
The window will show the Redmine list of not closed issues. Check on one or more issues and click Ok.
The message text on the commit window is automatically filled with the text "(Issue #number)". Type a commit message and click OK.
Now you can go to the Redmine issue and see all commits associated:
And that's all, from now all subversion commits are forced to be associated with an open Redmine issue adding traceability to all changes made to the source code.
No hay comentarios:
Publicar un comentario