当前位置:网站首页>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()
边栏推荐
- Dynamic memory development
- JVM Foundation
- Inventory of well-known source code mall systems at home and abroad
- Promise basic use
- Data governance notes
- The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree
- [hero planet July training leetcode problem solving daily] 20th BST
- SAP Spartacus - progressive web applications, progressive web applications
- [C + + primer notes] Chapter 6 functions
- Login and payment arrangement in uniapp
猜你喜欢

Jsonp solves cross domain plug-ins (JS, TS)

Pychart exits pytest mode (run pytest in mode)

The IPO of Tuba rabbit was terminated: the annual profit fell by 33%, and Jingwei Sequoia was the shareholder

The solution of displaying garbled code in SecureCRT

Kubernetes creates a user with dashboard read-only permission (with exec permission)

Specificity and five applications of Worthington alcohol dehydrogenase

Speed comparison between 64 bit width and 32 bit width of arm64 memory

Academicians said: researchers should also support their families. They can only do short-term and fast research if they are not promoted

Service address dynamic awareness of Nacos registry

Hbuilderx developed by uni app connects to night God simulator
随机推荐
Top priority of dry goods: common indicators and terms in data analysis!
DotNetCore. Cap notes
The cloud ecology conference comes with the "peak"!
Cloud native platform, let edge applications play out!
Green low-carbon Tianyi cloud, a new engine of digital economy!
Custom type
iptables :chains, target
Opengauss kernel analysis: query rewriting
Rightmost × Microframe, high quality heif image coding and compression technology
Musk responded whether he would upload his brain to the cloud: already did it!
Ireport export PDF font bold failure
On let variable promotion
EasyX realizes button effect
VC hesitates to invest in Henan
Promise basic use
PG Optimization -- execution plan
Take C language from 0 to 1 - program structure and use examples
Common functional interfaces_ Predicate interface_ Default method and and predicate interface exercise_ Set interface filtering
Three possible scenarios for SAP Spartacus server-side rendering
Upgrade the leapfrog products again, and the 2023 Geely Xingrui will be sold from 113700 yuan