2017-04-20 17 views
-1

リポジトリに作成されたコミット/ブランチ/ etcの数をウェブサイトに表示する方法があるのだろうかと思います。私は、apache2サーバー上のjinja2のWebサイトでFlaskを使用しています。新しいコミット/ブランチが作成されるたびに自動的に番号を更新したいと思っています。FlaskのウェブサイトにGitHubの統計情報を表示

答えて

-1

これを行うにはGitHub APIを使用できます。

たとえば、(GET)/repos/:owner/:repo/commitsを要求することによって、リポジトリのコミット量を要求できます。

(APIドキュメントから)次のように応答の例がある

[ 
    { 
    "url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e", 
    "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e", 
    "html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e", 
    "comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments", 
    "commit": { 
     "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e", 
     "author": { 
     "name": "Monalisa Octocat", 
     "email": "[email protected]", 
     "date": "2011-04-14T16:00:49Z" 
     }, 
     "committer": { 
     "name": "Monalisa Octocat", 
     "email": "[email protected]", 
     "date": "2011-04-14T16:00:49Z" 
     }, 
     "message": "Fix all the bugs", 
     "tree": { 
     "url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e", 
     "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e" 
     }, 
     "comment_count": 0, 
     "verification": { 
     "verified": true, 
     "reason": "valid", 
     "signature": "-----BEGIN PGP MESSAGE-----\n...\n-----END PGP MESSAGE-----", 
     "payload": "tree 6dcb09b5b57875f334f61aebed695e2e4193db5e\n..." 
     } 
    }, 
    "author": { 
     "login": "octocat", 
     "id": 1, 
     "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 
    }, 
    "committer": { 
     "login": "octocat", 
     "id": 1, 
     "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 
    }, 
    "parents": [ 
     { 
     "url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e", 
     "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e" 
     } 
    ] 
    } 
] 

すると、あなたがAPIを使用しているので、あなたは自動的に、ある意味で、ページがロードされるたびにそれを要求することができますそれを更新する。

関連する問題