从 pygithub 获取值 StatsCommitActivity

Get values StatsCommitActivity from pygithub

我想获取统计“添加”和“删除”GitHub 代表。我试试:

#!pip install PyGithub
from github import Github
g = Github("token")
repo = g.get_repo("bitcoin/bitcoin")
active = repo.get_stats_commit_activity()
print(active)

输出:

<github.StatsCommitActivity.StatsCommitActivity object at 0x0000018EBF2674F0>
<github.StatsCommitActivity.StatsCommitActivity object at 0x0000018EC09D6910>

我的下一步是什么?

P.S:我也找到了 classgithub.CommitStats.CommitStats,但我不知道如何使用它。

我想这是你的下一步:

https://docs.github.com/en/rest/reference/metrics#get-all-contributor-commit-activity

在 pygithub: https://pygithub.readthedocs.io/en/latest/github_objects/Repository.html?highlight=get_stats_contributors#github.Repository.Repository.get_stats_contributors

get_stats_contributors 方法与这种 return:

希望这样的return val可以帮到你:

[
  {
    "author": {
      "login": "octocat",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/octocat",
      "html_url": "https://github.com/octocat",
      "followers_url": "https://api.github.com/users/octocat/followers",
      "following_url": "https://api.github.com/users/octocat/following{/other_user}",
      "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
      "organizations_url": "https://api.github.com/users/octocat/orgs",
      "repos_url": "https://api.github.com/users/octocat/repos",
      "events_url": "https://api.github.com/users/octocat/events{/privacy}",
      "received_events_url": "https://api.github.com/users/octocat/received_events",
      "type": "User",
      "site_admin": false
    },
    "total": 135,
    "weeks": [
      {

或者,还有一些其他的方法通过git logs命令行,例如:

 git log --pretty=format:"%an" --shortstat --no-merges --author= \
  | sed '/^$/d'\
  | awk -F' ' '{s1+=;s2+=}END{printf "additions: %s; deletions: %s\n",s1,s2}'

希望这些信息能帮到你