当前位置:网站首页>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()
边栏推荐
- Leetcode - number of palindromes
- Start to build a three node Eureka cluster
- Custom type
- Document the use of anti shake in packaged components and projects
- [hero planet July training leetcode problem solving daily] 20th BST
- [linear DP] Digital triangle
- Google Earth engine - 1980 present global pressure, temperature, wind and other data sets
- Grpc sets connection lifetime and server health check
- PG Optimization -- execution plan
- If in ython__ name__ == ‘__ main__‘: Function and principle of
猜你喜欢
![[25. Hash table]](/img/c4/1500d070d44d3bd84eb141ed38013d.png)
[25. Hash table]

Fraud detection using CSP

Rightmost × Microframe, high quality heif image coding and compression technology

Boutique solution | Haitai cloud password application service solution to create secure and compliant Cloud Applications

Leetcode - number of palindromes

2022.7.20 linear table

How to empty localstorage before closing a page

DotNetCore. Cap notes

Take the first place in the International Olympic Games in mathematics, physics and chemistry, and win all the gold medals. Netizen: the Chinese team is too good

Antdb database products were selected into the global database industry map (2022) of the China Academy of communications and communications
随机推荐
Dynamic memory development
Take the first place in the International Olympic Games in mathematics, physics and chemistry, and win all the gold medals. Netizen: the Chinese team is too good
Mongodb security cluster construction
How to use ES6 async and await (basic)
Jsonp solves cross domain plug-ins (JS, TS)
Deamnet|filenotfounderror: [winerror 3] the system cannot find the specified path.: '/ Datasettest\\Set12‘
Beijing Zhun electric clock, Beidou clock server, GPS network time server, NTP satellite timing system
Completefuture parallel asynchronous return processing
Scientific data center resources and user access control system
Service address dynamic awareness of Nacos registry
Download files and web pages with WGet
How to empty localstorage before closing a page
[26. String hash]
[programmer interview classic] 01.09 string rotation
[leetcode] 3. Longest substring without repeated characters - go language problem solution
Resolution of multi thread conflict lock
Login and payment arrangement in uniapp
Interpretation of video generation paper of fed shot video to video (neurips 2019)
Introduction to ORM framework - what is ORM framework?
MySQL Basics (concepts, common instructions)