当前位置:网站首页>Gerrit statistics script
Gerrit statistics script
2022-07-25 01:43:00 【VinterYoung】
gerrit Statistics script
#!/usr/bin/env python3
#coding=utf-8
import sys, json
import time, datetime
import os
import xlwt
import datetime
reload(sys)
sys.setdefaultencoding('utf8')
servers = {
"gerrit.xxx.com",
}
owners = {
"[email protected]",
}
gerritkeys = [
"subject",
"owner.name",
"branch",
"project",
"id",
"owner.email",
"url",
"commitMessage",
]
filter_include_rules = [
["branch", "r/"],
["branch", "R/"],
["branch", "s/"],
["branch", "S/"],
]
filter_in_rules = [
["commitMessage", "MULTI"],
]
filter_non_include_rules = [
]
if time.localtime().tm_wday == 6:
after = datetime.datetime.today() - datetime.timedelta(days=time.localtime().tm_wday + 1)
else:
after = datetime.datetime.today() - datetime.timedelta(days=time.localtime().tm_wday + 8)
before = after + datetime.timedelta(days=7)
#timescale
begin_time = datetime.datetime.today() - datetime.timedelta(days = 7)
begin = str(begin_time.year) + "-" + str(begin_time.month) + "-" + str(begin_time.day)
end_time = datetime.datetime.today()
end = str(end_time.year) + "-" + str(end_time.month) + "-" + str(end_time.day)
file_end = datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
def getGerritToJson():
for s in servers:
print (s)
for o in owners:
print (s)
try:
os.mkdir(".cache");
except:
print ('already created')
os.system('echo "" > .cache/summaryfine.json')
for o in owners:
for s in servers:
#for b in branchs:
cmd = 'ssh ' + s + ' gerrit query --format=JSON --comments --patch-sets' + \
' --submit-records' + \
' after:' + begin +\
' before:' + end + \
' "status:merged' + ' owner:' + o + '"' +\
' >> .cache/summaryfine.json'
print(cmd)
os.system(cmd)
def getNode(node, path, index, length):
n = node[path[index]]
if index == length - 1:
return n
else:
return getNode(n, path, index + 1, length)
AllCommitMessageList=[]
def jsonToexcel():
f = open(r'.cache/summaryfine.json')
jsonfile = []
for l in f.readlines():
try:
dic = json.loads(l, encoding='utf-8')
if dic.has_key('project'):
jsonfile.append(dic)
print ("dic")
except:
print ("fail to decode")
#print (jsonfile)
workbook = xlwt.Workbook()
sheet1 = workbook.add_sheet("multimedia")
for i in range(0, len(gerritkeys)):
print (gerritkeys[i].split('.')[-1])
sheet1.write(0, i, gerritkeys[i])
for i in range(len(gerritkeys),40):
sheet1.write(0, i, "reviewer " + str(i-len(gerritkeys)+1))
print ("len:" + str(len(jsonfile)))
row = 1
for j in range(0,len(jsonfile)):
print ("start")
is_skip = False
# Filter the fields that need to be included
for i in range(0, len(filter_include_rules)):
m = getNode(jsonfile[j], filter_include_rules[i][0].split('.'), 0, len(filter_include_rules[i][0].split('.')))
for k in range(1, len(filter_include_rules[i])):
if filter_include_rules[i][k] not in m:
print ("include:" + filter_include_rules[i][k] + ":" + m)
is_skip = False
if is_skip:
break
if is_skip:
break
if is_skip:
continue
for i in range(0, len(filter_in_rules)):
m = getNode(jsonfile[j], filter_in_rules[i][0].split('.'), 0, len(filter_in_rules[i][0].split('.')))
for k in range(1, len(filter_in_rules[i])):
if filter_in_rules[i][k] not in m:
print ("skip: ----" + m)
is_skip = True
if is_skip:
break
if is_skip:
break
if is_skip:
continue
# Filter fields that do not need to be included
for i in range(0, len(filter_non_include_rules)):
m = getNode(jsonfile[j], filter_non_include_rules[i][0].split('.'), 0, len(filter_non_include_rules[i][0].split('.')))
for k in range(1, len(filter_non_include_rules[i])):
if filter_non_include_rules[i][k] in m:
print ("non-include:" + filter_non_include_rules[i][k] + ":" + m)
is_skip = True
if is_skip:
break
if is_skip:
break
if is_skip:
continue
#for i in range(0, len(gerritkeys)):
# m = getNode(jsonfile[j], gerritkeys[i].split('.'), 0, len(gerritkeys[i].split('.')))
# pass
# Remove commitMessage Common item
if jsonfile[j].has_key('commitMessage'):
noteCommitMessage = jsonfile[j]["commitMessage"].splitlines()[0]
print ("------------message:"+noteCommitMessage)
if noteCommitMessage in AllCommitMessageList:
print(noteCommitMessage + " break")
#row = row + 1
continue
else:
print(noteCommitMessage + " added")
AllCommitMessageList.append(noteCommitMessage)
# Remove commitMessage Common item done
for i in range(0, len(gerritkeys)):
# Press gerritkeys Find value
m = getNode(jsonfile[j], gerritkeys[i].split('.'), 0, len(gerritkeys[i].split('.')))
sheet1.write(row, i, m)
if jsonfile[j].has_key('patchSets'):
line = len(gerritkeys)
for patch in jsonfile[j]["patchSets"]:
if patch.has_key('comments'):
for com in patch['comments']:
if com.has_key('file'):
mess = "reviewer " + com['reviewer']['name'] + " Comment on " + com['file'] + " The first " + str(com['line']) + " That's ok : " + com['message']
else:
mess = "reviewer " + com['reviewer']['name'] + " Comment on " + " : " + com['message']
print (mess)
sheet1.write(row, line, mess)
line = line + 1
row = row + 1
print("save excel")
workbook.save('gerrit-comment-'+ end +'.xls')
getGerritToJson()
jsonToexcel()
边栏推荐
- Management mode of agricultural science data center based on life cycle theory
- Freedom and self action Hegel
- Research 280+ documents! The team of Tsinghua Huang Gao, the winner of CVPR best paper, proposed the first dynamic network overview to comprehensively review the development of dynamic networks!
- From casting sword to defending sword: the way to build the efficiency platform of didi project
- If in ython__ name__ == ‘__ main__‘: Function and principle of
- MySQL Basics (concepts, common instructions)
- Cloud native platform, let edge applications play out!
- The importance of system to Philosophy Hegel
- [FAQ of waiting insurance] can the waiting insurance evaluation organization help with the waiting insurance rectification?
- Interpretation of video generation paper of fed shot video to video (neurips 2019)
猜你喜欢

Service address dynamic awareness of Nacos registry
![[linear DP] Digital triangle](/img/8c/f7392733ef8e13b20c394da8b4c403.png)
[linear DP] Digital triangle

Specificity and five applications of Worthington alcohol dehydrogenase

Fabric. JS centered element

Target segmentation for 10000 frames of video, less than 1.4GB of video memory, open source code | ECCV 2022

VC hesitates to invest in Henan

Inventory of well-known source code mall systems at home and abroad

What is iftmcs indicating contract status message?

What does it operation and maintenance management mean? How to establish an effective IT operation and maintenance management system?

Human cell prosci 4-1BB ligand recombinant protein scheme
随机推荐
Ad active directory and domain network
PG Optimization -- execution plan
Listing of China graphite: the market value is nearly HK $1.2 billion, achieving a zero breakthrough in the listing of Hegang private enterprises
Mongodb security cluster construction
Worthington carboxyl transfer carbonic anhydrase application and literature reference
1260. Two dimensional grid migration: simple construction simulation problem
Web Security Foundation - file upload
Shell judges whether the file exists and whether the file size is 0
Opengauss kernel analysis: query rewriting
How to empty localstorage before closing a page
C traps and defects Chapter 2 lexical "traps" 2.4 switch statements
Some of my understanding about anti shake and throttling
[summer daily question] Luogu P7550 [coci2020-2021 6] bold
Beijing Zhun electric clock, Beidou clock server, GPS network time server, NTP satellite timing system
Open source demo | release of open source example of arcall applet
Login and payment arrangement in uniapp
[leetcode] 2. Add two numbers - go language problem solving
If in ython__ name__ == ‘__ main__‘: Function and principle of
The importance of system to Philosophy Hegel
Thinkphp5.0.24 deserialization chain analysis