在你决定克隆它之前,有没有办法看看GitHub上的Git存储库有多大?
这似乎是一个非常明显/基本的统计数据,但我根本找不到如何在GitHub上看到它。
在你决定克隆它之前,有没有办法看看GitHub上的Git存储库有多大?
这似乎是一个非常明显/基本的统计数据,但我根本找不到如何在GitHub上看到它。
当前回答
在浏览器中,使用JavaScript,因为Github API启用了CORS:
fetch(“https://api.github.com/repos/webdev23/source_control_sentry”) .then(v => v.json()).then((v) => { console.log(v['size'] + 'KB') } )
其他回答
你需要遵循GitHub API。有关存储库的所有详细信息,请参阅这里的文档。 它需要你做出一个GET请求,如:
获得/回购:所有者/:库
你需要替换两个东西:
:owner—存储库所有者的用户名 :repository—存储库名称
例如,我的用户名maheshmnj,我拥有一个存储库,flutter-ui-nice,所以我的GET URL将是:
https://api.github.com/repos/maheshmnj/flutter-ui-nice
在发出GET请求时,您将收到一些JSON数据,可能在第78行中您应该看到一个名为size的键,它将返回存储库的大小。
提示:当使用JSON时,我建议您添加一个插件来格式化JSON数据,使读取JSON变得容易。安装插件。
如果你已经安装了官方的GitHub CLI,你可以执行以下操作:
gh api repos/<org>/<repo> --jq '.size'
我想它的单位是kb。
对于私有存储库,您需要从https://github.com/settings/tokens获取个人访问令牌。
然后使用以下curl命令获取详细信息(用值替换[token], [owner]和[name]):
curl -u git:[token] https://api.github.com/repos/[owner]/[name] 2> /dev/null | grep size
如前所述,大小的单位可以是MB或KB。
我创建了一个bookmarklet脚本来使用NVRM的答案的方法来做到这一点。
要使用它,请创建一个新书签,为其命名,并将此脚本粘贴到URL字段中。在浏览一个回购时点击这个书签会弹出一个提醒,提醒的大小有兆字节和千字节。
javascript:(()=>{let url=new URL(document.location.href);if(url.origin!="https://github.com"){return}if(url.pathname=="/"){return}let p=url.pathname.slice(1,url.pathname.length);let parts=p.split('/');if(parts.length<2){return}let x=[parts[0],parts[1]].join('/');fetch(`https://api.github.com/repos/${x}`).then(r=>r.json()).then((b)=>alert(`${(b['size']/1000).toFixed(2)}mb (${b['size']}kb)`))})()
你可以使用Github API
下面是Python示例:
import requests
if __name__ == '__main__':
base_api_url = 'https://api.github.com/repos'
git_repository_url = 'https://github.com/garysieling/wikipedia-categorization.git'
github_username, repository_name = git_repository_url[:-4].split('/')[-2:] # garysieling and wikipedia-categorization
res = requests.get(f'{base_api_url}/{github_username}/{repository_name}')
repository_size = res.json().get('size')
print(repository_size)