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 ...
随机推荐
- django-数据库的增删改查操作
django-数据库的增删改查操作 1.添加用户记录 def login(request): 增加用户记录 使用save()方法来增加记录 username = UserInfo(username=' ...
- 剑指offer二刷(精刷)
剑指 Offer 03. 数组中重复的数字 题目描述 在一个长度为 n 的数组里的所有数字都在 0 到 n-1 的范围内.数组中某些数字是重复的,但不知道有几个数字是重复的,也不知道每个数字重复几次. ...
- Spring Boot 2.3 新特性优雅停机详解
什么是优雅停机 先来一段简单的代码,如下: @RestController public class DemoController { @GetMapping("/demo") p ...
- 设计原则:接口隔离原则(ISP)
接口隔离原则的英文是Interface Segregation Principle,缩写就是ISP.与里氏替换原则一样其定义同样有两种 定义1: Clients should not be force ...
- ES6 第一天
study in bilibili: es6视频教程(无废话版) 关键字: let 代码块内起作用,不会代码提升 const 常量 ES6结构赋值 作用:解析解构,然后自动赋值,简化程序员代码编写: ...
- C语言-内存函数的实现(一)之memcpy
C语言中的内存函数有如下这些 memcpy memmove memcmp memset 下面看看memcpy函数 memcpy 我们想想,之前有那个字符串拷贝的函数,即strcpy函数.都有拷贝的函数 ...
- Day16_90_通过反射机制获取某个特定的构造方法
通过反射机制获取某个特定的构造方法 public class ReflectTest13 { public static void main(String[] args) throws ClassNo ...
- 支持多线程的Redis6.0来了
支持多线程的 Redis 6.0 版本于 2020-05-02 终于发布了,为什么 Redis 忽然要支持多线程?如何开启多线程?开启后性能提升效果如何?线程数量该如何设置?开启多线程后会不会有线程安 ...
- CloudIDE:为开发者写代码开启“加速”模式
摘要:华为云CloudIDE,以软件基础技术结合新时代业务场景,给开发者提供更高效.优质的开发体验,帮助开发者实现业务创新新动力,以硬核技术重塑云原生开发生产力. 本文分享自华为云社区<华为云C ...
- 共享内存多进程key value操作
这个方法的优势是多进程,劣势也很明显,只允许操作key为uint32 value为uint32的数据. https://www.cnblogs.com/dearplain/p/11578588.h ...