2017-04-20 56 views
-1

我想知道是否有一种方法来显示提交/分支机构/等在存储库中的网站数量。我使用Flask来为apache2服务器上的jinja2提供网站,而不是通过硬编码来显示数字,我希望在每次创建新提交/分支时自动更新数字。在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,可以自动每个页面加载时间请求它,从某种意义上说,更新它。

相关问题