實現過程:html
[root@localhost crowd-web-server]# git log --pretty=format:'%an | %cd | %s' --after='2017-03-5 14:42'node
該命令爲:只獲取2017年3月5號之後的git log。而且只返回 提交人、提交時間、提交信息3個字段內容git
二、過濾掉一些CI提交內容的log,輸出時,在最前面加入模塊信息如:【sdk】【web】web
filter1 = 'gitlab-ci.yml' filter2 = 'Merge branch' filter3 = 'xxxxxxhui' File.readlines('sdk_sourceNotes.txt').each do |line| file.puts " 【sdk】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end
三、最後將過濾好的內容寫入一個文本便可。如下爲完整腳本ruby
souNotesPath = '/home/shench/script/releaseNotes/' sdk_ProjectPath = '/home/devProject/sdk/sense-crowd' sdk_crossline = '/home/devProject/sdk/crossline' server_nodeProjectPath = '/home/devProject/server/Crowd2.1-node' server_appProjectPath = '/home/devProject/server/CrowdAnalyze-app' server_forwardProjectPath = '/home/devProject/server/VideoForward' webStatic_projectPath = '/home/devProject/web/crowd-web-static' webServer_projectPath = '/home/devProject/web/crowd-web-server' branch = ARGV[0].to_s.sub('[','').sub(']','') ciBranch = ARGV[1].to_s.sub('[','').sub(']','') devBranch = 'v2.3.0' sdk_CL_branch = 'v1.0.0' system("cd /home/CrowdProduct;git checkout #{branch};git status;git pull #{branch} #{branch};cat releaseNotes.txt") #獲取上次編譯時間 File.readlines('/home/CrowdProduct/releaseNotes.txt').each do |line| @lastBuilt = line.sub('build time:','') if line=~/build/ end puts "last built time:#{@lastBuilt}" puts "get git log" source_releaseNotes = "git log --pretty=format:'%an | %cd | %s' --after=#{@lastBuilt.chomp.inspect}" # puts source_releaseNotes puts "get sdk git log" #獲取sdk編譯日誌 system("cd #{sdk_ProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}sdk_sourceNotes.txt") 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") puts "get server git log" #獲取server編譯日誌 #node -tianshuai system("cd #{server_nodeProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}server_node_sourceNotes.txt;cat #{so uNotesPath}server_node_sourceNotes.txt") #app - kesong system("cd #{server_appProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}server_app_sourceNotes.txt;cat #{souN otesPath}server_app_sourceNotes.txt") #forward -zhongxing system("cd #{server_forwardProjectPath};pwd;git checkout #{devBranch};git pull #{devBranch} #{devBranch};git status;#{source_releaseNotes} > #{souNotesPath}server_forward_sourceNotes.txt;ca t #{souNotesPath}server_forward_sourceNotes.txt") puts "get web git log" #獲取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 eb_sourceNotes_#{branch}.txt") system("cd #{webStatic_projectPath};pwd;git checkout #{branch};git pull #{branch} #{branch};git status;#{source_releaseNotes} > #{souNotesPath}webStatic_sourceNotes_#{branch}.txt;cat #{souN otesPath}webStatic_sourceNotes_#{branch}.txt") system("cd #{webServer_projectPath};pwd;git checkout #{branch};git pull #{branch} #{branch};git status;#{source_releaseNotes} > #{souNotesPath}webServer_sourceNotes_#{branch}.txt;cat #{souN otesPath}webServer_sourceNotes_#{branch}.txt") #規整輸出日誌 currTime = Time.now.strftime("%Y-%m-%d %H:%M") puts "build time:#{currTime}" file = File.open('releaseNotes.txt',"w+") file.puts "build time:#{currTime}" filter1 = 'gitlab-ci.yml' filter2 = 'Merge branch' filter3 = 'xxxxxhui' File.readlines('sdk_sourceNotes.txt').each do |line| file.puts " 【sdk】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end File.readlines('sdk_CLsourceNotes.txt').each do |line| file.puts " 【sdk】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end File.readlines('server_node_sourceNotes.txt').each do |line| file.puts " 【server】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end File.readlines('server_app_sourceNotes.txt').each do |line| file.puts " 【server】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end File.readlines('server_forward_sourceNotes.txt').each do |line| file.puts " 【server】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end File.readlines("webStatic_sourceNotes_#{branch.sub('"','').sub('"','')}.txt").each do |line| file.puts " 【web】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end File.readlines("webServer_sourceNotes_#{branch.sub('"','').sub('"','')}.txt").each do |line| file.puts " 【web】"+line if !line.include?(filter1) and !line.include?(filter2) and !line.include?(filter3) end file.close puts "format releaseNotes done ............." system("pwd;cat #{souNotesPath}releaseNotes.txt;du -sh *")
release notes消息能夠查看上一遍:ruby發送郵件 http://www.cnblogs.com/fithon/p/6644294.htmlapp
執行過程以下:ide
build time:2017-03-28 14:42last built time:2017-03-28 14:42get git logget sdk git log/home/devProject/sdk/sense-crowdAlready on 'v2.3.0'From http://gitlab.sensenets.com/yyansheng/sense-crowd * branch v2.3.0 -> FETCH_HEADAlready up-to-date.# On branch v2.3.0nothing to commit, working directory clean/home/devProject/sdk/crosslineAlready 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_HEADAlready 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 cleanget server git log/home/devProject/server/Crowd2.1-nodeAlready on 'v2.3.0'From http://gitlab.sensenets.com/zhangtianshuai/Crowd2.1 * branch v2.3.0 -> FETCH_HEADAlready up-to-date.# On branch v2.3.0nothing to commit, working directory clean/home/devProject/server/CrowdAnalyze-appAlready on 'v2.3.0'From http://gitlab.sensenets.com/zhangkesong/CrowdAnalyze * branch v2.3.0 -> FETCH_HEADAlready up-to-date.# On branch v2.3.0nothing to commit, working directory clean/home/devProject/server/VideoForwardAlready on 'v2.3.0'From http://gitlab.sensenets.com/jiangzhongxing/VideoForward * branch v2.3.0 -> FETCH_HEADAlready up-to-date.# On branch v2.3.0nothing to commit, working directory cleanget web git log/home/devProject/web/crowd-web-staticAlready 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_HEADUpdating 5d64ce1..892f2b0Fast-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 cleanxxxxnpan | Thu Mar 30 15:10:04 2017 +0800 | 進出人數統計導出xxxxnpan | Thu Mar 30 09:54:35 2017 +0800 | 進出計數統計代碼提交/home/devProject/web/crowd-web-serverAlready on 'v2.4.0'From http://gitlab.sensenets.com/panlong/crowd-web-server * branch v2.4.0 -> FETCH_HEADAlready up-to-date.# On branch v2.4.0nothing to commit, working directory cleanbuild time:2017-03-31 10:06format releaseNotes done ............./home/shench/script/releaseNotesbuild time:2017-03-31 10:06 【web】pan | Thu Mar 30 15:10:04 2017 +0800 | 進出人數統計導出 【web】pan | Thu Mar 30 09:54:35 2017 +0800 | 進出計數統計代碼提交4.0K getReleaseNotes_v2.3.0.rb8.0K getReleaseNotes_v2.4.0.rb4.0K releaseNotes.txt0 sdk_CLsourceNotes.txt0 sdk_sourceNotes.txt0 server_app_sourceNotes.txt0 server_forward_sourceNotes.txt0 server_node_sourceNotes.txt0 webServer_sourceNotes_v2.4.0.txt4.0K webStatic_sourceNotes_v2.4.0.txt