实现过程:

1、使用git log 可以获取到所有git commit。对命令加入参数后,可以获取某段时间的log、和只输出log的某些字段。如:

[root@localhost crowd-web-server]# git log --pretty=format:'%an | %cd | %s' --after='2017-03-5 14:42'

该命令为:只获取2017年3月5号以后的git log。并且只返回 提交人、提交时间、提交信息3个字段内容

2、过滤掉一些CI提交内容的log,输出时,在最前面加入模块信息如:【sdk】【web】

  1. filter1 = 'gitlab-ci.yml'
  2. filter2 = 'Merge branch'
  3. filter3 = 'xxxxxxhui'
  4.  
  5. File.readlines('sdk_sourceNotes.txt').each do |line|
  6. file.puts " 【sdk】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  7. end

3、最后将过滤好的内容写入一个文本即可。以下为完整脚本

  1. souNotesPath = '/home/shench/script/releaseNotes/'
  2. sdk_ProjectPath = '/home/devProject/sdk/sense-crowd'
  3. sdk_crossline = '/home/devProject/sdk/crossline'
  4. server_nodeProjectPath = '/home/devProject/server/Crowd2.1-node'
  5. server_appProjectPath = '/home/devProject/server/CrowdAnalyze-app'
  6. server_forwardProjectPath = '/home/devProject/server/VideoForward'
  7. webStatic_projectPath = '/home/devProject/web/crowd-web-static'
  8. webServer_projectPath = '/home/devProject/web/crowd-web-server'
  9.  
  10. branch = ARGV[0].to_s.sub('[','').sub(']','')
  11. ciBranch = ARGV[1].to_s.sub('[','').sub(']','')
  12. devBranch = 'v2.3.0'
  13. sdk_CL_branch = 'v1.0.0'
  14.  
  15. system("cd /home/CrowdProduct;git checkout #{branch};git status;git pull #{branch} #{branch};cat releaseNotes.txt")
  16. #获取上次编译时间
  17. File.readlines('/home/CrowdProduct/releaseNotes.txt').each do |line|
  18. @lastBuilt = line.sub('build time:','') if line=~/build/
  19. end
  20. puts "last built time:#{@lastBuilt}"
  21. puts "get git log"
  22. source_releaseNotes = "git log --pretty=format:'%an | %cd | %s' --after=#{@lastBuilt.chomp.inspect}"
  23. # puts source_releaseNotes
  24.  
  25. puts "get sdk git log"
  26. #获取sdk编译日志
  27. system("cd #{sdk_ProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}sdk_sourceNotes.txt")
  28. system("cd #{sdk_crossline};pwd;git checkout #{sdk_CL_branch};git pull #{sdk_CL_branch} #{sdk_CL_branch};git status;#{source_releaseNotes} > #{souNotesPath}sdk_CLsourceNotes.txt")
  29.  
  30. puts "get server git log"
  31. #获取server编译日志
  32. #node -tianshuai
  33. system("cd #{server_nodeProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}server_node_sourceNotes.txt;cat #{so
  34. uNotesPath}server_node_sourceNotes.txt")
  35.  
  36. #app - kesong
  37. system("cd #{server_appProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}server_app_sourceNotes.txt;cat #{souN
  38. otesPath}server_app_sourceNotes.txt")
  39. #forward -zhongxing
  40. system("cd #{server_forwardProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}server_forward_sourceNotes.txt;ca
  41. t #{souNotesPath}server_forward_sourceNotes.txt")
  42.  
  43. puts "get web git log"
  44. #获取web编译日志system("cd #{web_projectPath};pwd;git checkout #{branch};git pull #{branch} #{branch};git status;#{source_releaseNotes} > #{souNotesPath}web_sourceNotes_#{branch}.txt;cat #{souNotesPath}w
  45. eb_sourceNotes_#{branch}.txt")
  46. system("cd #{webStatic_projectPath};pwd;git checkout #{branch};git pull #{branch} #{branch};git status;#{source_releaseNotes} > #{souNotesPath}webStatic_sourceNotes_#{branch}.txt;cat #{souN
  47. otesPath}webStatic_sourceNotes_#{branch}.txt")
  48. system("cd #{webServer_projectPath};pwd;git checkout #{branch};git pull #{branch} #{branch};git status;#{source_releaseNotes} > #{souNotesPath}webServer_sourceNotes_#{branch}.txt;cat #{souN
  49. otesPath}webServer_sourceNotes_#{branch}.txt")
  50.  
  51. #规整输出日志
  52. currTime = Time.now.strftime("%Y-%m-%d %H:%M")
  53. puts "build time:#{currTime}"
  54. file = File.open('releaseNotes.txt',"w+")
  55. file.puts "build time:#{currTime}"
  56. filter1 = 'gitlab-ci.yml'
  57. filter2 = 'Merge branch'
  58. filter3 = 'xxxxxhui'
  59.  
  60. File.readlines('sdk_sourceNotes.txt').each do |line|
  61. file.puts " 【sdk】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  62. end
  63. File.readlines('sdk_CLsourceNotes.txt').each do |line|
  64. file.puts " 【sdk】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  65. end
  66. File.readlines('server_node_sourceNotes.txt').each do |line|
  67. file.puts " 【server】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  68. end
  69. File.readlines('server_app_sourceNotes.txt').each do |line|
  70. file.puts " 【server】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  71. end
  72. File.readlines('server_forward_sourceNotes.txt').each do |line|
  73. file.puts " 【server】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  74. end
  75. File.readlines("webStatic_sourceNotes_#{branch.sub('"','').sub('"','')}.txt").each do |line|
  76. file.puts " 【web】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  77. end
  78. File.readlines("webServer_sourceNotes_#{branch.sub('"','').sub('"','')}.txt").each do |line|
  79. file.puts " 【web】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3)
  80. end
  81. file.close
  82. puts "format releaseNotes done ............."
  83. system("pwd;cat #{souNotesPath}releaseNotes.txt;du -sh *")

release notes消息可以查看上一遍:ruby发送邮件 http://www.cnblogs.com/fithon/p/6644294.html

执行过程如下:

  1. build time:2017-03-28 14:42
    last built time:2017-03-28 14:42
    get git log
    get sdk git log
    /home/devProject/sdk/sense-crowd
    Already on 'v2.3.0'
    From http://gitlab.sensenets.com/yyansheng/sense-crowd
    * branch v2.3.0 -> FETCH_HEAD
    Already up-to-date.
    # On branch v2.3.0
    nothing to commit, working directory clean
    /home/devProject/sdk/crossline
    Already on 'v1.0.0'
    Your branch is ahead of 'v1.0.0/v1.0.0' by 12 commits.
    (use "git push" to publish your local commits)
    From http://gitlab.sensenets.com/wuyuchun/crossline
    * branch v1.0.0 -> FETCH_HEAD
    Already up-to-date.
    # On branch v1.0.0
    # Your branch is ahead of 'v1.0.0/v1.0.0' by 12 commits.
    # (use "git push" to publish your local commits)
    #
    nothing to commit, working directory clean
    get server git log
    /home/devProject/server/Crowd2.1-node
    Already on 'v2.3.0'
    From http://gitlab.sensenets.com/zhangtianshuai/Crowd2.1
    * branch v2.3.0 -> FETCH_HEAD
    Already up-to-date.
    # On branch v2.3.0
    nothing to commit, working directory clean
    /home/devProject/server/CrowdAnalyze-app
    Already on 'v2.3.0'
    From http://gitlab.sensenets.com/zhangkesong/CrowdAnalyze
    * branch v2.3.0 -> FETCH_HEAD
    Already up-to-date.
    # On branch v2.3.0
    nothing to commit, working directory clean
    /home/devProject/server/VideoForward
    Already on 'v2.3.0'
    From http://gitlab.sensenets.com/jiangzhongxing/VideoForward
    * branch v2.3.0 -> FETCH_HEAD
    Already up-to-date.
    # On branch v2.3.0
    nothing to commit, working directory clean
    get web git log
    /home/devProject/web/crowd-web-static
    Already on 'v2.4.0'
    Your branch is ahead of 'v2.4.0/v2.4.0' by 16 commits.
    (use "git push" to publish your local commits)
    From http://gitlab.sensenets.com/panlong/crowd-web-static
    * branch v2.4.0 -> FETCH_HEAD
    Updating 5d64ce1..892f2b0
    Fast-forward
    .project | 17 ++
    module/ocx/PlayVideoTool.js | 1 -
    module/ocx/VideoOcxTool.js | 1 -
    module/statistic/statistic.main.js | 17 +-
    module/statistic/statistic.status.js | 341 +++++++++++++++++++++-
    template/statistic/stat-status-by-minute-tpl.html | 8 +
    template/statistic/statistic-main.html | 1 +
    7 files changed, 374 insertions(+), 12 deletions(-)
    # On branch v2.4.0
    # Your branch is ahead of 'v2.4.0/v2.4.0' by 18 commits.
    # (use "git push" to publish your local commits)
    #
    nothing to commit, working directory clean
    xxxxnpan | Thu Mar 30 15:10:04 2017 +0800 | 进出人数统计导出
    xxxxnpan | Thu Mar 30 09:54:35 2017 +0800 | 进出计数统计代码提交/home/devProject/web/crowd-web-server
    Already on 'v2.4.0'
    From http://gitlab.sensenets.com/panlong/crowd-web-server
    * branch v2.4.0 -> FETCH_HEAD
    Already up-to-date.
    # On branch v2.4.0
    nothing to commit, working directory clean
    build time:2017-03-31 10:06
    format releaseNotes done .............
    /home/shench/script/releaseNotes
    build time:2017-03-31 10:06
    webpan | Thu Mar 30 15:10:04 2017 +0800 | 进出人数统计导出
    webpan | Thu Mar 30 09:54:35 2017 +0800 | 进出计数统计代码提交
    4.0K getReleaseNotes_v2.3.0.rb
    8.0K getReleaseNotes_v2.4.0.rb
    4.0K releaseNotes.txt
    0 sdk_CLsourceNotes.txt
    0 sdk_sourceNotes.txt
    0 server_app_sourceNotes.txt
    0 server_forward_sourceNotes.txt
    0 server_node_sourceNotes.txt
    0 webServer_sourceNotes_v2.4.0.txt
    4.0K webStatic_sourceNotes_v2.4.0.txt

ruby 规整git commit 信息的更多相关文章

  1. 修改已经提交到远端的git commit信息

    有这么一种场景,就是以前没有设置用户名和邮箱,导致提交时git commit信息中用户信息不正确.这样的情况导致后来我们提交代码到git上面时因为身份验证错误,只有到 push 阶段了才发现提交不上去 ...

  2. Git commit 信息标准和丢弃必须要的commit

    /***************************************************************************** * Git commit 信息标准和丢弃必 ...

  3. 给程序添加git commit信息

    遇到了一个客户程序出问题,自己这边始终无法重现的bug.为了检查问题,查到了一个添加git的commit信息到程序中的方法,感觉对程序版本控制十分好用. 一,项目中添加如下文件 文件结构: GitVe ...

  4. 如何写好git commit message

    1.触发事件 我有这样一个版本库,里面包含两个学习用的练习项目:BookStore(以下简称BS)和PictureFriend(以下简称PF) 我在更改PF以后,未进行提交,同时又到BS中优化了一下文 ...

  5. git commit的规范

    https://www.yuque.com/fe9/basic/nruxq8#6c228def 制定一个 git commit 信息的提交规范是开发团队工作流必不可少的环节.试想一下,如果查看主分支上 ...

  6. git commit 、CHANGELOG 和版本发布的标准自动化

    一直以来,因为团队项目迭代节奏很快,每次发布的更新日志和版本更新都是通过人肉来完成的.有时候实在忙的团团转,对于手动的写这些更新信息就显得力不从心了.对于团队新来的小伙伴,有时候遇到些紧急情况,就更显 ...

  7. 自家公司关于git commit 的规范

    代码提交的commit info提个建议,fix的issue是哪个issue?都要有明确的链接.推荐方式:1.建立issue,说明问题的背景和原因.http://git.startdt.net/pay ...

  8. git 修改commit信息

    可以使用 git commit --amend 修改上一次的提交信息. 操作示例 如下: git commit --amend 后会出现编辑界面,如下 可以在最上面红框的地方,修改要提交的信息,然后按 ...

  9. git修改已push的commit信息

    本条适用于修改已push的最新的commit信息,确保本地的文件是最新的. 使用 git commit --amend 命令,(修改最近一次提交的注释信息),会进入到vim 编辑器 编辑提交信息,保存 ...

随机推荐

  1. 在编辑Spring的配置文件时的自动提示

    打 开MyEclipse—>Windows--->referenecs——>General,选择下面的Keys,这就是快捷键的设 置,可将Content Assist的快捷键改为 A ...

  2. python_57_高阶函数

    变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数. def add(a,b,f): return f(a)+f(b) res=add(-3,- ...

  3. Unity的sendmessage用法

    刚学完sendmessage用法,自己也尝试测试了一下,用法如下: 1.在unity2017新建一个场景test 2.在场景中添加一个立方体cube作为主角,另添加一个胶囊体capsule,调整为如图 ...

  4. C# 多态与new关键字

    1. 你通常怎样用多态? 假设我有一个类,里面有一个 PrintStatus 方法,用于打印实例的当前状态,我希望该类的派生类都带有一个 PrintStatus 方法,并且这些方法都用于打印其实例的当 ...

  5. WebAppBuilder独立于portal之arcgis for js应用框架研究之二

    WAB采用ArcGIS JavaScript for API作为地图开发底层,采用Web AppBuilder作为开发框架,利用该框架即拿即用的Widget来构建应用,比如制图.查询.地理处理.编辑. ...

  6. grep与正则表达式使用

    grep简介 grep 是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.通常grep有三种版本grep.egrep(等同于grep -E)和fgrep.egrep为扩展的g ...

  7. PHP array_multisort()函数超详细理解

    项目中用到这个函数了 ,起初对这个函数一直是懵逼状态,文档都看的朦朦胧胧的 网上无意间看到这篇文章 ,写的超级详细,收藏了 . 当然要先放原地址:https://www.cnblogs.com/WuN ...

  8. 数据结构-二叉树(Binary Tree)

    #include <stdio.h> #include <string.h> #include <stdlib.h> #define LIST_INIT_SIZE ...

  9. 嵌入式Linux环境搭建备忘

    嵌入式Linux开发平台搭建步骤: 1.安装宿主机Linux系统 如果选用最新的Linux发行版,应改主意其他软件是否能很好的兼容. 2.安装交叉编译器 交叉编译器的版本很多,一般到芯片厂家官网下载官 ...

  10. 容斥原理:HDU-4135Co-prime

    容斥原理公式:这里就需要用到容斥原理了,公式就是:n/2+n/3+n/5-n/(2*3)-n/(2*5)-n/(3*5)+n/(2*3*5). 求的是多个重合区间的里面的数字个数. 解题心得: 1.一 ...