Python3统计gitlab上的代码量
import threading
import gitlab
import xlwt #获取所有的user
def getAllUsers():
usersli = []
client = gitlab.Gitlab(private_host, private_token=private_token)
users = client.users.list(all=True)
for user in users:
usersli.append(user.username)
return usersli #获取所有的project
def getAllProjects():
client = gitlab.Gitlab(private_host, private_token=private_token)
projects = client.projects.list(all=True)
return projects #获取project下所有的branche
def getAllBranchByProject(project):
try:
branches = project.branches.list()
return branches
except:
return "" #获取project和branch下的commit
def getCommitByBranch(project, branch):
author_commits = []
commits = project.commits.list(all=True, ref_name=branch.name)
for commit in commits:
committer_email = commit.committer_email
title = commit.title
message = commit.message
#if ('Merge' in message) or ('Merge' in title):
# print('Merge跳过')
# continue
#else:
author_commits.append(commit)
return author_commits #获取project项目下commit对应的code
def getCodeByCommit(commit, project):
commit_info = project.commits.get(commit.id)
code = commit_info.stats
return code def getAuthorCode(project,fenzhi):
# print("project:%s" % project)
users = getAllUsers()
branches = getAllBranchByProject(project)
if branches == "":
pass
else:
for branch in branches:
# print("branch#####",branch.name)
if branch.name == fenzhi:
#print("branch:%s" % branch)
#print('获取工程', project.name, '分支', branch.name, "的提交记录")
branchdata = {}
branchdata['group'] = project.name_with_namespace.split("/")[0]
branchdata['projectname'] = project.name
branchdata['branchename'] = branch.name
author_commits = getCommitByBranch(project, branch)
# print(author_commits)
codes = []
res1 = []
for commit in author_commits:
#print('获取提交', commit.id, "的代码量")
code = getCodeByCommit(commit, project)
# print(commit,code)
# print(code)
# print(commit)
# print(commit.committer_name)
codes.append(code)
# for user in users:
# if commit.committer_name == user:
# res1.append(commit)
record = calculate(codes)
branchdata['commitcount'] = len(author_commits)
branchdata['codecount'] = record
data.append(branchdata)
# print(codes)
# print(calculate(codes))
# print(data)
# for res in res1:
# print(res)
return data #写入execl
def writeExcel(excelPath, data):
workbook = xlwt.Workbook()
# 获取第一个sheet页
sheet = workbook.add_sheet('git')
row0 = ['项目组', '工程名称', '分支名称', '提交次数', '新增代码', '删除代码', '总计代码']
for i in range(0, len(row0)):
sheet.write(0, i, row0[i])
addcount = 0
delcount = 0
totalcount = 0
commitcount = 0
for i in range(0, len(data)):
recode = data[i]
j = 0
sheet.write(i + 1, j, recode['group'])
sheet.write(i + 1, j + 1, recode['projectname'])
sheet.write(i + 1, j + 2, recode['branchename'])
commitcount += (int)(recode['commitcount'])
sheet.write(i + 1, j + 3, recode['commitcount'])
addcount += (int)(recode['codecount']['additions'])
sheet.write(i + 1, j + 4, recode['codecount']['additions'])
delcount += (int)(recode['codecount']['deletions'])
sheet.write(i + 1, j + 5, recode['codecount']['deletions'])
totalcount += (int)(recode['codecount']['total'])
sheet.write(i + 1, j + 6, recode['codecount']['total']) sheet.write(len(data) + 1, 3, commitcount)
sheet.write(len(data) + 1, 4, addcount)
sheet.write(len(data) + 1, 5, delcount)
sheet.write(len(data) + 1, 6, totalcount)
workbook.save(excelPath) def calculate(data):
record = {}
addacount = 0
deletecount = 0
totaolcount = 0
for i in data:
# print(i)
addacount += int(i['additions'])
deletecount += int(i['deletions'])
totaolcount += int(i['total'])
record['additions'] = addacount
record['deletions'] = deletecount
record['total'] = totaolcount
return record if __name__ == '__main__':
# 用户git账户的token 6S7jy689FeCrP5w_UwgZ
private_token = 'T3Nz2xCxq4FcVQ4wytr1' #gitlab用户tonken
# git地址
private_host = 'http://10.0.0.1:8888/' #gitlab地址 data = []
thread_list = []
projects = getAllProjects()
# print(projects) for i in projects:
branches = getAllBranchByProject(i)
for j in branches:
t = threading.Thread(target=getAuthorCode, args=(i,j.name))
thread_list.append(t) for threadname in thread_list: threadname.start()
for threadname in thread_list: threadname.join()
# print(data)
writeExcel('d:/code_count.xls', data)
来源:https://blog.csdn.net/sinat_25318461/article/details/103489793
Python3统计gitlab上的代码量的更多相关文章
- git统计项目中成员代码量
查看git上个人代码量 git log --author="username" --pretty=tformat: --numstat | awk '{ add += $1; su ...
- [chrome插件分享] gitlab-tree 更方便的浏览Gitlab上的代码
说明 经常玩Github的人肯定都知道大名鼎鼎的octotree吧,这款chrome插件可以说是浏览代码的神器,利用左侧的树形菜单可以很方便的打开目录.浏览文件等,加上Github全站本身使用了pja ...
- jenkins如何获取gitlab上的代码
如何安装jenkins和gitlab我就不重复了,请自行搜索我的博客 那么,jenkins如何获取gitlab上的代码呢? 具体配置步骤如下 1.在gitlab上配置个人访问令牌.注意事项:姓名那里需 ...
- Git拉取Gitlab上的代码时,报128的解决方法
今天拉取gitlab上的代码时出现错误,一直返回128 首先我们确定我们在存储库上有没有权限,然后我就去项目中的 Members上看是否有权限,然后发现也是有的. 然后克隆的时候发现输入一万遍密码都还 ...
- (转)通过gitlab统计git提交的代码量
git的代码量大多数都是根据命令行统计,或者根据第三方插件统计.但是都不满足我的需求,因为我们代码都由gitlab管理,于是想到了通过gitlab暴露出来的接口获取数据. 第一步,生成私钥 登录你的g ...
- gitlab上传代码及报错总结
将目录变成git可管理的仓库 git init 将文件添加到暂存区中 git add README.md 将文件提交到仓库 git commit -m "fisrt commit" ...
- 将GitLab上面的代码克隆到本地
1.安装GitLab客户端 2.去GitLab服务端找项目路径 3.去GitLab客户端去克隆代码 右键-->git Clone 4.最后结果
- gitlab 上传代码
#生成公钥ssh-keygen -t ed25519 -C "xxx@tianwang.com"#拷贝公钥pbcopy < ~/.ssh/id_ed25519.pub 在网页 ...
- windows调起git bash执行sh脚本定时统计git仓库代码量
本来挺简单的一个东西硬是弄了两天 心力交瘁 找了网上不少资料 整理一下发给大家 首先是统计每个人的代码量的git命令 在网上找的 我这里做了以下修改 git log --format='%aN'|so ...
随机推荐
- 呵呵,Semaphore,就这?
这是并发线程工具类的第二篇文章,在第一篇中,我们分析过 CountDownLatch 的相关内容,你可以参考 一文搞懂 CountDownLatch 用法和源码! 那么本篇文章我们继续来和你聊聊并发工 ...
- html5 video/audio 标签
一般来说推荐使用,第三方的媒体播放库[例如 videojs 等],这些库的ui界面,js控制都已写好,功能也扩展的比较丰富 ,直接参考文档使用更加的高效! 这里还是 记录一下 html 原生 vide ...
- c++ 实现向量去重操作
去重的时候要考虑线性表或链表是否是有序 1.1.无序线性表 对于向量[1,5,3,7,2,4,7,3], 从头开始扫描vector内的元素, 对于表中r处的元素a[r], 检查数组0至r-1区间内是否 ...
- 迷宫问题(BFS)
给定一个n* m大小的迷宫,其中* 代表不可通过的墙壁,而"."代表平地,S表示起点,T代表终点.移动过程中,如果当前位置是(x, y)(下标从0开始),且每次只能前往上下左右.( ...
- 亮相 LiveVideoStackCon,透析阿里云窄带高清的现在与未来
2021.4.16-4.17,阿里云视频云亮相 LiveVideoStackCon 音视频技术大会上海站,带来三场不同视角的主题演讲,并与众多行业伙伴一同交流.在 "编解码的新挑战与新机会& ...
- prometheus入门介绍及相关组件、原理讲解
1:介绍 Prometheus 是由 SoundCloud 开源监控告警解决方案. prometheus是由谷歌研发的一款开源的监控软件,目前已经被云计算本地基金会托管,是继k8s托管的第二个项目. ...
- matlab帮助文档
matlab的纯文本帮助命令有多种,help.lookfor.which.doc.get.type等 help命令 help命令用来查询一个函数的使用方式. help fun %fun是函数名称 ...
- 重绘DevExpress的XtraMessageBox消息提示框控件
先来看提示框,可以看到框其实是一个去掉最大化.最小化按钮后的窗体,窗体的内容就是我们想要提示的内容,重绘提示框其实就是重绘窗体以及中间部分的内容. 首先重绘窗体,消息提示框的窗体不是XtraForm而 ...
- Ionic5手写签名SignaturePad
测试程序下载:https://hanzhe.lanzous.com/itt47kncw3a 初始化项目 1. 首先新建一个Ionic5的项目: ionic start test-1 blank 2. ...
- Python 并行计算那点事 -- 译文 [原创]
Python 并行计算的那点事1(The Python Concurrency Story) 英文原文:https://powerfulpython.com/blog/python-concurren ...