通过电子邮件发送 svn 的每日提交报告
我有一个提交后钩子,它将 svn 日志保存为 XML 文件。接下来,我必须进行格式化,以表格报告的形式显示数据,该报告将包含以下详细信息: 1)工单编号 2)文件名 2)文件路径 3) 修订号 4)业主 5)提交时间
该报告需要每天下午 5 点通过电子邮件发送给小组。 我需要一些示例代码来寻求帮助。
I have a post commit hook that will save the svn log as an XML file.Next i have to do formatting for showing the data in the form of a tabular report that will have the following details:
1)Work Order NO
2)Filename
2)Filepath
3)Revision No.
4)Owner
5)Commit Time
This report needs to be send to a group everyday at 5 PM via email.
I need some sample code for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这完全取决于您所使用的语言。
许多语言都有用于读取 XML 文件的模块。例如,Perl 有 XML::Simple 模块。
如果这是您的 Subversion 存储库每天下午 5 点需要的每日报告,那么您最好使用某种调度软件在下午 5 点运行一次该报告。在 Unix 系统上,您可以使用 cron 守护进程来安排系统运行脚本。在 Windows 上,您可以使用计划任务向导。
运行报告非常简单。您所需要的只是这样:
您必须计算
$YESTERDAY
是什么,并将其放入YYYYMMDD
格式,然后您就得到了报告!你如何获得昨天的日期?取决于您的编程语言。大多数操作系统将日期存储为距 epoc 的秒数(在 Unix 中,为 1970 年 1 月 1 日)。您使用编程语言的日期例程。
这将按更改集顺序列出,并列出每个更改集下更改的文件列表。如果您需要不同的格式,可以使用
--xml
开关,并获取 XML 格式的报告。此 XML 输出的格式非常简单,并且结构非常规则,您甚至可以在不使用 XML 解析模块的情况下解析它。除此之外我真的无法给你太多帮助。我不知道操作系统、您使用的语言,甚至不知道您的报告中到底需要什么。我只能告诉您的是,您不需要提交后挂钩 - 只需在适当的时间使用正确的参数运行 svn log ,几分钟之内,您就可以获得所有报告准备邮寄出去。
而且,由于这是使用
svn
,因此您所需要的只是 Subversion 客户端。您甚至不必在特定机器上生成此报告,只要该机器具有 Subversion 命令行客户端(可从许多地方下载)并以某种方式指定何时可以运行报告即可。It all depends upon the language you're using.
Many languages have modules for reading XML files. For example, Perl has the XML::Simple module.
If this is a daily report that you need for your Subversion repository at 5pm every day, you're better off simply running the report once at 5pm using some sort of scheduling software. On Unix systems, you could use the cron daemon to schedule your system to run a script. On Windows, you can use the Schedule Task Wizard.
Running the report can be very simple. All you need is something like this:
You have to calculate what
$YESTERDAY
is and put it inYYYYMMDD
format, and you have your report!How do you get yesterday's date? Depends upon your programming language. Most operating systems store dates as the number of seconds from an epoc (In Unix, it's January 1, 1970). You use your programming language's date routines.
This would be listed in change set order with a list of of the files changed under each change set. If you need a different format, you could use the
--xml
switch, and get the report in XML format. The format for this XML output is pretty straight forward, and is so regular in structure that you could even parse it without using an XML parsing module.I can't really give you much help beyond this. I don't know the OS, the language you use, or even exactly what you need in your report. All that I can tell you is that you don't need a post-commit hook -- just run the
svn log
at the appropriate time with the right parameters, and in minutes, you have your report all ready to mail out.And, since this is using
svn
, all you need is the Subversion client. You don't even have to produce this report on a particular machine as long as that machine has a Subversion command line client (downloadable from many places) and someway to specify when the report can be run.没有任何理由使用提交后挂钩,因为您只需使用 svn log -v --xml 即可获取数据。您可以要求其按日期进行修改;例如,
svn log -v --xml -r "$(date +'{%Y-%m-%d}'):HEAD"
获取今天的修订。还要记住,svn log 可以给出一个 URL,而不是本地结账。无论您熟悉哪种编程语言,都肯定具有可用于将 XML 转换为报告的 XML 解析库。
然后,您只需安排每天调用您的程序一次。在 Unix 上,您可以使用 cron。在 Windows 上,您可以使用任务计划程序。
除此之外,您所要求的东西类似于“为我编写代码”,这是危险的。
There isn't any reason to use a post-commit hook, because you can just get the data using
svn log -v --xml
. You can ask it for revisions by date; e.g.,svn log -v --xml -r "$(date +'{%Y-%m-%d}'):HEAD"
to get today's revisions. Remember also that svn log can be givin a URL instead of a local checkout.Whatever programming language you're familiar with surely has XML parsing libraries you can use to transform the XML into your report.
You then just need to arrange for your program to be called once per day. On Unix, you'd use cron. On Windows, you can use the Task Scheduler.
Other than that, you're asking for something dangerously close to "write my code for me".
我认为 SVN hook 不适合这项工作。毕竟,只有在每次提交后才会触发(如果每天有数百次提交怎么办?如果下午 5 点左右没有人提交怎么办?)。相反,我会编写一个 cron 作业 (linux) 或计划任务 (windows) 来每天下午 5 点执行此操作。您可以使用svn命令行工具查询日志 从存储库中,重新格式化它,然后通过电子邮件发送。
I think that an SVN hook is the wrong task for this job. After all this fires only after every commit (what if you have hundreds of commits a day? what if no one is committing around 5pm?). Instead, I would write a cron job (linux) or scheduled task (windows) to do this everyday at 5pm. You can use the svn command line tools to query the log from the repository, reformat it and then email it.