After the release of Amino Acid Quizillator 1.5 last week, we had an opportunity to do some general housekeeping. I decided to tackle a task that we had been wanting to deal with for a while, namely some JIRA project management. This led me down a bit of a rabbit hole that ultimately required updating all the log entries for one of our Subversion repositories.
Being fairly new to JIRA, one thing I like about it is the ability to see Subversion activity on an issue by issue basis thanks to the Subversion JIRA plugin by Atlassian. The plugin indexes each revision log entry for various Subversion repositories. It then uses the JIRA issue key to associate a log entry with a JIRA issue. The issue key itself being comprised of the corresponding JIRA project key and a number.
Long story short, I ended up having to rename one of our JIRA projects. This included changing the corresponding JIRA project key which ended up being pretty straightforward thanks to this post: http://confluence.atlassian.com/display/JIRA/Changing+the+Project+Key. However, it wasn’t immediately clear how to update all of the revision log entries for one of our Subversion repositories that was associated with this JIRA project. Our Subversion repositories each execute a pre-commit hook which enforces the inclusion of a JIRA issue key in the log message. This was something to start with.
After some investigation I discovered exactly what I needed, the following Subversion admin command:
svnadmin setlog REPOS_PATH -r REVISION FILE
This command only updates the log entry for a specific revision which makes sense. That being the case, I decided to brush up on my Python and write a quick and dirty script to use this command to iteratively update the JIRA issue key in each revision log entry. First things first, I grabbed a dump of the repository to be updated so I could test the script against it locally before letting it anywhere near our Subversion server. Below is the script I wrote:
#! /usr/bin/env python import os #determine the newest revision in the repository using 'svnlook youngest' max_rev = os.popen("svnlook youngest /path/to/repository").read().rstrip() print max_rev temp_filename = "newlog.txt" for i in range(1, int(max_rev) + 1): #grab the old log message using 'svnlook log' and replace the old project key with the new one f1 = os.popen("svnlook log /path/to/repository -r " + `i`) new_log_message = f1.read().replace("OLD_PROJECT_KEY", "NEW_PROJECT_KEY", 1).rstrip() #replace the temporary file and write new log message to it, since this is what 'svnadmin setlog' requires f2 = open(temp_filename, "w") f2.write(new_log_message) f2.close() #update the revision log with the new message using 'svnadmin setlog' rename_cmd = "svnadmin setlog --bypass-hooks /path/to/repository -r " + `i` + " " + temp_filename print rename_cmd f3 = os.popen(rename_cmd)
The script worked as expected and the repository was updated. I just had to wait for the JIRA Subversion plugin to run and index the changes; or so I thought. I checked some of the JIRA projects associated with this repository and had yet to see any of the updated log messages; or any log messages for that matter. After some digging, it turned out that one more step had to be performed. That is, to get JIRA to re-index all the subversion logs from the integrated Subversion repositories. I found that the following forum thread pointed me in the right direction to accomplish this: http://forums.atlassian.com/thread.jspa?threadID=39390&tstart=0&messageID=257326108.