Restricting Subversion commits if the Jira Issue key is Not in the commit message

I am using SVN for revision control and atlassian JIRA as the issue tracker for my LAMP website. I want to restrict SVN commit if any of my team member commits without mentioning the Jira Issue key for the same. I am using JIRA standalone and have installed it on my server. Google search gave me Subversion Jira Plugin (https://ecosystem.atlassian.net/wiki/display/SVN/Subversion+JIRA+plugin) but it can only help me out in tracking the commits that had a JIRA key, not in restricting them.

Please let me know, if I should post any more specifics about the issue.

Regards,

TechProceed.com

2 answers

Hi Snehal

You will have to write pre-commit hook in SVN to check if the comment has the JIRA key. You can additionally verify if the JIRA key is valid and is not closed. Here is extract from my pre-commit hook.

#Check first line contains JiraId
        firstline =lines[0].lstrip()
        if  firstline.find(":")==-1:
            sys.stderr.write(stdErrMsg)
            sys.exit(1)
        prefix= firstline.split(":")[0]
		
        if prefix.strip()=="":
            sys.stderr.write(stdErrMsg)
            sys.exit(1)

        jiraIDpattern = re.compile(r"(\A[A-Z]{2,}-\d+)")
        IDs=prefix.split(",")
        invalidMessage=0
        for rawID in IDs:
            ID=rawID.strip()
            result=jiraIDpattern.match(ID)
            if not result:
                sys.stderr.write("\n '"+ID+"' is not a valid JIRA issue ID")
                invalidMessage=1

        if invalidMessage:
            sys.exit(1)

		#Check JIRA is up
        try:
            soap = SOAPpy.WSDL.Proxy(jiraWSDL)
            auth = soap.login(jirauser, jirapasswd)
        except Exception, err:
            # If JIRA is down then except commit message as is.
            sendMail(firstline + " " + author )
            sys.exit(0)

        #Check JIRA issues exist
        invalidJIRAissue=0
        for rawID in IDs:
            issueid=rawID.strip()
            try:
                issue = soap.getIssue(auth, issueid)
            except SOAPpy.faultType,e :
                #issue does not exist
                soapError = issueid+": "+ str(e)
                sys.stderr.write("\n"+ issueid + " does not exist in JIRA")
                invalidJIRAissue=1
            else:
                #Check JIRA status is not closed
                if int(issue.status) == 6:
                    sys.stderr.write("\nYou cannot commit against "+issueid+ " as it is in a resolved state (CLOSED) ! ")
                    invalidJIRAissue=1
        if invalidJIRAissue:
            sys.exit(1)

Here user is required to put the commit message in format "JIRA-1234 : <message goes here>"

Vijay

Hi Vijay, thanks for the suggestion and the code! Sounds good and probably better than using a not really supported 3rd-party-plugin.

Let me note that you are relying on the SOAP API in your code, which will be removed in JIRA 7.

Use the Commit Policy Plugin.

Learn more about the Subversion-specific parts and use this recipe. If you want to limit which issues you allow to commit against, then also use these recipes.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

41 views 0 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you