Last active
September 26, 2022 05:38
-
-
Save drugoi/9f0523c13c399cb1e604cc1495108900 to your computer and use it in GitHub Desktop.
Collect scope from commitlint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# before: git log --pretty=format:%s | grep -E '^(\w+)\((\w+|\*)\)' > commits.log | |
def logFileToList(logFilename): | |
resList = [] | |
with open(logFilename) as f: | |
for s in f: | |
resList.append(s) | |
return resList | |
def logListToDic(logFileList): | |
dic = {} | |
for s in logFileList: | |
key = s[s.find("(")+1:s.find(")")] | |
value = s[s.find(":"):].strip() | |
if key not in dic: | |
dic[key] = set() | |
dic[key].add(value) | |
return dic | |
def exportToCsv(outPutFileName,logFileDic): | |
logFileValueCountDic = {} | |
for k, v in logFileDic.items(): | |
logFileValueCountDic[k] = len(v) | |
with open(outPutFileName, 'w') as csv_file: | |
writer = csv.writer(csv_file) | |
writer.writerow(["scope", "count"]) | |
for key, value in logFileValueCountDic.items(): | |
writer.writerow([key, value]) | |
def exportLogsCountToCsv(logFilename,outPutFileName): | |
exportToCsv(outPutFileName,logListToDic(logFileToList(logFilename))) | |
if __name__ == "__main__": | |
#light checks | |
inputLogList = ['feat(scope1): blabla\n', 'feat(scope2): blabla\n', 'feat(scope3): blabla\n', 'feat(scope1): blabla\n', 'fix(scope2): blabla\n', 'fix(scope3): blabla\n', 'feat(scope1): blabla\n', 'feat(scope2): blabla\n', 'feat(scope3): blabla'] | |
expectedLogDic = {'scope1': {': blabla'}, 'scope2': {': blabla'}, 'scope3': {': blabla'}} | |
assert logListToDic(inputLogList) == expectedLogDic | |
#main export | |
exportLogsCountToCsv('commits.log','dict.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment