如何使用 Trac & 实施提交后挂钩 Windows环境下的SVN?
我在带有 Trac / SVN 的 Windows 环境中运行,我希望提交到存储库以集成到 Trac 并关闭 SVN 注释中指出的错误。
我知道有一些提交后挂钩可以做到这一点,但关于如何在 Windows 上执行此操作的信息不多。
有谁做过成功的吗? 为了实现这一目标,您采取了哪些步骤?
这是我需要在 SVN 中放置的钩子,但我不太确定如何在 Windows 环境中执行此操作。
I'm running in a windows environment with Trac / SVN and I want commits to the repository to integrate to Trac and close the bugs that were noted in the SVN Comment.
I know there's some post commit hooks to do that, but there's not much information about how to do it on windows.
Anyone done it successfully? And what were the steps you followed to achive it?
Here's the hook I need to put in place in SVN, but I'm not exactly sure how to do this in the Windows environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我要添加的一件事是“Code Monkey 的答案是完美的”——要警惕这一点(我的错误),
我没有设置非系统路径,花了我一段时间才看到明显的:D
只要匹配确定不-别人也犯同样的错误! 感谢代码猴子! 1000000000 点 :D
One thing I'll add "Code Monkey's Answer is PERFECT" - is to be wary of this (my mistake)
I hadn't set the Non-System paths and took me a while to see the obvious :D
Just match sure no-one else makes the same mistake! Thanks Code Monkey! 1000000000 points :D
提交后挂钩位于服务器端存储库所在的“hooks”目录中。 我不知道你的环境中哪里有它们,所以这只是一个例子,
例如 (Windows):
例如(llinux/unix):
Post commit hooks live in the "hooks" directory where ever you have the repository living on the server side. I don't know where you have them in your environment, so this is just an example
e.g. (windows):
e.g. (llinux/unix):
对于所有想要安装最新 trac (0.11.5) 的 Windows 用户:
按照名为 TracOnWindows 的 Trac 网站上的说明进行操作。
即使您有 64 位 Windows,也请下载 32 位 1.5 Python。
注意:我在某处看到了如何编译 trac 以在 64 位系统上本地工作的说明。
安装所需的所有内容后,请转到存储库文件夹。 有文件夹挂钩。
里面放了 Code Monkey 提到的文件,但不要像他那样创建“trac-post-commit-resolve-ticket-ref.py”。 听取 Quant Analyst 的建议并像他说的那样:
“但是,根据您的 trac 版本获取正确的 python 脚本很重要。要获取适当的版本,SVN 检查文件夹:
http://svn.edgewall.com/repos/trac/branches/xxx -稳定/贡献
其中 xxx 对应于您正在使用的 trac 版本,例如:0.11"
从那里下载文件“trac-post-commit-hook”并将其放入 hooks 文件夹中。
在 trac-post-commit.cmd 中编辑这些行
记住没有最后一个 \ !!!
我已将最后一行 -r "%REV%" 中的引号删除为 -r %REV% 但我不知道是否需要这样做。这现在不起作用(至少在我的 win 2008 服务器),因为钩子会失败(提交会正常)。默认情况下,权限受到限制,我们需要允许 python 或 svn 或 trac (无论我不知道)更改 trac 信息。因此,转到 trac 文件夹、项目文件夹、db 文件夹,右键单击 trac.db 并选择属性,转到安全选项卡并编辑权限以允许每个人完全控制,但这不是很安全,但我在这个安全性上浪费了一整天。很重要,我不想浪费另一个只是为了找到应该为哪个用户启用权限
希望这会有所帮助......
For all Windows users who wants to install newest trac (0.11.5):
Follow the instructions on Trac's site named TracOnWindows.
Download 32bit 1.5 Python even if You have 64bit Windows.
note: I saw somewhere instructions how to compile trac to work natively on 64bit system.
When You install all that is required go to the repository folder. There is folder hooks.
Inside it put files Code Monkey mentioned, but dont create "trac-post-commit-resolve-ticket-ref.py" like he did. Take advice from Quant Analyst and do like he said:
"However, it's important to get the right python script depending on your trac version. To get the appropriate version, SVN check out the folder:
http://svn.edgewall.com/repos/trac/branches/xxx-stable/contrib
where xxx corresponds to the trac version you're using, for instance: 0.11"
From there downoad file "trac-post-commit-hook" and put it in hooks folder.
Edit these lines in trac-post-commit.cmd
Remember no last \ !!!
I have removed quotes from last line -r "%REV%" to be -r %REV% but i dont know if this is needed. This will not work now ( at least on my win 2008 server ), because hook will fail ( commit will go ok). This got to do with permissions. By default permissions are restricted and we need to allow python or svn or trac ( whatever i dont know ) to change trac information. So go to your trac folder,project folder,db folder, right click trac.db and choose properties. Go to the security tab and edit permissions to allow everyone full control. This isn't so secure but i wasted all day on this security matter and i don't want to waste another just to find for which user you should enable permissions.
Hope this helps....
首先非常感谢Code Monkey!
但是,根据您的 trac 版本获取正确的 python 脚本非常重要。 要获取适当的版本,SVN 请查看文件夹:
http://svn.edgewall.com /repos/trac/branches/xxx-stable/contrib
其中 xxx 对应于您正在使用的 trac 版本,例如:0.11
否则您将收到如下所示的提交后错误:
commit failed (details follow): MERGE of '/svn/project/trunk/web/directory/': 200 OK
First a big thanks to Code Monkey!
However, it's important to get the right python script depending on your trac version. To get the appropriate version, SVN check out the folder:
http://svn.edgewall.com/repos/trac/branches/xxx-stable/contrib
where xxx corresponds to the trac version you're using, for instance: 0.11
Otherwise you'll get a post-commit error that looks like this:
commit failed (details follow): MERGE of '/svn/project/trunk/web/directory/': 200 OK
好吧,现在我有时间在弄清楚这一切后发布我的经验,并感谢克雷格让我走上正确的轨道。 以下是您需要执行的操作(至少对于 SVN v1.4 和 Trac v0.10.3):
%~dp0\trac- post-commit-hook.cmd %1 %2
这里最重要的部分是设置 TRAC_ENV,它是存储库根目录的路径 (SET TRAC_ENV=C:\trac\MySpecialProject)
此脚本中的下一个最重要的事情是要做下列:
如果您在上面的脚本文件中看到我正在使用 svnlook(这是 SVN 的命令行实用程序)来获取 LOG 消息以及提交到存储库的作者。
然后,脚本的下一行实际上是调用 Python 代码来执行票证关闭并解析日志消息。 我必须修改它以传递日志消息和作者(我在 Trac 中使用的用户名与 SVN 中的用户名匹配,所以这很容易)。
脚本中的上述行将把 Trac 环境、修订版本、提交者及其评论传递到 python 脚本中。
这是我使用的 Python 脚本。 除了常规脚本之外,我做的一件事是我们使用自定义字段 (fixed_in_ver),我们的 QA 团队使用该字段来判断他们正在验证的修复是否位于他们在 QA 中测试的代码版本中。 因此,我修改了 python 脚本中的代码来更新票证上的该字段。 您可以删除该代码,因为您不需要它,但如果您也想这样做,它是一个很好的示例,说明您可以在 Trac 中更新自定义字段。
我通过让用户选择在他们的评论中包含类似以下内容来做到这一点:
然后,我使用 Python 脚本与正则表达式相同的技术来获取信息。 还不错。
无论如何,这是我使用的 python 脚本,希望这是一个很好的教程,讲述了我如何让它在 Windows 世界中工作,这样你们都可以在自己的商店中利用它......
如果你不想处理使用我用于更新自定义字段的附加代码,从上面 Craig 提到的位置获取基本脚本 (来自 Edgewall 的脚本)
Alright, now that I've got some time to post my experience after figuring this all out, and thanks to Craig for getting me on the right track. Here's what you need to do (at least with SVN v1.4 and Trac v0.10.3):
%~dp0\trac-post-commit-hook.cmd %1 %2
The most important parts here are to set your TRAC_ENV which is the path to the repository root (SET TRAC_ENV=C:\trac\MySpecialProject)
The next MAJORLY IMPORTANT THING in this script is to do the following:
if you see in the script file above I'm using svnlook (which is a command line utility with SVN) to get the LOG message and the author that made the commit to the repository.
Then, the next line of the script is actually calling the Python code to perform the closing of the tickets and parse the log message. I had to modify this to pass in the Log message and the author (which the usernames I use in Trac match the usernames in SVN so that was easy).
The above line in the script will pass into the python script the Trac Environment, the revision, the person that made the commit, and their comment.
Here's the Python script that I used. One thing that I did additional to the regular script is we use a custom field (fixed_in_ver) which is used by our QA team to tell if the fix they're validating is in the version of code that they're testing in QA. So, I modified the code in the python script to update that field on the ticket. You can remove that code as you won't need it, but it's a good example of what you can do to update custom fields in Trac if you also want to do that.
I did that by having the users optionally include in their comment something like:
I then use the same technique that the python script uses with regular expressions to get the information out. It wasn't too bad.
Anyway, here's the python script I used, Hopefully this is a good tutorial on exactly what I did to get it to work in the windows world so you all can leverage this in your own shop...
If you don't want to deal with my additional code for updating the custom field, get the base script from this location as mentioned by Craig above (Script From Edgewall)
本杰明的答案很接近,但在 Windows 上,您需要为挂钩脚本文件提供可执行扩展名,例如 .bat 或 .cmd。 我使用.cmd。 您可以采用模板脚本(unix shell 脚本、shell 脚本)并将它们转换为 .bat/.cmd 语法。
但要回答与 Trac 集成的问题,请按照以下步骤操作。
确保 Python.exe 位于系统路径上。 这将使您的生活更轻松。
在 \hooks 文件夹中创建 post-commit.cmd。 这是 Subversion 将在提交后事件上执行的实际挂钩脚本。
<前><代码>@ECHO 关闭
:: 提交后挂钩
::
:: 提交后钩子在提交后调用。 Subversion 运行
:: 通过调用程序(脚本、可执行文件、二进制文件等)来调用此钩子
:: 命名为“post-commit”(此文件是其模板)
:: 以下有序参数:
::
:: [1] REPOS-PATH(此存储库的路径)
:: [2] REV(刚刚提交的修订版本号)
::
:: 调用的默认工作目录未定义,因此
* 如果程序关心的话,应该明确设置一个。
::
:: 因为提交已经完成并且无法撤消,
:: 钩子程序的退出代码被忽略。 钩子程序
:: 可以使用“svnlook”实用程序来帮助它检查
:: 新提交的树。
::
:: 在 Unix 系统上,正常的过程是“post-commit”
:: 调用其他程序来完成实际工作,尽管它可能会执行
:: 本身也起作用。
::
:: 请注意,“提交后”必须可由将要执行此操作的用户执行
:: 调用它(通常是用户 httpd 运行),并且该用户必须
:: 具有访问存储库的文件系统级权限。
::
:: 在Windows系统上,你应该给hook程序命名
:: 'post-commit.bat' 或 'post-commit.exe',
:: 但基本思想是相同的。
::
:: 钩子程序通常不继承环境
:: 它的父进程。 例如,一个常见的问题是
:: PATH 环境变量未设置为其通常的值,因此
:: 除非通过绝对路径调用,否则子程序无法启动。
:: 如果您在使用挂钩程序时遇到意外问题,
:: 罪魁祸首可能是异常(或丢失)的环境变量。
::
:: 这是一个用于 Unix /bin/sh 解释器的示例挂钩脚本。
:: 有关更多示例和预先编写的挂钩,请参阅
:: Subversion 存储库位于
:: http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ 和
:: http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/
设置本地
:: 调试设置
:: 1. 复制该文件。
:: 2. 启用以下命令来调用复制的文件。
:: 3.删除所有其他命令
::call %~dp0post-commit-run.cmd %* > %1/hooks/post-commit.log 2>&1
:: 调用 Trac 提交后挂钩
调用 %~dp0trac-post-commit.cmd %* || 1号出口
终端本地
在 \hooks 文件夹中创建 trac-post-commit.cmd:
<前><代码>@ECHO 关闭
::
:: 适用于 Windows 的 Trac post-commit-hook 脚本
::
* 由markus 提供,由CBOO 修改。
:: 用法:
::
:: 1) 在 post-commit.bat 脚本中插入以下行
::
:: 调用 %~dp0\trac-post-commit-hook.cmd %1 %2
::
:: 2) 检查下面的“修改路径”部分,确保至少设置 TRAC_ENV
设置本地
: ------------------------------------------------ ----------
:: 修改路径:
:: -- 这个*必须*设置
SET TRAC_ENV=D:\projects\trac\membershipdnn
:: -- 如果Python不在系统路径中则设置
设置 PYTHON_PATH=
:: -- 如果安装在非标准位置,则设置为包含 trac/ 的文件夹
设置 TRAC_PATH=
::------------------------------------------------ ----------
:: 如果trac环境不存在则不执行hook
如果不存在%TRAC_ENV% 转到:EOF
设置路径=%PYTHON_PATH%;%PATH%
设置 PYTHONPATH=%TRAC_PATH%;%PYTHONPATH%
设置转速=%2
:: 解决票证引用(修复、关闭、引用等)
Python "%~dp0trac-post-commit-resolve-ticket-ref.py" -p "%TRAC_ENV%" -r "%REV%"
终端本地
在 \hooks 文件夹中创建 trac-post-commit-resolve-ticket-ref.py。 我使用了来自 EdgeWall 的相同脚本,只是我重命名了它以更好地阐明其目的。
Benjamin's answer is close, but on Windows you need to give the hook script files an executable extension, such as .bat or .cmd. I use .cmd. You can take the template scripts, which are unix shell scripts, shell scripts and convert them to .bat/.cmd syntax.
But to answer the question of integrating with Trac, follow these steps.
Ensure that Python.exe is on the system path. This will make your life easier.
Create post-commit.cmd in \hooks folder. This is the actual hook script that Subversion will execute on the post-commit event.
Create trac-post-commit.cmd in \hooks folder:
Create trac-post-commit-resolve-ticket-ref.py in \hooks folder. I used the same script from EdgeWall, only I renamed it to better clarify its purpose.