继上一篇JSON保存git log历史记录里subject带有特殊字符的转义的处理,获得的git.json文件进行逐一分析处理,对比两个分支之间的实际差异,并将差异部分发送给对应的author
dir('gitrepo') {
jsonData = readJSON file: 'git.json'
println jsonData
env.git_log = ""
env.emailReceiption = ""
jsonData.each{
env.commit = it.commit
subj1 = it.subject
if(subj1.contains("[") || subj1.contains("]")){
subj1 = subj1.replaceAll('\\[','\\\\[') #对[进行转义
subj1 = subj1.replaceAll('\\]','\\\\]') #对]进行转义
}
if(subj1.contains("(") || subj1.contains(")")){
subj1 = subj1.replaceAll('\\(','\\\\(') #对(进行转义
subj1 = subj1.replaceAll('\\)','\\\\)') #对)进行转义
}
env.subject = subj1
env.author = it.author
println "hello $subject"
if(subj1.contains("cherry-pick")){ #判断带有“cherry-pick”字样的,同时母commit一致,代表两个分支都存在不是DIFF部分
cherryCommit = subj1.split('-')[-1]
newCRCommit = cherryCommit.split(' ')[0]
env.anCommit = newCRCommit.substring(0, newCRCommit.length() - 1)
String masterHas = shResult(
'''
git show --pretty=tformat:%h $anCommit
'''
)
println "masterHas is $masterHas"
if (masterHas != "") {
println "$subj1 should remove, now remove from jsonData"
} else {
println "$subj1 should remain"
env.git_log = env.git_log + """
<tr>
<td>$it.commit</td>
<td>$it.subject</td>
<td>$it.author</td>
<td>$it.email</td>
<td>$it.date</td>
</tr>
"""
if (!emailReceiption.contains(it.email) && it.email != "dementor@qiyi.com") {
env.emailReceiption = env.emailReceiption + ";" + it.email
}
}
} else {
String result = shResult(
'''
git log --pretty=tformat:%h --grep="cherry-pick-${commit%?}" master ^"${compareBranch}"
'''
)
println "result is $result"
if (result != "") {
println "$subj1 should remove, now remove from jsonData"
} else {
println "$subj1 should remain"
env.git_log = env.git_log + """
<tr>
<td>$it.commit</td>
<td>$it.subject</td>
<td>$it.author</td>
<td>$it.email</td>
<td>$it.date</td>
</tr>
"""
if (!emailReceiption.contains(it.email) && it.email != "dementor@qiyi.com" && it.email != "pangwenyu@qiyi.com") {
env.emailReceiption = env.emailReceiption + ";" + it.email
}
}
}
}
println emailReceiption
}