Subversion restriction is fixed if the Jira Issue key is not in the commit message

I am using SVN-1.7.4 for version control and atlassian JIRA as a problem tracker for my LAMP website. I want to limit the commit of SVN if any of my team members make a mistake without mentioning that this key is for Jira Issue. I use JIRA autonomously and installed it on my server. A Google search gave me the Subversion Jira Plugin (https://studio.plugins.atlassian.com/wiki/display/SVN/Subversion+JIRA+plugin), but it can help me track commits with the JIRA key, and not limit them . Please let me know if I write any details about this issue.

+5
source share
7 answers

It is easy to verify that the problem also exists in JIRA using the JIRA ReST API.

In our case, I used the pre-commit.tmpl and added the following after the comments section:

 REPOS="$1" TXN="$2" SVNLOOK=/usr/bin/svnlook CURL=/usr/bin/curl JIRAURL=http://our.jira.url:8080/rest/api/latest/issue # Make sure that the log message contains some text. LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS") echo ${LOGMSG} | grep "[a-zA-Z0-9]" > /dev/null || exit 1 # check that log message starts with a JIRA ticket # should have format 'FOO-123: my commit message' or 'FOO-123 my commit message' JIRAID=$(expr "${LOGMSG}" : '^\([AZ]*-[0-9]*\)[: ].*') if [[ "$JIRAID" == "" ]] then echo "No JIRA id found in log message \"${LOGMSG}\"" >&2 echo "Please use log message of the form \"JIRA-ID: My message\"" >&2 exit 1 fi # check if JIRA issue exists JIRAISSUE=$(${CURL} ${JIRAURL}/${JIRAID}) if [[ "${JIRAISSUE}" =~ "Issue Does Not Exist" ]] then echo "The JIRA id ${JIRAID} was not found" >&2 echo "Please use log message of the form \"JIRA-ID: My message\"" >&2 exit 1 fi 

This requires that the message be in the form of "JIRA-id: text" or "JIRA-id test". You can make the regex more general to allow the JIRA identifier anywhere in the text. You can also add checks on ${JIRAISSUE} to make sure the problem is open if necessary, but that seems sufficient for our purposes.

+8
source

I have a pre-commit hook that covers this (as well as much more).

The hook is available through the Git-Hub . It does not check if a Jira identifier exists, but it can verify that an identifier similar to Jira exists in a commit message. This is usually enough for developers to add Jira ticket numbers to their commit message. There is an example of a control.ini file that shows how to check a ticket number like Jira in your commit message. Valid commit messages will be formatted as follows:

  • NO: I fixed a problem in which there was no Jira ticket number
  • FDS-1231: I fixed one Jira ticket
  • FDS-1231, FDS-3232: I fixed several Jira tickets

However, a better way than the pre-commit trap is to change the workplace culture so that the developers naturally indicate the Jira ticket number in the commit messages and automatically give more detailed commit messages. I found that using a continuous build server such as Jenkins will do this.

Jenkins will automatically collect your code every time you register. Each assembly shows you the changes and commit comment. Jenkins integrates with Jira, so with one click you can see information about Jira. Jenkins will also attach a commit message and collect # on the Jira ticket so the quality assurance officer can look at a specific Jira ticket and see which assembly corrected that ticket.

Suddenly, commit message information becomes more visible. Developers and QA are starting to rely on this. Developers who do not add a Jira ticket are not targeted by the build guy, but by their boss and fellow developers. Posting good commit messages is now becoming a place culture. And this is much more efficient than any hook before committing.

+5
source

Atlassian provides a trigger script that does this for most common VCS systems, including SVN, plus a JIRA plugin that allows you to determine what to look for in a commit description. See the JIRA Commit Accepting Page .

+4
source

Well, I did this by creating a simple shell script host (pre-commit) that checks to see if the jira problem key was given by a regular expression and called the REST API to ensure that the problem exists on the server

 #!/bin/sh REPOS="$1" TXN="$2" SVNLOOK=/usr/bin/svnlook JIRAURL=http://myown.jira.server:8080/rest/api/latest/issue CURL=/usr/bin/curl LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS") # check if any comment has supplied by the commiter if [ -z "$LOGMSG" ]; then echo "Your commit was blocked because it have no comments." 1>&2 exit 1 fi #check minimum size of text if [ ${#LOGMSG} -lt 20 ]; then echo "Your Commit was blocked because the comments does not meet minimum length requirements (20 letters)." 1>&2 exit 1 fi # get jira ID by regex JIRAID=$(expr "$LOGMSG" : '^\([AZ]*-[0-9]*\)[: ].*') # Check if jira id was found. if [ -z "$JIRAID" ]; then echo "No JIRA id found in log message \"$LOGMSG\"" 1>&2 echo "Please use log message of the form JIRA-ID: My message" 1>&2 exit 1 fi # check if JIRA issue exists on the server JSON_RETURN=$(${CURL} -s ${JIRAURL}/${JIRAID} -u username:password | grep -o "errorMessage") if [ -n "$JSON_RETURN" ]; then echo "The specified Jira Issue \"$JIRAID\" was not found in Jira server." 1>&2 echo "Please, verify the specified issue ID and try again!" 1>&2 exit 1 fi 
+3
source

The floating policy plugin is a fairly new addition to JIRA to provide this.

Unlike other solutions proposed here, it not only checks for the presence of a type key in the message, for example a template (for example, "FOO-123"), but even matches the JQL query to configure JQL

For example, this allows you to check whether these problems exist:

  • current user stories in the current sprint
  • unresolved errors or tasks for the next version of the product
  • priority tasks assigned to teams (during the period of code freezing)

Besides checking these issues, he can also check:

  • committer identifier (is it in JIRA? is it in the JIRA group?)
  • modified files (only images are presented? are there any .class, .obj, * .tmp files? all * .PNG are in the / images directory?)
  • a commit message (the duration of this 10+ characters without spaces?) does it start with a JIRA key?)

Be sure to review the documentation and try.

Disclaimer: I am a developer working on this add-in. However, this is the best solution available for this problem.

+1
source

A regular expression is added after the script to find any pattern, for example abc-123, and check if it is present in jira. Also, any similar model can also be present anywhere in the comment, but the presence of one successful template will allow you to commit -

 #!/usr/bin/perl -w $STATUS="1"; $REPOS=$ARGV[0]; $TXN=$ARGV[1]; $SVNLOOK="/usr/bin/svnlook"; $CURL="/usr/bin/curl"; $JIRAURL="http://xxxx/jira/rest/api/2/issue"; $LOGMSG = `$SVNLOOK log -t $TXN $REPOS`; chomp ($LOGMSG); print "--$LOGMSG--\n"; if ($LOGMSG !~ /[A-Za-z][A-Za-z]*-[0-9][0-9]*/ ) { print STDERR "NO JIRA case Found in comment - $LOGMSG"; exit (1); } @ARRAY= split (' ',$LOGMSG); foreach (@ARRAY){ next if ! /[A-Za-z][A-Za-z]*-[0-9][0-9]*/ ; chop(); $JIRAISSUE = `$CURL $JIRAURL/$_`; chop ($JIRAISSUE); if ($JIRAISSUE =~ /Issue Does Not Exist/){ print STDERR "The JIRA id $_ was not found\n"; }else { exit (0) }; } exit ($STATUS); 
+1
source

I saw this before using a simple regular expression in a binding before commit.

On the plus side, there was no need to test Jira at all, but it also meant that you could just put something into it only as a valid problem key.

0
source

Source: https://habr.com/ru/post/1411303/


All Articles