1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHub APIでコミット履歴を取得する

Posted at

概要

GitHub APIを利用して、コミット履歴を取得します。

publicリポジトリのコミット履歴を取得するので、認証についての考慮はしません。

利用するAPI

https://api.github.com/repos/{owner}/{repo}/commits
を利用します。(詳細は下記)
https://docs.github.com/en/github-ae@latest/rest/reference/repos#list-commits

 やってみた

試しにこのリポジトリの2020年のコミットを1つ取得するために、下記のようなリクエストを投げてみました。

https://api.github.com/repos/nannany/reading_memo/commits?since=2018-01-01T00:00:00+0900&until=2018-12-31T23:59:59+0900&per_page=1

結果はこんな感じ。

[
    {
        "sha": "d22d194dcb2392e97e56329f131fd184da9d0246",
        "node_id": "MDY6Q29tbWl0MTE5Mzg1NjY3OmQyMmQxOTRkY2IyMzkyZTk3ZTU2MzI5ZjEzMWZkMTg0ZGE5ZDAyNDY=",
        "commit": {
            "author": {
                "name": "nannany",
                "email": "ymym1990ymym@gmail.com",
                "date": "2018-12-30T04:59:34Z"
            },
            "committer": {
                "name": "nannany",
                "email": "ymym1990ymym@gmail.com",
                "date": "2018-12-30T04:59:34Z"
            },
            "message": "release",
            "tree": {
                "sha": "07f52b3055e8b92fca56bba10d3d09ae921ccef8",
                "url": "https://api.github.com/repos/nannany/reading_memo/git/trees/07f52b3055e8b92fca56bba10d3d09ae921ccef8"
            },
            "url": "https://api.github.com/repos/nannany/reading_memo/git/commits/d22d194dcb2392e97e56329f131fd184da9d0246",
            "comment_count": 0,
            "verification": {
                "verified": false,
                "reason": "unsigned",
                "signature": null,
                "payload": null
            }
        },
        "url": "https://api.github.com/repos/nannany/reading_memo/commits/d22d194dcb2392e97e56329f131fd184da9d0246",
        "html_url": "https://github.com/nannany/reading_memo/commit/d22d194dcb2392e97e56329f131fd184da9d0246",
        "comments_url": "https://api.github.com/repos/nannany/reading_memo/commits/d22d194dcb2392e97e56329f131fd184da9d0246/comments",
        "author": {
            "login": "nannany",
            "id": 14943122,
            "node_id": "MDQ6VXNlcjE0OTQzMTIy",
            "avatar_url": "https://avatars.githubusercontent.com/u/14943122?v=4",
            "gravatar_id": "",
            "url": "https://api.github.com/users/nannany",
            "html_url": "https://github.com/nannany",
            "followers_url": "https://api.github.com/users/nannany/followers",
            "following_url": "https://api.github.com/users/nannany/following{/other_user}",
            "gists_url": "https://api.github.com/users/nannany/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/nannany/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/nannany/subscriptions",
            "organizations_url": "https://api.github.com/users/nannany/orgs",
            "repos_url": "https://api.github.com/users/nannany/repos",
            "events_url": "https://api.github.com/users/nannany/events{/privacy}",
            "received_events_url": "https://api.github.com/users/nannany/received_events",
            "type": "User",
            "site_admin": false
        },
        "committer": {
            "login": "nannany",
            "id": 14943122,
            "node_id": "MDQ6VXNlcjE0OTQzMTIy",
            "avatar_url": "https://avatars.githubusercontent.com/u/14943122?v=4",
            "gravatar_id": "",
            "url": "https://api.github.com/users/nannany",
            "html_url": "https://github.com/nannany",
            "followers_url": "https://api.github.com/users/nannany/followers",
            "following_url": "https://api.github.com/users/nannany/following{/other_user}",
            "gists_url": "https://api.github.com/users/nannany/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/nannany/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/nannany/subscriptions",
            "organizations_url": "https://api.github.com/users/nannany/orgs",
            "repos_url": "https://api.github.com/users/nannany/repos",
            "events_url": "https://api.github.com/users/nannany/events{/privacy}",
            "received_events_url": "https://api.github.com/users/nannany/received_events",
            "type": "User",
            "site_admin": false
        },
        "parents": [
            {
                "sha": "b19ac18b72e63e7798a6dce5828fcdaf9ead86e7",
                "url": "https://api.github.com/repos/nannany/reading_memo/commits/b19ac18b72e63e7798a6dce5828fcdaf9ead86e7",
                "html_url": "https://github.com/nannany/reading_memo/commit/b19ac18b72e63e7798a6dce5828fcdaf9ead86e7"
            }
        ]
    }
]

感想

GitHub APIには多くのエンドポイントが用意されており驚きました。
(OPEN API Specのファイルが60,000行弱ありました😲)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?