Linux・Ubuntu

Githubリポジトリの情報(star/fork)をLinuxコマンドで取得する方法

リポジトリの”star”や”fork”の数をコマンドラインから取得することができる.

#  e.g.ariya/phantomjs

# リポジトリの"star"の数を取得する
curl --silent 'https://api.github.com/repos/ariya/phantomjs' -H 'Accept: application/vnd.github.preview' | jq '.watchers'

# リポジトリの"fork"の数を取得する
curl --silent 'https://api.github.com/repos/ariya/phantomjs' -H 'Accept: application/vnd.github.preview' | jq '.forks'

# リポジトリの"issue"の数を取得する
curl --silent 'https://api.github.com/repos/ariya/phantomjs' -H 'Accept: application/vnd.github.preview' | jq '.open_issues'

# リポジトリの"size"を取得する
curl --silent 'https://api.github.com/repos/ariya/phantomjs' -H 'Accept: application/vnd.github.preview' | jq '.size'

https://github.com/ariya/phantomjs

James Sugrue asked, “@GitHubAPI is there a way to find the number of stars for a given repository?”

Example

$ curl -ni "https://api.github.com/search/repositories?q=more+useful+keyboard" -H 'Accept: application/vnd.github.preview'
{
  "total_count": 1,
  "items": [
    {
      "id": 9118195,
      "name": "keyboard",
      "full_name": "jasonrudolph/keyboard",
      "owner": {
        "login": "jasonrudolph",
        "id": 2988,
        "avatar_url": "https://secure.gravatar.com/avatar/592e1e6f041f9a4ec51846fd82013aea?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
        "gravatar_id": "592e1e6f041f9a4ec51846fd82013aea",
        "url": "https://api.github.com/users/jasonrudolph",
        "html_url": "https://github.com/jasonrudolph",
        "followers_url": "https://api.github.com/users/jasonrudolph/followers",
        "following_url": "https://api.github.com/users/jasonrudolph/following{/other_user}",
        "gists_url": "https://api.github.com/users/jasonrudolph/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/jasonrudolph/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/jasonrudolph/subscriptions",
        "organizations_url": "https://api.github.com/users/jasonrudolph/orgs",
        "repos_url": "https://api.github.com/users/jasonrudolph/repos",
        "events_url": "https://api.github.com/users/jasonrudolph/events{/privacy}",
        "received_events_url": "https://api.github.com/users/jasonrudolph/received_events",
        "type": "User"
      },
      "private": false,
      "html_url": "https://github.com/jasonrudolph/keyboard",
      "description": "Toward a more useful keyboard",
      "fork": false,
      "url": "https://api.github.com/repos/jasonrudolph/keyboard",
      "forks_url": "https://api.github.com/repos/jasonrudolph/keyboard/forks",
      "keys_url": "https://api.github.com/repos/jasonrudolph/keyboard/keys{/key_id}",
      "collaborators_url": "https://api.github.com/repos/jasonrudolph/keyboard/collaborators{/collaborator}",
      "teams_url": "https://api.github.com/repos/jasonrudolph/keyboard/teams",
      "hooks_url": "https://api.github.com/repos/jasonrudolph/keyboard/hooks",
      "issue_events_url": "https://api.github.com/repos/jasonrudolph/keyboard/issues/events{/number}",
      "events_url": "https://api.github.com/repos/jasonrudolph/keyboard/events",
      "assignees_url": "https://api.github.com/repos/jasonrudolph/keyboard/assignees{/user}",
      "branches_url": "https://api.github.com/repos/jasonrudolph/keyboard/branches{/branch}",
      "tags_url": "https://api.github.com/repos/jasonrudolph/keyboard/tags",
      "blobs_url": "https://api.github.com/repos/jasonrudolph/keyboard/git/blobs{/sha}",
      "git_tags_url": "https://api.github.com/repos/jasonrudolph/keyboard/git/tags{/sha}",
      "git_refs_url": "https://api.github.com/repos/jasonrudolph/keyboard/git/refs{/sha}",
      "trees_url": "https://api.github.com/repos/jasonrudolph/keyboard/git/trees{/sha}",
      "statuses_url": "https://api.github.com/repos/jasonrudolph/keyboard/statuses/{sha}",
      "languages_url": "https://api.github.com/repos/jasonrudolph/keyboard/languages",
      "stargazers_url": "https://api.github.com/repos/jasonrudolph/keyboard/stargazers",
      "contributors_url": "https://api.github.com/repos/jasonrudolph/keyboard/contributors",
      "subscribers_url": "https://api.github.com/repos/jasonrudolph/keyboard/subscribers",
      "subscription_url": "https://api.github.com/repos/jasonrudolph/keyboard/subscription",
      "commits_url": "https://api.github.com/repos/jasonrudolph/keyboard/commits{/sha}",
      "git_commits_url": "https://api.github.com/repos/jasonrudolph/keyboard/git/commits{/sha}",
      "comments_url": "https://api.github.com/repos/jasonrudolph/keyboard/comments{/number}",
      "issue_comment_url": "https://api.github.com/repos/jasonrudolph/keyboard/issues/comments/{number}",
      "contents_url": "https://api.github.com/repos/jasonrudolph/keyboard/contents/{+path}",
      "compare_url": "https://api.github.com/repos/jasonrudolph/keyboard/compare/{base}...{head}",
      "merges_url": "https://api.github.com/repos/jasonrudolph/keyboard/merges",
      "archive_url": "https://api.github.com/repos/jasonrudolph/keyboard/{archive_format}{/ref}",
      "downloads_url": "https://api.github.com/repos/jasonrudolph/keyboard/downloads",
      "issues_url": "https://api.github.com/repos/jasonrudolph/keyboard/issues{/number}",
      "pulls_url": "https://api.github.com/repos/jasonrudolph/keyboard/pulls{/number}",
      "milestones_url": "https://api.github.com/repos/jasonrudolph/keyboard/milestones{/number}",
      "notifications_url": "https://api.github.com/repos/jasonrudolph/keyboard/notifications{?since,all,participating}",
      "labels_url": "https://api.github.com/repos/jasonrudolph/keyboard/labels{/name}",
      "created_at": "2013-03-30T16:01:43Z",
      "updated_at": "2013-07-22T02:01:08Z",
      "pushed_at": "2013-07-14T00:26:07Z",
      "git_url": "git://github.com/jasonrudolph/keyboard.git",
      "ssh_url": "git@github.com:jasonrudolph/keyboard.git",
      "clone_url": "https://github.com/jasonrudolph/keyboard.git",
      "svn_url": "https://github.com/jasonrudolph/keyboard",
      "homepage": "",
      "size": 228,
      "watchers_count": 235,
      "language": null,
      "has_issues": true,
      "has_downloads": true,
      "has_wiki": false,
      "forks_count": 7,
      "mirror_url": null,
      "open_issues_count": 1,
      "forks": 7,
      "open_issues": 1,
      "watchers": 235,
      "master_branch": "master",
      "default_branch": "master",
      "score": 38.069878
    }
  ]
}

Stars and watchers are in a transition period.
Until that transition is complete, you get the number of stars using the old terminology (i.e., “watchers_count”).

view raw
gistfile1.md
hosted with ❤ by GitHub