运行 SVN 预提交挂钩时如何将 stdout 发送给用户
我有一个 SVN 的预提交钩子,它运行错误检查程序并在出现问题时中止提交。如果出现问题,stderr 会被重定向到发起提交的用户。但即使没有发现问题,我也想从错误检查程序发送用户输出,以便通知用户错误检查程序已运行并且没有发现问题。如何使用 SVN 预提交钩子来做到这一点?
I have a pre-commit hook for SVN which run error-checker program and aborts commit in case of problems. stderr is redirected to the user initiating commit in case of problems. But I would like to send user output from the error-checker program even if no problems were found, so that the user is notified that error-checker ran and found no problems. How to do it with SVN pre-commit hook?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Subversion hooks 会吃掉它们的 STDOUT。脚本运行后,就没有 STDOUT。您甚至无法让预提交脚本将 STDOUT 发送到另一个进程。
然而,在预提交挂钩内,STDOUT 仍然存在并且仍然可以重定向。例如,我的钩子由一个 shell 脚本组成,该脚本由几行 Unix 命令行实用程序组成。每个命令行实用程序都有一个 STDIN 和一个 STDOUT,我可以从一个管道传输到另一个。但是,一旦该钩子脚本执行完毕,就没有 STDOUT。
另一件事是无法通过钩子范例来通信 STDOUT。 Subversion 不提供任何类型的通信链接。有一个 STDERR 的链接,但前提是钩子本身失败。这是一个预提交挂钩,我怀疑您故意想让这个挂钩失败只是为了向用户提供报告。
您可以做的是使用其他通知方法。有些人建议使用电子邮件。您可以运行提交后脚本来生成报告并根据用户的电子邮件地址通过电子邮件发送该报告。我不会将此作为预提交触发器,因为您不希望事务因报告不起作用而失败。
有些人建议您可以使用电子邮件地址映射进行提交的用户并向该用户发送电子邮件。我不会这样做,因为用户会简单地忽略该电子邮件。他们已经收到了来自各个流程的数十封甚至数百封电子邮件,提醒他们注意这一点或那点。
我建议是使用像 Hudson 这样的产品来进行连续构建,并由 Hudson 生成此报告并将其发布在 Hudson 生成的构建页面上。这样,开发人员可以返回并检查报告。事实上,Hudson 已经有各种插件可以进行错误检查并生成各种漂亮的报告和图表(通常与 findbugs 或其他类似项目一起使用)。
更有趣的插件之一是一个游戏,它会为成功构建、修复错误和警告等奖励积分。它提供了一个排行榜,以便开发人员可以将他们的分数与其他开发人员进行比较。我从未使用过它,但 Hudson 用户组中的一些人说开发人员的分数竞争非常激烈。
Subversion hooks eat their STDOUT. Once the script is run, there is no STDOUT. You can't even have the pre-commit script send STDOUT to another process.
However inside the pre-commit hook, STDOUT still exists and can still be redirected. For example, my hook consists of a shell script consisting of several lines of Unix command line utilities. Each command line utility has a STDIN and a STDOUT, and I can pipe from one to the other. But, once that hook script finishes executing, there is no STDOUT.
The other thing is that there is no way to communicate STDOUT via the hook paradigm. Subversion doesn't provide any sort of communications link. There is a link for STDERR, but only if the hook itself fails. This being a pre-commit hook, I doubt you purposely want to fail this hook just to give the user the report.
What you can do is use other methods of notification. Some people suggested email. You could run a post-commit script to generate the report and email that report based upon the user's email address. I would not do this as a pre-commit trigger because you don't want the transaction to fail because the report didn't work.
Some people suggested that you can map the user who did the commit with an email address and email the user. I would not do this because the users will simply ignore the email. They already get dozens if not hundreds of emails from various processes alerting them to this or that.
What I would recommend is to use a product like Hudson to do continuous builds, and have this report generated by Hudson and posted on the build page Hudson generates. This way, a developer can go back and examine the report. In fact, Hudson already has various plugins that do error checking and produces all sorts of nice reports and graphs (usually working with findbugs or other projects like that).
One of the more interesting plugins is a game that awards points for successful builds, fixing bugs and warnings, etc. It presents a leader board, so developers can compare their score to other developers. I never used it, but some people on the Hudson user group say that the developers get very competitive over their scores.
您必须以某种方式将用户名映射到电子邮件地址。然后您可以将输出收集到文件中并将其邮寄给提交者。
You must map the username to an email address somehow. Then you can collect the output in a file and mail it to the committer.
就我而言,我编写了一个简单的 C# Windows 窗体应用程序来显示挂钩的进度。
In my case, I wrote a simple C# Windows form application to display the progress of the hook.