統計
Repository Statistics API を使用すると、GitHub Enterprise Server がさまざまなタイプのリポジトリのアクティビティを視覚化するために用いるデータをフェッチできます。
キャッシングについて
リポジトリの統計情� �を計算するのは� 荷が高い操作なので、可能な限りキャッシュされたデータを返すようにしています。 リポジトリの統計をクエリした際にデータがキャッシュされていなかった� �合は、202 レスポンスを受け取ります。また、この統計をまとめるため、バックグラウンドでジョブが開始します。 このジョブが完了するまで少し待ってから、リクエストを再度サブミットしてく� さい。 ジョブが完了していた� �合、リクエストは 200 レスポンスを受けとり、レスポンスの本文には統計情� �が含まれています。
リポジトリの統計情� �は、リポジトリのデフォルトブランチに SHA でキャッシュされ、デフォルトのブランチにプッシュすると統計情� �のキャッシュがリセットされます。
統計で除外されるコミットのタイプ
API によって公開される統計は、別のリポジトリグラフで表示される統計と同じものです。
要約すると、
-
すべての統計は、マージコミットが除外されます。
-
コントリビューター統計では、空のコミットも除外されます。
Get the weekly commit activity
Returns a weekly aggregate of the number of additions and deletions pushed to a repository.
get /repos/{owner}/{repo}/stats/code_frequencyパラメータ
Name Type In Description acceptstring header Setting to
application/vnd.github.v3+jsonis recommended.ownerstring path repostring path コードサンプル
Shell
curl \ -H "Accept: application/vnd.github.v3+json" \ http(s)://{hostname}/api/v3/repos/octocat/hello-world/stats/code_frequencyJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/stats/code_frequency', { owner: 'octocat', repo: 'hello-world' })Returns a weekly aggregate of the number of additions and deletions pushed to a repository.
Status: 200 OK[ [ 1302998400, 1124, -435 ] ]Accepted
Status: 202 AcceptedA header with no content is returned.
Status: 204 No ContentNotes
Get the last year of commit activity
Returns the last year of commit activity grouped by week. The
daysarray is a group of commits per day, starting onSunday.get /repos/{owner}/{repo}/stats/commit_activityパラメータ
Name Type In Description acceptstring header Setting to
application/vnd.github.v3+jsonis recommended.ownerstring path repostring path コードサンプル
Shell
curl \ -H "Accept: application/vnd.github.v3+json" \ http(s)://{hostname}/api/v3/repos/octocat/hello-world/stats/commit_activityJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/stats/commit_activity', { owner: 'octocat', repo: 'hello-world' })Response
Status: 200 OK[ { "days": [ 0, 3, 26, 20, 39, 1, 0 ], "total": 89, "week": 1336280400 } ]Accepted
Status: 202 AcceptedA header with no content is returned.
Status: 204 No ContentNotes
Get all contributor commit activity
Returns the
totalnumber of commits authored by the contributor. In addition, the response includes a Weekly Hash (weeksarray) with the following information:w- Start of the week, given as a Unix timestamp.a- Number of additionsd- Number of deletionsc- Number of commits
get /repos/{owner}/{repo}/stats/contributorsパラメータ
Name Type In Description acceptstring header Setting to
application/vnd.github.v3+jsonis recommended.ownerstring path repostring path コードサンプル
Shell
curl \ -H "Accept: application/vnd.github.v3+json" \ http(s)://{hostname}/api/v3/repos/octocat/hello-world/stats/contributorsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/stats/contributors', { owner: 'octocat', repo: 'hello-world' })w- Start of the week, given as a Unix timestamp.a- Number of additionsd- Number of deletionsc- Number of commits
Status: 200 OK[ { "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": [ { "w": 1367712000, "a": 6898, "d": 77, "c": 10 } ] } ]Accepted
Status: 202 AcceptedA header with no content is returned.
Status: 204 No ContentNotes
Get the weekly commit count
Returns the total commit counts for the
ownerand total commit counts inall.allis everyone combined, including theownerin the last 52 weeks. If you'd like to get the commit counts for non-owners, you can subtractownerfromall.The array order is oldest week (index 0) to most recent week.
get /repos/{owner}/{repo}/stats/participationパラメータ
Name Type In Description acceptstring header Setting to
application/vnd.github.v3+jsonis recommended.ownerstring path repostring path コードサンプル
Shell
curl \ -H "Accept: application/vnd.github.v3+json" \ http(s)://{hostname}/api/v3/repos/octocat/hello-world/stats/participationJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/stats/participation', { owner: 'octocat', repo: 'hello-world' })The array order is oldest week (index 0) to most recent week.
Status: 200 OK{ "all": [ 11, 21, 15, 2, 8, 1, 8, 23, 17, 21, 11, 10, 33, 91, 38, 34, 22, 23, 32, 3, 43, 87, 71, 18, 13, 5, 13, 16, 66, 27, 12, 45, 110, 117, 13, 8, 18, 9, 19, 26, 39, 12, 20, 31, 46, 91, 45, 10, 24, 9, 29, 7 ], "owner": [ 3, 2, 3, 0, 2, 0, 5, 14, 7, 9, 1, 5, 0, 48, 19, 2, 0, 1, 10, 2, 23, 40, 35, 8, 8, 2, 10, 6, 30, 0, 2, 9, 53, 104, 3, 3, 10, 4, 7, 11, 21, 4, 4, 22, 26, 63, 11, 2, 14, 1, 10, 3 ] }Resource not found
Status: 404 Not FoundNotes
Get the hourly commit count for each day
Each array contains the day number, hour number, and number of commits:
0-6: Sunday - Saturday0-23: Hour of day- Number of commits
For example,
[2, 14, 25]indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. All times are based on the time zone of individual commits.get /repos/{owner}/{repo}/stats/punch_cardパラメータ
Name Type In Description acceptstring header Setting to
application/vnd.github.v3+jsonis recommended.ownerstring path repostring path コードサンプル
Shell
curl \ -H "Accept: application/vnd.github.v3+json" \ http(s)://{hostname}/api/v3/repos/octocat/hello-world/stats/punch_cardJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/stats/punch_card', { owner: 'octocat', repo: 'hello-world' })For example,
[2, 14, 25]indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. All times are based on the time zone of individual commits.Status: 200 OK[ [ 0, 0, 5 ], [ 0, 1, 43 ], [ 0, 2, 21 ] ]A header with no content is returned.
Status: 204 No ContentNotes