在Github中,是否有一种方法可以让我看到回购的下载数量?
当前回答
GitHub已经弃用下载支持,现在支持“发布”- https://github.com/blog/1547-release-your-software。要创建一个版本,要么使用GitHub UI,要么创建一个带注释的标签(http:// git-scm.com/book/ch2-6.html),并在GitHub中添加发布说明。然后,您可以将二进制文件或“资产”上传到每个版本。
一旦你发布了一些版本,GitHub API支持获取关于它们及其资产的信息。
curl -i \
https://api.github.com/repos/:owner/:repo/releases \
-H "Accept: application/vnd.github.manifold-preview+json"
寻找‘download_count’条目。更多信息请访问http://developer.github.com/v3/repos/releases/。这部分API仍然处于预览期,所以可能会有变化。
2013年11月更新:
GitHub的发布API现在已经过了预览期,因此不再需要'Accept'标头- http://developer.github.com/changes/2013-11-04-releases-api-is-official/
不过,继续添加'Accept'标头不会造成任何伤害。
其他回答
为了更清楚地说明这一点: 对于这个github项目:stant/ mdcsvimportter2015 https://github.com/stant/mdcsvimporter2015 在 https://github.com/stant/mdcsvimporter2015/releases
转到HTTP或https:(注意添加了“api.”和“/repos”) https://api.github.com/repos/stant/mdcsvimporter2015/releases
你会得到这个json输出,你可以搜索"download_count":
"download_count": 2,
"created_at": "2015-02-24T18:20:06Z",
"updated_at": "2015-02-24T18:20:07Z",
"browser_download_url": "https://github.com/stant/mdcsvimporter2015/releases/download/v18/mdcsvimporter-beta-18.zip"
或者在命令行执行: Wget——no-check-certificate https://api.github.com/repos/stant/mdcsvimporter2015/releases
这里是一个使用pip install PyGithub包的python解决方案
from github import Github
g = Github("youroauth key") #create token from settings page
for repo in g.get_user().get_repos():
if repo.name == "yourreponame":
releases = repo.get_releases()
for i in releases:
if i.tag_name == "yourtagname":
for j in i.get_assets():
print("{} date: {} download count: {}".format(j.name, j.updated_at, j._download_count.value))
如前所述,您可以通过API获得有关您的版本的信息。
对于那些使用WordPress的人,我开发了这个插件:GitHub Release Downloads。它可以让你获得下载计数,链接和更多的信息发布GitHub存储库。
为了解决最初的问题,短代码[grd_count user=" user " repo="MyRepo"]将返回存储库的下载数量。这个数字对应于一个GitHub存储库的所有版本的所有下载计数值的总和。
例子:
很晚了,但这是你想要的答案:
https://api.github.com/repos/ [git username] / [git project] /releases
接下来,在数据中找到您要查找的项目的id。它应该在顶部附近,在url旁边。然后,导航到
https://api.github.com/repos/ [git username] / [git project] /releases/ [id] / assets
名为download_count的字段就是答案。
编辑:在你的用户名和项目名中大写字母很重要
11年后…… 下面是一个小的python3代码片段,用于检索最近100个发行版资产的下载计数:
import requests
owner = "twbs"
repo = "bootstrap"
h = {"Accept": "application/vnd.github.v3+json"}
u = f"https://api.github.com/repos/{owner}/{repo}/releases?per_page=100"
r = requests.get(u, headers=h).json()
r.reverse() # older tags first
for rel in r:
if rel['assets']:
tag = rel['tag_name']
dls = rel['assets'][0]['download_count']
pub = rel['published_at']
print(f"Pub: {pub} | Tag: {tag} | Dls: {dls} ")
Pub: 2013-07-18T00:03:17Z | Tag: v1.2.0 | Dls: 1193
Pub: 2013-08-19T21:20:59Z | Tag: v3.0.0 | Dls: 387786
Pub: 2013-10-30T17:07:16Z | Tag: v3.0.1 | Dls: 102278
Pub: 2013-11-06T21:58:55Z | Tag: v3.0.2 | Dls: 381136
...
Pub: 2020-12-07T16:24:37Z | Tag: v5.0.0-beta1 | Dls: 93943
Demo
推荐文章
- 了解Git和GitHub的基础知识
- 在GitHub上有一个公共回购的私人分支?
- 只用GitHub动作在特定分支上运行作业
- Git合并与强制覆盖
- 是否有一个链接到GitHub下载文件的最新版本的存储库?
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- Github:我能看到回购的下载数量吗?
- 如何运行一个github-actions步骤,即使前一步失败,同时仍然失败的工作
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 在GitHub repo上显示Jenkins构建的当前状态
- 如何取消在github上的拉请求?
- HEAD和master的区别
- 在另一个目录中运行操作
- GitHub克隆与OAuth访问令牌
- 我可以在GitHub上对要点进行拉请求吗?