【发布时间】:2015-10-14 01:43:39
【问题描述】:
日历显示去年的捐款。有没有办法查看类似的计数但没有开始日期限制?
【问题讨论】:
标签: github
日历显示去年的捐款。有没有办法查看类似的计数但没有开始日期限制?
【问题讨论】:
标签: github
【讨论】:
您可以使用 Github API 检索您的存储库的统计信息,并使用几行代码来生成全局计数。
注意:公共访问请求的限制非常低。我建议您生成具有Access commit status 和Read all user profile data 权限的令牌(Settings > Developper settings > Personal access tokens)。
这是一个使用 curl 和 jq 的小型 bash 脚本。您只需要更改您的用户名。您还可以取消注释 AUTH 行并设置生成的令牌以避免达到查询限制:
#!/bin/bash
# Parameters
USER=jyvet
#AUTH="-u $USER:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
GAPI="https://api.github.com"
REPOS=$(curl $AUTH -s $GAPI/users/$USER/repos | jq -c -r '.[].name')
COMMITS=0
ADDITIONS=0
DELETIONS=0
# Iterate over all the repositories owned by the user
for r in $REPOS; do
STATS=$(curl $AUTH -s "$GAPI/repos/$USER/$r/stats/contributors" |
jq ".[] | select(.author.login == \"$USER\")" 2> /dev/null)
if [ $? -eq 0 ]; then
tmp=$(echo -n "$STATS" | jq '.total' 2> /dev/null)
COMMITS=$(( COMMITS + tmp ))
tmp=$(echo -n "$STATS" | jq '[.weeks[].a] | add' 2> /dev/null)
ADDITIONS=$(( ADDITIONS + tmp ))
tmp=$(echo -n "$STATS" | jq '[.weeks[].d] | add' 2> /dev/null)
DELETIONS=$(( DELETIONS + tmp ))
fi
done
echo "Commits: $COMMITS, Additions: $ADDITIONS, Deletions: $DELETIONS"
结果:
> Commits: 193, Additions: 20403, Deletions: 2687
【讨论】: