当前位置:网站首页>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()
边栏推荐
- How to use ES6 async and await (basic)
- [25. Hash table]
- MySQL series | log module
- Musk responded whether he would upload his brain to the cloud: already did it!
- JVM Foundation
- Visual studio code installation package download slow & Installation & environment configuration & new one-stop explanation
- What is iftmcs indicating contract status message?
- Mongodb security cluster construction
- G025-db-gs-ins-02 openeuler deployment opengauss (1 active and 1 standby)
- When does MySQL use table locks and row locks?
猜你喜欢

Prosci anti-CD22 antibody epratuzum28 flow cytometry display

The most complete summary of MySQL data types in history - (first)

Talk about resume optimization and interview skills of algorithm post!

Thinkphp5.0.24 deserialization chain analysis
![[development tutorial 10] crazy shell · open source Bluetooth smart health watch OTA image production and download technical documents](/img/97/c4ef281ca14eb68c8a14f18e03c3dd.png)
[development tutorial 10] crazy shell · open source Bluetooth smart health watch OTA image production and download technical documents

How to use ES6 async and await (basic)

Amd epyc 9654 Genoa CPU cache test exposure L1 bandwidth up to 30tb/s

Promise basic use
![[25. Hash table]](/img/c4/1500d070d44d3bd84eb141ed38013d.png)
[25. Hash table]

Take C language from 0 to 1 - program structure and use examples
随机推荐
Plug ins QRcode and ityped
Record the bugs encountered and some work experience
[leetcode] 2. Add two numbers - go language problem solving
[summer daily question] output of Luogu p1157 combination
Opengauss kernel analysis: query rewriting
G025-db-gs-ins-02 openeuler deployment opengauss (1 active and 1 standby)
Ecosystem long-term observation data product system
Antdb database products were selected into the global database industry map (2022) of the China Academy of communications and communications
Upgrade the leapfrog products again, and the 2023 Geely Xingrui will be sold from 113700 yuan
POM reports an error
Some of my understanding about anti shake and throttling
Scientific data center resources and user access control system
[summer daily question] Luogu p1706 full ranking question
Prosci anti-CD22 antibody epratuzum28 flow cytometry display
How to obtain workers' coats and helmets in stray? How to obtain workers' helmets
How to empty localstorage before closing a page
Which bank outlet in Zhejiang can buy REITs fund products?
[hero planet July training leetcode problem solving daily] 20th BST
Google Earth engine - 1980 present global pressure, temperature, wind and other data sets
Green low-carbon Tianyi cloud, a new engine of digital economy!