如果Jira Issue密钥不在提交消息中,则限制Subversion提交 [英] Restricting Subversion commits if the Jira Issue key is Not in the commit message

查看:110
本文介绍了如果Jira Issue密钥不在提交消息中,则限制Subversion提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SVN-1.7.4进行版本控制,并使用atlassian JIRA作为我的LAMP网站的问题跟踪器。我想限制SVN提交,如果我的任何团队成员都提交而没有提及相同的Jira Issue密钥。
我正在独立使用JIRA,并已将其安装在服务器上。 Google搜索为我提供了Subversion Jira插件(https://studio.plugins.atlassian.com/wiki/display/SVN/Subversion+JIRA+plugin),但它只能帮助我跟踪具有JIRA密钥的提交,而不能帮助我跟踪在限制他们。
如果让我发布有关此问题的更多详细信息,请告诉我。

I am using SVN-1.7.4 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://studio.plugins.atlassian.com/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.

推荐答案

使用JIRA ReST API检查JIRA中是否也存在该问题并不困难。

It's not difficult to check that the issue exists in JIRA also, using the JIRA ReST API.

在我们的例子中,我使用了 pre-commit.tmpl 文件,并在开始注释部分之后添加了以下内容:

In our case I used the pre-commit.tmpl file and added the following after the opening 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}" : '^\([A-Z]*-[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

这要求消息的格式为 JIRA -id:文本或 JIRA-id测试。您可以使正则表达式更通用,以允许在文本中的任何位置使用JIRA id。您还可以在 $ {JIRAISSUE} 上添加支票,以确保在需要时可以打开该问题,但这对我们而言似乎足够。

This requires the the message to be of the form "JIRA-id: text" or "JIRA-id test". You could make the regular expression more general to allow a JIRA id anywhere in the text. You could also add checks on the ${JIRAISSUE} to ensure that the issue is open if desired, but this seems sufficient for our purposes.

这篇关于如果Jira Issue密钥不在提交消息中,则限制Subversion提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆