Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ccbuildpro/GitLabCommitStatics

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

需要统计Gitlab上所有仓库、所有人的代码提交状况。 在网上找了找,发现基本上都是基于已经checkout到本地的统计,如果要统计服务器上所有仓库的,则没有现成的工具,所有我用Python写了一个。

一,核心思路

通过GitLab官方提供的API,基本可以得到如下流程: 获取所有Projects API->获取branch list->获取commit list->获取commit detail,再做汇总。

有几个注意点: 1,所有接口都需要access token 2,所有的列表接口,都是分页的

另外,这些接口都可以用postman来调一遍,或者直接在浏览器里访问

二,接口调用

获取仓库列表

http://gitlab.example.com/api/v3/projects/all?private_token=%s&per_page=1000&page=%d&order_by=last_activity_at

你需要填上gitlab的url、你的token、和page(也就是第几页)。 业务可以自己去填。 你需要把不符合要求的仓库过滤掉

获取分支列表

http://gitlab.example.com/api/v4/projects/%s/repository/branches?private_token=%s'

你需要填上gitlab的url、project id、你的token

获取单个分支的commit列表

http://gitlab.example.com/api/v4/projects/%s/repository/commits?page=1&per_page=1000&ref_name=%s&since=%s&until=%s&private_token=%s

你需要填上gitlab的url、project id、你的token,ref_name(分支名称)、since(其实日期)、until(截止日期)。 这两个日期都需要是“%Y-%m-%dT%H:%M:%S.%fZ”的格式

获取单个commit的详情

http://gitlab.example.com/api/v4/projects/%s/repository/commits/%s?private_token=%s

你需要填上gitlab的url、project id、你的token。

三,需要注意

由于branch会相互merge,所以会造成重复统计,需要去重 另一个是,merge人和提交人不是同一个,有可能导致一份提交统计到两个人身上去了。

层层for循环进行http请求,如果不并行的话,时间非常长,所以要起子线程处理。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.