在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的字段就是答案。

编辑:在你的用户名和项目名中大写字母很重要

其他回答

很晚了,但这是你想要的答案:

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的字段就是答案。

编辑:在你的用户名和项目名中大写字母很重要

我最终写了一个scraper脚本来查找我的克隆计数:

#!/bin/sh
#
# This script requires:
#   apt-get install html-xml-utils
#   apt-get install jq
#
USERNAME=dougluce
PASSWORD="PASSWORD GOES HERE, BE CAREFUL!"
REPO="dougluce/node-autovivify"

TOKEN=`curl https://github.com/login -s -c /tmp/cookies.txt | \
     hxnormalize | \
     hxselect 'input[name=authenticity_token]' 2>/dev/null | \
     perl -lne 'print $1 if /value=\"(\S+)\"/'`

curl -X POST https://github.com/session \
     -s -b /tmp/cookies.txt -c /tmp/cookies2.txt \
     --data-urlencode commit="Sign in" \
     --data-urlencode authenticity_token="$TOKEN" \
     --data-urlencode login="$USERNAME" \
     --data-urlencode password="$PASSWORD" > /dev/null

curl "https://github.com/$REPO/graphs/clone-activity-data" \
     -s -b /tmp/cookies2.txt \
     -H "x-requested-with: XMLHttpRequest" | jq '.summary'

这将从相同的端点获取数据,Github的克隆图使用,并从它吐出总数。数据还包括每天的计数,将.summary替换为just。看看那些漂亮的印花。

为了更清楚地说明这一点: 对于这个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

Github API不再提供所需的信息。看看Stan Towianski的回答中提到的发布页面。正如我们在回答的评论中讨论的那样,Github API只报告他每次发布的三个文件中的一个的下载量。

我已经检查了解决方案,在这个问题的其他一些答案。Vonc的回答体现了Michele Milidoni解决方案的关键部分。我安装了他的gdc脚本,结果如下

# ./gdc stant
mdcsvimporter.mxt: 37 downloads
mdcsvimporter.mxt: 80 downloads
How-to-use-mdcsvimporter-beta-16.zip: 12 downloads

正如您可以清楚地看到的,gdc没有报告tar.gz和zip文件的下载计数。

如果您想在不安装任何东西的情况下进行检查,请尝试Somsubhra在他的回答中提到的安装解决方案的网页。填写“stant”作为Github用户名和“mdcsvimportter2015”作为存储库名称,你会看到如下内容:

Download Info:
mdcsvimporter.mxt(0.20MB) - Downloaded 37 times.
Last updated on 2015-03-26

唉,还是只有一个没有下载tar.gz和zip文件的报告。我仔细检查了Github的API返回的信息,但它没有提供任何地方。目前,API返回的download_count还远远不够完整。

新的实现:

移植到GitHub组合动作重用工作流代码基。

https://github.com/andry81-devops/github-accum-stats

附加功能:

可以计数流量克隆或/和视图。 可以使用GitHub复合动作重用工作流代码基:https://docs.github.com/en/actions/creating-actions/creating-a-composite-action

GitHub工作流文件示例:

.github /工作流/ accum-gh-clone-stats.yml


以前的实现(标记为obsolete):

此实现基于GitHub Actions +统计累加到单独的存储库:https://github.com/andry81-devops/github-clone-count-badge

基于:https://github.com/MShawon/github-clone-count-badge

有一些优点:

用于跟踪的存储库和用于存储流量统计数据的存储库是不同的,您可以直接将统计数据指向提交列表:https://github.com/{{REPO_OWNER}}/{{REPO}}--gh-stats/commits/master/traffic/clones 工作流使用aac -traffic-clone .sh bash脚本积累流量克隆 脚本将统计数据累加到单个文件和一组按年分组并每天分配的文件中:traffic/克隆/by_year/YYYY/YYYY- mm - dd .json

GitHub工作流文件示例:

.github /工作流/ myrepo-gh-clone-stats.yml